{"id":13600045,"url":"https://github.com/mindawei/weather","last_synced_at":"2025-06-25T21:33:59.231Z","repository":{"id":215749575,"uuid":"116452142","full_name":"mindawei/weather","owner":"mindawei","description":"一个天气查询服务：爬取数据、Web服务、小程序展示","archived":false,"fork":false,"pushed_at":"2018-03-26T13:46:28.000Z","size":1301,"stargazers_count":56,"open_issues_count":0,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-23T12:14:09.048Z","etag":null,"topics":["html","java","maven","mini-program","spring-boot","weather-service"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mindawei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-01-06T04:08:14.000Z","updated_at":"2025-03-30T17:07:18.000Z","dependencies_parsed_at":"2024-01-06T10:32:21.485Z","dependency_job_id":null,"html_url":"https://github.com/mindawei/weather","commit_stats":null,"previous_names":["mindawei/weather"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindawei%2Fweather","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindawei%2Fweather/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindawei%2Fweather/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindawei%2Fweather/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mindawei","download_url":"https://codeload.github.com/mindawei/weather/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250430595,"owners_count":21429324,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html","java","maven","mini-program","spring-boot","weather-service"],"created_at":"2024-08-01T18:00:20.376Z","updated_at":"2025-04-23T12:14:17.037Z","avatar_url":"https://github.com/mindawei.png","language":"Java","readme":"### 前置说明\n1. /doc 文件夹中包含项目截图和以下将要描述的文档(\u003ca href=\"https://github.com/mindawei/weather/blob/master/doc/%E5%A4%A9%E6%B0%94%E6%9C%8D%E5%8A%A1%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.pdf\"\u003ePDF文档\u003c/a\u003e )。\n2. weather-web 项目： 天气Web服务。 \n3. weather-weixin 项目：查询天气微信小程序（微信扫描下图可以查看）。\n\n![查询天气小程序](https://github.com/mindawei/weather/blob/master/doc/imgs/weahter-weixin.jpg)\n\n4. 项目中一些关键Key已经去除，开发者可以自行添加，如有问题可以留言或者邮件联系。\n5. 欢迎 fork 和 star ~\n\n天气服务说明文档\n====\n# 1背景\n## 1.1意义\n\u0026emsp;\u0026emsp;设计该服务，主要有以下几个原因：\n\u003e1. 目前的一些天气API（高德、百度等）都只有3天的预报，不能提供长期预报。\n\u003e2. 第三方API有调用次数限制、认证情况比较麻烦。\n## 1.2不足\n\u0026emsp;\u0026emsp;该服务存在以下缺陷：\n\u003e1. 依赖第三方网站，第三方网站的网页结构变化后需要重新修改代码。\n\u003e2. 第三方服务器崩溃或者提供反爬技术的话，该服务失效。\n## 1.3 声明\n\u0026emsp;\u0026emsp;本服务只是为了学习交流使用。\n# 2服务结构\n\u0026emsp;\u0026emsp;如果开发者需要基于该服务项目进行开发的话，需要了解该服务的一些结构。该服务（weather-web项目）的总体结构如下图所示。\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/mindawei/weather/blob/master/doc/imgs/frame.png\"/\u003e\n\u003c/p\u003e\n\n\u0026emsp;\u0026emsp;其中，淡粉色部分表示支持查询的接口，淡紫色部分表示第三方的接口或网站，淡绿色部分是项目中主要的几个类。使用该服务，需要注意一下几个方面：\n\u003e1. 如果是按经纬度查询，则需要利用第三方API（腾讯的API）将经纬度转换为对应的城市名称。\n\u003e2. 因为最后是根据查询城市的拼音找到解析数据的网页的，所以需要事先爬取城市名称和拼音的关系，最后统一转换为按拼音查询。\n\u003e3. 为了减少频繁爬取第三方数据，该服务按天粒度进行更新，每次查询的时候会比对天气日期，如果过期才会重新爬取，否则则会返回缓存中的数据。\n为了服务的快速，服务所有数据都在内存中，并没有落盘。\n# 3服务接口\n## 3.1访问接口\n\u0026emsp;\u0026emsp;访问接口如下表所示，接口中中文部分表示需要提供的参数。开发者在部署服务后，最终的访问接口是：协议（http 或 https）+ 主机地址 + 接口。\u003cbr\u003e\n\u003cbr\u003e\n\n| 功能        | 接口          | \n| ------------- |:-------------:| \n| 按经纬度进行查询      | /weather/?latitude=纬度\u0026longitude=经度 |\n| 按城市名称中文（或拼音）进行查询      | /weather/城市名称或拼音 |\n\n__开放测试接口__：https://weather.mindawei.cn/weather/\n\n以杭州为例：\n* https://weather.mindawei.cn/weather/hangzhou\n* https://weather.mindawei.cn/weather/杭州\n* https://weather.mindawei.cn/weather/?latitude=30.27415\u0026longitude=120.15515\n\n## 3.2返回结果\n\u0026emsp;\u0026emsp;返回的结果是Json格式，包含30天天气基本情况，具体如下所示：\n\u003cpre\u003e\u003ccode\u003e\n{\n    \"queryName\": \"泰州\",  // 查询的城市名字，如果无数据返回空\n    \"date\": \"2018-01-06\",  // 第一天数据日期，缓存可以判断是否过期\n    \"weatherItems\": [     // 天气情况数组，30天\n        {\n            \"date\": \"01月06日\",      // 日期\n            \"dayKind\": \"今天\",        // 星期几，前三天是今天明天后天 \n            \"weather\": \"雪\",           // 天气描述\n            \"weatherImg\": \"b15.png\",   // 天气用什么图片表示\n            \"minTemperature\": \"-6\",    // 最低温度 \n            \"maxTemperature\": \"4\",     // 最高温度\n            \"wind\": \"东北风 3级\"     // 风力描述\n        },\n        ...\n    ]\n}\n\u003c/code\u003e\u003c/pre\u003e\n\n# 4基于该服务的小程序\n\u0026emsp;\u0026emsp;基于该服务可以构建一些天气查询应用。为了演示该服务，写了一个小程序。下面几幅图就是小程序项目（weather-weixin）的演示效果图。小程序启动时可以根据经纬度给出一个当前位置的天气情况，之后可以根据查询关键字更新数据。\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/mindawei/weather/blob/master/doc/imgs/1.png\" width=\"33%\" height=\"33%\" /\u003e\n\u003cimg src=\"https://github.com/mindawei/weather/blob/master/doc/imgs/2.png\" width=\"33%\" height=\"33%\" /\u003e\n\u003cimg src=\"https://github.com/mindawei/weather/blob/master/doc/imgs/3.png\" width=\"33%\" height=\"33%\" /\u003e\n\u003c/p\u003e\n\n# 5项目实际部署\n## 5.1运行Web服务\n1. 如果要支持经纬度查询，则需要配置WeatherWebConfig.txt中的腾讯地图API KEY。\n2. 由于小程序使用https，所以如果要运行小程序，则需要将域名指向Web服务主机，申请证书，并配置src/main/resources下的application.properties文件。\n## 5.2运行小程序\n1. project.config.json中填入你申请的appid。\n2. pages\\index\\index.js内容中开头部分的baseUrl替换成：Web服务地址的部署地址+”weather/”。\n","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmindawei%2Fweather","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmindawei%2Fweather","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmindawei%2Fweather/lists"}