PHPackages                             sssword/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. sssword/weather

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

sssword/weather
===============

a weather SDK

0.0.2(7y ago)09MITPHP

Since Jan 22Pushed 7y ago1 watchersCompare

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

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

weather
-------

[](#weather)

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

[![Build Status](https://camo.githubusercontent.com/318f61bc990b4703d69450e674437c3fce16b0fe88687f7bce1c7a614a0f0b48/68747470733a2f2f7472617669732d63692e6f72672f737373776f72642f776561746865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sssword/weather)

安装Installing
------------

[](#安装installing)

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

配置
--

[](#配置)

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

使用Usage
-------

[](#使用usage)

```
use Sssword\Weather\Weather;

$key = '高德开放平台APP Key';

$weather = new Weather($key);
```

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

[](#获取实时天气)

```
$response = $weather->getWeather('230100');
```

示例：

```
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "lives": [
        {
            "province": "黑龙江",
            "city": "哈尔滨市",
            "adcode": "230100",
            "weather": "多云",
            "temperature": "-6",
            "winddirection": "西",
            "windpower": "≤3",
            "humidity": "53",
            "reporttime": "2019-01-22 17:12:22"
        }
    ]
}
```

获取预报天气
------

[](#获取预报天气)

```
$response = $weather->getWeather('230100', 'all');
```

示例：

```
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "forecasts": [
        {
            "city": "哈尔滨市",
            "adcode": "230100",
            "province": "黑龙江",
            "reporttime": "2019-01-22 17:12:22",
            "casts": [
                {
                    "date": "2019-01-22",
                    "week": "2",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "-3",
                    "nighttemp": "-17",
                    "daywind": "西",
                    "nightwind": "西",
                    "daypower": "4",
                    "nightpower": "4"
                },
                {
                    "date": "2019-01-23",
                    "week": "3",
                    "dayweather": "晴",
                    "nightweather": "晴",
                    "daytemp": "-8",
                    "nighttemp": "-20",
                    "daywind": "西北",
                    "nightwind": "西北",
                    "daypower": "4",
                    "nightpower": "4"
                },
                {
                    "date": "2019-01-24",
                    "week": "4",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "-7",
                    "nighttemp": "-18",
                    "daywind": "西北",
                    "nightwind": "西北",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-01-25",
                    "week": "5",
                    "dayweather": "阵雪",
                    "nightweather": "多云",
                    "daytemp": "-9",
                    "nighttemp": "-19",
                    "daywind": "西北",
                    "nightwind": "西北",
                    "daypower": "4",
                    "nightpower": "4"
                }
            ]
        }
    ]
}
```

参数说明
----

[](#参数说明)

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

- $city -城市名，e.g. "哈尔滨";
- $type -返回内容类型，*`base`*: 返回实况天气，*`all`*: 返回预报天气;
- $format -输出数据格式，*`json`*: JSON格式，*`xml`*: XML格式;

参考
--

[](#参考)

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

Contributing
------------

[](#contributing)

You can contribute in one of three ways:

1. File bug reports using the [issue tracker](https://github.com/sssword/weather/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/sssword/weather/issues).
3. Contribute new features or update the wiki.

*The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.*

License
-------

[](#license)

MIT

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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 ~0 days

Total

2

Last Release

2670d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/09c4933bf4727d066ac9ff69bc58cf375c5857b8b472ddb6d5116ed156f858da?d=identicon)[sssword](/maintainers/sssword)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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