{"id":13704687,"url":"https://github.com/overtrue/weather","last_synced_at":"2025-05-16T02:07:20.201Z","repository":{"id":52402330,"uuid":"144818004","full_name":"overtrue/weather","owner":"overtrue","description":":rainbow: 基于高德开放平台接口的 PHP 天气信息组件。","archived":false,"fork":false,"pushed_at":"2025-02-06T21:04:02.000Z","size":50,"stargazers_count":173,"open_issues_count":1,"forks_count":49,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-10T18:48:22.763Z","etag":null,"topics":["weather","weather-api","weather-sdk"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/overtrue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["overtrue"]}},"created_at":"2018-08-15T07:04:33.000Z","updated_at":"2025-04-29T01:38:34.000Z","dependencies_parsed_at":"2023-11-17T01:09:41.745Z","dependency_job_id":"644d9be3-52d2-4e1b-92df-2133bd0413e5","html_url":"https://github.com/overtrue/weather","commit_stats":{"total_commits":42,"total_committers":5,"mean_commits":8.4,"dds":0.1428571428571429,"last_synced_commit":"6d333287305205334508a22a49c3fd2967f90353"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overtrue%2Fweather","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overtrue%2Fweather/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overtrue%2Fweather/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overtrue%2Fweather/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/overtrue","download_url":"https://codeload.github.com/overtrue/weather/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254453652,"owners_count":22073617,"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":["weather","weather-api","weather-sdk"],"created_at":"2024-08-02T21:01:18.140Z","updated_at":"2025-05-16T02:07:20.180Z","avatar_url":"https://github.com/overtrue.png","language":"PHP","funding_links":["https://github.com/sponsors/overtrue"],"categories":["配置 Configuration","第三方API( Third Party APIs )"],"sub_categories":["第三方api Third Party APIs"],"readme":"\n\u003ch1 align=\"center\"\u003eWeather\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e:rainbow: 基于高德开放平台的 PHP 天气信息组件。\u003c/p\u003e\n\n[![Tests](https://github.com/overtrue/weather/actions/workflows/tests.yml/badge.svg)](https://github.com/overtrue/weather/actions/workflows/tests.yml)\n\n[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me-button-s.svg?raw=true)](https://github.com/sponsors/overtrue)\n\n## 安装\n\n```sh\n$ composer require overtrue/weather -vvv\n```\n\n## 配置\n\n在使用本扩展之前，你需要去 [高德开放平台](https://lbs.amap.com/dev/id/newuser) 注册账号，然后创建应用，获取应用的 API Key。\n\n\n## 使用\n\n```php\nuse Overtrue\\Weather\\Weather;\n\n$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';\n\n$weather = new Weather($key);\n```\n\n###  获取实时天气\n\n```php\n$response = $weather-\u003egetLiveWeather('深圳');\n```\n示例：\n\n```json\n{\n    \"status\": \"1\",\n    \"count\": \"1\",\n    \"info\": \"OK\",\n    \"infocode\": \"10000\",\n    \"lives\": [\n        {\n            \"province\": \"广东\",\n            \"city\": \"深圳市\",\n            \"adcode\": \"440300\",\n            \"weather\": \"中雨\",\n            \"temperature\": \"27\",\n            \"winddirection\": \"西南\",\n            \"windpower\": \"5\",\n            \"humidity\": \"94\",\n            \"reporttime\": \"2018-08-21 16:00:00\"\n        }\n    ]\n}\n```\n\n### 获取近期天气预报\n\n```\n$response = $weather-\u003egetForecastsWeather('深圳');\n```\n示例：\n\n```json\n{\n    \"status\": \"1\",\n    \"count\": \"1\",\n    \"info\": \"OK\",\n    \"infocode\": \"10000\",\n    \"forecasts\": [\n        {\n            \"city\": \"深圳市\",\n            \"adcode\": \"440300\",\n            \"province\": \"广东\",\n            \"reporttime\": \"2018-08-21 11:00:00\",\n            \"casts\": [\n                {\n                    \"date\": \"2018-08-21\",\n                    \"week\": \"2\",\n                    \"dayweather\": \"雷阵雨\",\n                    \"nightweather\": \"雷阵雨\",\n                    \"daytemp\": \"31\",\n                    \"nighttemp\": \"26\",\n                    \"daywind\": \"无风向\",\n                    \"nightwind\": \"无风向\",\n                    \"daypower\": \"≤3\",\n                    \"nightpower\": \"≤3\"\n                },\n                {\n                    \"date\": \"2018-08-22\",\n                    \"week\": \"3\",\n                    \"dayweather\": \"雷阵雨\",\n                    \"nightweather\": \"雷阵雨\",\n                    \"daytemp\": \"32\",\n                    \"nighttemp\": \"27\",\n                    \"daywind\": \"无风向\",\n                    \"nightwind\": \"无风向\",\n                    \"daypower\": \"≤3\",\n                    \"nightpower\": \"≤3\"\n                },\n                {\n                    \"date\": \"2018-08-23\",\n                    \"week\": \"4\",\n                    \"dayweather\": \"雷阵雨\",\n                    \"nightweather\": \"雷阵雨\",\n                    \"daytemp\": \"32\",\n                    \"nighttemp\": \"26\",\n                    \"daywind\": \"无风向\",\n                    \"nightwind\": \"无风向\",\n                    \"daypower\": \"≤3\",\n                    \"nightpower\": \"≤3\"\n                },\n                {\n                    \"date\": \"2018-08-24\",\n                    \"week\": \"5\",\n                    \"dayweather\": \"雷阵雨\",\n                    \"nightweather\": \"雷阵雨\",\n                    \"daytemp\": \"31\",\n                    \"nighttemp\": \"26\",\n                    \"daywind\": \"无风向\",\n                    \"nightwind\": \"无风向\",\n                    \"daypower\": \"≤3\",\n                    \"nightpower\": \"≤3\"\n                }\n            ]\n        }\n    ]\n}\n```\n\n### 获取 XML 格式返回值\n\n以上两个方法第二个参数为返回值类型，可选 `json` 与 `xml`，默认 `json`：\n\n```php\n$response = $weather-\u003egetLiveWeather('深圳', 'xml');\n```\n\n示例：\n\n```xml\n\u003cresponse\u003e\n    \u003cstatus\u003e1\u003c/status\u003e\n    \u003ccount\u003e1\u003c/count\u003e\n    \u003cinfo\u003eOK\u003c/info\u003e\n    \u003cinfocode\u003e10000\u003c/infocode\u003e\n    \u003clives type=\"list\"\u003e\n        \u003clive\u003e\n            \u003cprovince\u003e广东\u003c/province\u003e\n            \u003ccity\u003e深圳市\u003c/city\u003e\n            \u003cadcode\u003e440300\u003c/adcode\u003e\n            \u003cweather\u003e中雨\u003c/weather\u003e\n            \u003ctemperature\u003e27\u003c/temperature\u003e\n            \u003cwinddirection\u003e西南\u003c/winddirection\u003e\n            \u003cwindpower\u003e5\u003c/windpower\u003e\n            \u003chumidity\u003e94\u003c/humidity\u003e\n            \u003creporttime\u003e2018-08-21 16:00:00\u003c/reporttime\u003e\n        \u003c/live\u003e\n    \u003c/lives\u003e\n\u003c/response\u003e\n```\n\n### 参数说明\n\n```\narray | string   getLiveWeather(string $city, string $format = 'json')\narray | string   getForecastsWeather(string $city, string $format = 'json')\n```\n\n\u003e - `$city` - 城市名/[高德地址位置 adcode](https://lbs.amap.com/api/webservice/guide/api/district)，比如：“深圳” 或者（adcode：440300）；\n\u003e - `$format`  - 输出的数据格式，默认为 json 格式，当 output 设置为 “`xml`” 时，输出的为 XML 格式的数据。\n\n\n### 在 Laravel 中使用\n\n在 Laravel 中使用也是同样的安装方式，配置写在 `config/services.php` 中：\n\n```php\n    .\n    .\n    .\n     'weather' =\u003e [\n        'key' =\u003e env('WEATHER_API_KEY'),\n    ],\n```\n\n然后在 `.env` 中配置 `WEATHER_API_KEY` ：\n\n```env\nWEATHER_API_KEY=xxxxxxxxxxxxxxxxxxxxx\n```\n\n可以用两种方式来获取 `Overtrue\\Weather\\Weather` 实例：\n\n#### 方法参数注入\n\n```php\n    .\n    .\n    .\n    public function edit(Weather $weather)\n    {\n        $response = $weather-\u003egetLiveWeather('深圳');\n    }\n    .\n    .\n    .\n```\n\n#### 服务名访问\n\n```php\n    .\n    .\n    .\n    public function edit()\n    {\n        $response = app('weather')-\u003egetLiveWeather('深圳');\n    }\n    .\n    .\n    .\n\n```\n\n## 参考\n\n- [高德开放平台天气接口](https://lbs.amap.com/api/webservice/guide/api/weatherinfo/)\n\n## :heart: Sponsor me\n\n[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue)\n\n如果你喜欢我的项目并想支持它，[点击这里 :heart:](https://github.com/sponsors/overtrue)\n\n\n## Project supported by JetBrains\n\nMany thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.\n\n[![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/overtrue)\n\n## PHP 扩展包开发\n\n\u003e 想知道如何从零开始构建 PHP 扩展包？\n\u003e\n\u003e 请关注我的实战课程，我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovertrue%2Fweather","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fovertrue%2Fweather","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovertrue%2Fweather/lists"}