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

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

smallk/weather
==============

A weather

0.01(7y ago)02MITPHP

Since Jan 2Pushed 7y agoCompare

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

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

 weather
=========

[](#-weather-)

 A weather SDK.

Installing
----------

[](#installing)

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

使用
--

[](#使用)

```
    use Smallk\Weather\Weather;

    $key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

    $weather = new Weahter;

```

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

[](#获取实时天气)

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

```

### 示列

[](#示列)

```
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "lives": [
        {
            "province": "上海",
            "city": "上海市",
            "adcode": "310000",
            "weather": "晴",
            "temperature": "4",
            "winddirection": "东南",
            "windpower": "≤3",
            "humidity": "60",
            "reporttime": "2019-01-02 10:14:58"
        }
    ]
}

```

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

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

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

```

### 示列

[](#示列-1)

```
    {
        "status": "1",
        "count": "1",
        "info": "OK",
        "infocode": "10000",
        "forecasts": [
            {
            "city": "上海市",
            "adcode": "310000",
            "province": "上海",
            "reporttime": "2019-01-02 10:14:58",
            "casts": [
                    {
                    "date": "2019-01-02",
                    "week": "3",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "7",
                    "nighttemp": "4",
                    "daywind": "北",
                    "nightwind": "北",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                    },
                    {
                    "date": "2019-01-03",
                    "week": "4",
                    "dayweather": "阴",
                    "nightweather": "小雨",
                    "daytemp": "10",
                    "nighttemp": "5",
                    "daywind": "东北",
                    "nightwind": "东北",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                    },
                    {
                    "date": "2019-01-04",
                    "week": "5",
                    "dayweather": "小雨",
                    "nightweather": "小雨",
                    "daytemp": "10",
                    "nighttemp": "8",
                    "daywind": "东",
                    "nightwind": "东",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                    },
                    {
                    "date": "2019-01-05",
                    "week": "6",
                    "dayweather": "小雨",
                    "nightweather": "小雨",
                    "daytemp": "9",
                    "nighttemp": "5",
                    "daywind": "东北",
                    "nightwind": "东北",
                    "daypower": "4",
                    "nightpower": "4"
                    }
                ]
            }
        ]
    }

```

获取XML格式返回
---------

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

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

 $response = $weather->getWather('上海', 'all' ,'json');

```

### 示列

[](#示列-2)

```

    1
    1
    OK
    10000

    上海市
    310000
    上海
    2019-01-02 10:14:58

            2019-01-023
            多云
            多云
            7
            4
            北
            北
            ≤3
            ≤3

            2019-01-03
            4
            阴
            小雨
            10
            5
            东北
            东北
            ≤3
            ≤3

            2019-01-04
            5
            小雨
            小雨
            10
            8
            东
            东
            ≤3
            ≤3

            2019-01-05
            6
            小雨
            小雨
            9
            5
            东北
            东北
            4
            4

```

参数说明
----

[](#参数说明)

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

```

字段值说明citystring城市名('上海')typestring返回内容类型: base : 返回实况天气 / all : 返回预报天气formatstring输出的数据格式，默认为 json 格式，当 output 设置为 “xml” 时，输出的为 XML 格式的数据。在 Laravel 中使用
-------------

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

### 1. 在Laravel 中使用也是一样的安装方式,配置写在 config/services.php中

[](#1-在laravel-中使用也是一样的安装方式配置写在-configservicesphp中)

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

```

### 2.然后在 .env 中配置 WEATHER\_API\_KEY

[](#2然后在-env-中配置-weather_api_key)

```
  WEATHER_API_KEY=xxxxxxxxxxxxxxxxxxxxx

```

### 3. 方法注入参数

[](#3-方法注入参数)

```
  public function edit (Weather $weather)
  {
      $response = $weather->getWather('上海');
  }

```

### 4. 服务器访问名字

[](#4-服务器访问名字)

```
  public funtion edit ()
  {
      $response = app->('weather')->getWather('上海');
  }

```

参考
--

[](#参考)

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

License
-------

[](#license)

MIT

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

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

2690d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/85547c88592556535af1d832bcc38e11ce924330e147c6ecc02adcb3af3c266d?d=identicon)[smallk1002](/maintainers/smallk1002)

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/smallk-weather/health.svg)](https://phpackages.com/packages/smallk-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)
