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

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

wenslim/weather
===============

A weather SDK for amap

0.0.2(6y ago)07[2 PRs](https://github.com/wenslim/weather/pulls)MITPHP

Since Jun 9Pushed 3y agoCompare

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

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

Weather
=======

[](#weather)

基于「\[高德开放平台」的`PHP`天气信息组件

[![Build Status](https://camo.githubusercontent.com/98cb7c1653a6ca0b8f3c4594c9c985ee5a5edd8ec79e72c7de0a1edf6d688a82/68747470733a2f2f7472617669732d63692e6f72672f77656e736c696d2f776561746865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/wenslim/weather)[![StyleCI build status](https://camo.githubusercontent.com/60baafbca03f669d24e5f352aee1ce84f5df204f364db928d8cf10ec80a3e739/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3139303936303938382f736869656c64)](https://camo.githubusercontent.com/60baafbca03f669d24e5f352aee1ce84f5df204f364db928d8cf10ec80a3e739/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3139303936303938382f736869656c64)[![Latest Stable Version](https://camo.githubusercontent.com/8bc9f8e7e2aad023714700cffef0e520eb6f9041f73395ebed79789ccc71ed2e/68747470733a2f2f706f7365722e707567782e6f72672f77656e736c696d2f776561746865722f762f737461626c65)](https://packagist.org/packages/wenslim/weather)[![Latest Unstable Version](https://camo.githubusercontent.com/745017a8b4dd036873b6d295b813264ec5a5e127e9a9d9914d5b4aa2e097a140/68747470733a2f2f706f7365722e707567782e6f72672f77656e736c696d2f776561746865722f762f756e737461626c65)](https://packagist.org/packages/wenslim/weather)[![License](https://camo.githubusercontent.com/5f766f19e134ee3272a91b3952e4617e215b4fa08ad160d40ffb1d7febe3f759/68747470733a2f2f706f7365722e707567782e6f72672f77656e736c696d2f776561746865722f6c6963656e7365)](https://packagist.org/packages/wenslim/weather)

#### 安装

[](#安装)

```
$ composer require wenslim/weather -vvv

```

#### 配置

[](#配置)

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

#### 基本使用

[](#基本使用)

```
use Wenslim\Weather\Weather;

$key = 'xxxxxx';
$weather = new Weather($key);

```

#### 获取实时天气

[](#获取实时天气)

```
$response = $weather->getLiveWeather('上海');

```

示例：

```
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "lives": [
        {
            "province": "上海",
            "city": "上海市",
            "adcode": "310000",
            "weather": "阴",
            "temperature": "26",
            "winddirection": "西北",
            "windpower": "≤3",
            "humidity": "59",
            "reporttime": "2019-06-08 10:49:45"
        }
    ]
}

```

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

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

```
$response = $weather->getForecastsWeather('上海', 'all');

```

示例：

```
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "forecasts": [
    {
        "city": "上海市",
        "adcode": "310000",
        "province": "上海",
        "reporttime": "2019-06-08 10:49:45",
        "casts": [
        {
            "date": "2019-06-08",
            "week": "6",
            "dayweather": "多云",
            "nightweather": "多云",
            "daytemp": "29",
            "nighttemp": "21",
            "daywind": "东南",
            "nightwind": "东南",
            "daypower": "≤3",
            "nightpower": "≤3"
        },
        {
            "date": "2019-06-09",
            "week": "7",
            "dayweather": "多云",
            "nightweather": "多云",
            "daytemp": "30",
            "nighttemp": "22",
            "daywind": "东南",
            "nightwind": "东南",
            "daypower": "≤3",
            "nightpower": "≤3"
        },
        {
            "date": "2019-06-10",
            "week": "1",
            "dayweather": "小雨",
            "nightweather": "多云",
            "daytemp": "30",
            "nighttemp": "21",
            "daywind": "东北",
            "nightwind": "东北",
            "daypower": "4",
            "nightpower": "4"
        },
        {
            "date": "2019-06-11",
            "week": "2",
            "dayweather": "多云",
            "nightweather": "多云",
            "daytemp": "29",
            "nighttemp": "21",
            "daywind": "东",
            "nightwind": "东",
            "daypower": "4",
            "nightpower": "4"
        }]
    }]
}

```

#### 获取 XML 格式返回值

[](#获取-xml-格式返回值)

第三个参数为返回值类型，可选 `json` 与 `xml`，默认 `json`：

```
$response = $weather->getLiveWeather('上海', 'xml');

```

示例

```

    1
    1
    OK
    10000

            上海
            上海市
            310000
            晴
            26
            西北
            ≤3
            69
            2019-06-09 11:18:31

```

#### 参数说明

[](#参数说明)

```
array|string getLiveWeather(string $city, string $format = 'json')

```

> - $city - 城市名，比如：“上海”；
> - $format - 输出的数据格式，默认为 json 格式，当 output 设置为 “xml” 时，输出的为 XML 格式的数据。

#### 在`laravel`中使用

[](#在laravel中使用)

配置写在`config/services.php`中

```
    .
    .
    .
    'weather' => [
        'key' => env('WEATHER_API_KEY'),
    ],

```

`.env`中配置`WEATHER_API_KEY`：

```
WEATHER_API_KEY=xxxxxxxxxxxxxxxxxxxxx

```

可以用两种方式来获取`Wenslim\Weather\Weather`实例：

##### 方法参数注入

[](#方法参数注入)

```
use Wenslim\Weather\Weather;

public function show(Weather $weather)
{
    $response = $weather->getLiveWeather('上海');
}

```

##### 服务名访问

[](#服务名访问)

```
public function show(Weather $weather)
{
    $response = app('weather')->getLiveWeather('上海');
}

```

#### License

[](#license)

MIT

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

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

2531d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0244f4a24cff48db8596c2c11eb725792f0866614f52c66a75527b1282fea0ac?d=identicon)[Wenslim](/maintainers/Wenslim)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[dhlparcel/magento2-plugin

DHL Parcel plugin for Magento 2

11180.5k2](/packages/dhlparcel-magento2-plugin)[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)
