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

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

run6/weather
============

A weather SDK

0.0.1(6y ago)09MITPHPPHP &gt;=7.1.0

Since Jun 10Pushed 6y agoCompare

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

READMEChangelog (1)Dependencies (4)Versions (4)Used By (0)

 weather
=========

[](#-weather-)

 A weather SDK.

[![Build Status](https://camo.githubusercontent.com/3602bc1013e6d1b8ca9affb056aa4f89e41d39692c1ae2952366d1610830ffbe/68747470733a2f2f7472617669732d63692e6f72672f72756e362f776561746865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/run6/weather)[![StyleCI](https://camo.githubusercontent.com/d47f7f162edec91712b9a25013db2a5729aebd329d662b97a783399ff54e732a/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3139303838333535342f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/190883554)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/24afedb9fbbc2133c22bcd0ce15533f298d903b73898edc38a8fa6c6f2eb9ce9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72756e362f776561746865722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/run6/weather/?branch=master)[![Packagist](https://camo.githubusercontent.com/f871ce212231f2eac51ac76820a35bf3a19f0acd0e1573654dafc85db1652a79/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72756e362f776561746865722e737667)](https://packagist.org/packages/run6/weather)

Installing
----------

[](#installing)

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

Usage
-----

[](#usage)

### 配置

[](#配置)

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

### 开始

[](#开始)

```
use Run6\Weather\Weather;

$key = 'xxxxxxxxxxxxxxx'; //替换成你的API—KEY

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

### 获取实时的天气

[](#获取实时的天气)

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

### 返回实例

[](#返回实例)

```
{
  "status": "1",
  "count": "1",
  "info": "OK",
  "infocode": "10000",
  "lives": [
    {
      "province": "浙江",
      "city": "杭州市",
      "adcode": "330100",
      "weather": "多云",
      "temperature": "33",
      "winddirection": "东",
      "windpower": "≤3",
      "humidity": "50",
      "reporttime": "2019-06-10 13:51:19"
    }
  ]
}
```

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

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

```
$response = $weather->getWeather('杭州','all')
```

### 返回实例

[](#返回实例-1)

```
{
  "status": "1",
  "count": "1",
  "info": "OK",
  "infocode": "10000",
  "forecasts": [
    {
      "city": "杭州市",
      "adcode": "330100",
      "province": "浙江",
      "reporttime": "2019-06-10 13:51:19",
      "casts": [
        {
          "date": "2019-06-10",
          "week": "1",
          "dayweather": "小雨",
          "nightweather": "多云",
          "daytemp": "33",
          "nighttemp": "21",
          "daywind": "东北",
          "nightwind": "东北",
          "daypower": "≤3",
          "nightpower": "≤3"
        },
        {
          "date": "2019-06-11",
          "week": "2",
          "dayweather": "多云",
          "nightweather": "多云",
          "daytemp": "29",
          "nighttemp": "21",
          "daywind": "东北",
          "nightwind": "东北",
          "daypower": "≤3",
          "nightpower": "≤3"
        },
        {
          "date": "2019-06-12",
          "week": "3",
          "dayweather": "多云",
          "nightweather": "多云",
          "daytemp": "29",
          "nighttemp": "21",
          "daywind": "东",
          "nightwind": "东",
          "daypower": "4",
          "nightpower": "4"
        },
        {
          "date": "2019-06-13",
          "week": "4",
          "dayweather": "小雨",
          "nightweather": "晴",
          "daytemp": "29",
          "nighttemp": "18",
          "daywind": "无风向",
          "nightwind": "无风向",
          "daypower": "≤3",
          "nightpower": "≤3"
        }
      ]
    }
  ]
}
```

### 获取XML格式返回值

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

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

```
$response = $weather('杭州','base','xml')
```

### 返回实例

[](#返回实例-2)

```

  1
  1
  OK
  10000

      浙江
      杭州市
      330100
      多云
      33
      东
      ≤3
      50
      2019-06-10 13:51:19

```

### 参数说明

[](#参数说明)

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

> - `$city` - 城市名，比如："杭州";
> - `$type` - 返回内容：`base`： 返回实时天气 / `all`:返回天气预报
> - `$format` - 输出的数据格式，默认为 `json`, 当设置为 `xml` 时，输出XML格式数据。

### Laravel 中使用

[](#laravel-中使用)

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

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

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

```
WEATHER_API_KEY=xxxxxxxxx
```

可以使用两种方式获取 `Run6\Weather\Weather` 实例：

#### 方式参数注入

[](#方式参数注入)

```
    ·
    ·
    ·
    // 在控制器中通过依赖注入的方式
    public function getWeather(Weather $weather)
    {
        $response = $weather->getWeather('杭州');
    }
    .
    .
    .
```

#### 服务名访问

[](#服务名访问)

```
    .
    .
    .
    pubcli function getWeather()
    {
        $response = app('weather')->getWeather('杭州');
    }
    .
    .
    .
```

参考
--

[](#参考)

- [高德开放平台天气接口](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/run6/composer-test/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/run6/composer-test/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

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

Unknown

Total

1

Last Release

2531d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[aedart/athenaeum

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

245.2k](/packages/aedart-athenaeum)[nativephp/mobile

NativePHP for Mobile

82724.0k43](/packages/nativephp-mobile)[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[pulkitjalan/ip-geolocation

IP Geolocation Wrapper with Laravel Support

89164.9k1](/packages/pulkitjalan-ip-geolocation)[bakame/laravel-domain-parser

Laravel package to integrate PHP Domain parser.

26534.8k4](/packages/bakame-laravel-domain-parser)

PHPackages © 2026

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