PHPackages                             cannonsir/weather - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cannonsir/weather

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cannonsir/weather
=================

A weather SDK

0.0.2(6y ago)06MITPHP

Since Jul 16Pushed 6y agoCompare

[ Source](https://github.com/cannonsir/weather)[ Packagist](https://packagist.org/packages/cannonsir/weather)[ RSS](/packages/cannonsir-weather/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

 weather
=========

[](#-weather-)

基于 [高德开放平台](https://lbs.amap.com/dev/index) 的 PHP 天气信息组件。

安装
--

[](#安装)

```
$ composer require cannonsir/weather -vvv
```

使用
--

[](#使用)

> 在使用本扩展之前，你需要去 [高德开放平台](https://lbs.amap.com/dev/key/app) 注册账号，然后创建应用，获取应用的 API Key

```
use CannonSir\Weather\Weather;

$weather = new Weather('your api key');
```

获取实时天气
------

[](#获取实时天气)

```
$weather->getWeather('成都')
$weather->getLiveWeather('成都', 'json')
```

返回结果示例:

```
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "lives": [
        {
            "province": "四川",
            "city": "成都市",
            "adcode": "510100",
            "weather": "晴",
            "temperature": "24",
            "winddirection": "东",
            "windpower": "≤3",
            "humidity": "94",
            "reporttime": "2019-07-17 23:52:01"
        }
    ]
}
```

获取近期天气预报
--------

[](#获取近期天气预报)

```
$weather->getWeather('成都', 'forecasts');
```

返回结果示例

```
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "forecasts": [
        {
            "city": "成都市",
            "adcode": "510100",
            "province": "四川",
            "reporttime": "2019-07-17 23:52:01",
            "casts": [
                {
                    "date": "2019-07-17",
                    "week": "3",
                    "dayweather": "多云",
                    "nightweather": "晴",
                    "daytemp": "29",
                    "nighttemp": "23",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-07-18",
                    "week": "4",
                    "dayweather": "阵雨",
                    "nightweather": "阵雨",
                    "daytemp": "31",
                    "nighttemp": "23",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-07-19",
                    "week": "5",
                    "dayweather": "阵雨",
                    "nightweather": "阵雨",
                    "daytemp": "31",
                    "nighttemp": "24",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-07-20",
                    "week": "6",
                    "dayweather": "阵雨",
                    "nightweather": "小雨",
                    "daytemp": "33",
                    "nighttemp": "23",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                }
            ]
        }
    ]
}
```

> 通过传递第最后一个参数可设置返回值类型: `json/xml` 默认`json`格式

参数说明
----

[](#参数说明)

```
array|string getWeather(string $city, string $type = 'live', string $format = 'json')
```

> - $city - 城市名，比如：“深圳”；
> - $type - 返回内容类型：live: 返回实况天气 / forecasts: 返回预报天气；
> - $format - 输出的数据格式，默认为 json 格式，当 format 设置为 “xml” 时，输出的为 XML 格式的数据。

在 Laravel 中使用
-------------

[](#在-laravel-中使用)

在Laravel中使用也是同样的安装方式，配置写在 config/services.php 中:

```
'weather' => [
    'key' => env('AMAP_API_KEY')
]
```

然后在 `.env` 文件中配置 `AMAP_API_KEY`

```
AMAP_API_KEY=xxxxxxxxxxxxxxxxxxxxx
```

参考
--

[](#参考)

- [高德开放平台天气接口](https://lbs.amap.com/api/webservice/guide/api/weatherinfo/)

License
-------

[](#license)

MIT

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

2540d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f24a33f91882ecea6535674aeb30e80b8577b30140a5c7ac89dc2df0cc3b285a?d=identicon)[HeJiaNong](/maintainers/HeJiaNong)

---

Top Contributors

[![jianongHe](https://avatars.githubusercontent.com/u/39476157?v=4)](https://github.com/jianongHe "jianongHe (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cannonsir-weather/health.svg)

```
[![Health](https://phpackages.com/badges/cannonsir-weather/health.svg)](https://phpackages.com/packages/cannonsir-weather)
```

###  Alternatives

[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k496.1k33](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.2M46](/packages/tencentcloud-tencentcloud-sdk-php)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751284.3k37](/packages/civicrm-civicrm-core)[roundcube/roundcubemail

The Roundcube Webmail suite

7.0k1.4k3](/packages/roundcube-roundcubemail)[spatie/laravel-export

Create a static site bundle from a Laravel app

672139.5k6](/packages/spatie-laravel-export)[nfse-nacional/nfse-php

This is my package nfse

1523.1k](/packages/nfse-nacional-nfse-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
