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

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

lepig/weather
=============

A weather SDK.

0.0.2(7y ago)09MITPHP

Since Feb 18Pushed 7y ago1 watchersCompare

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

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

 weather
=========

[](#-weather-)

[![Build Status](https://camo.githubusercontent.com/83a005d98f1037a89ab8df61669875af89c7fe49d6490df283ec38f805235c51/68747470733a2f2f7472617669732d63692e6f72672f6c655069672f776561746865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/lePig/weather)

 A weather SDK..

Installing
----------

[](#installing)

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

配置
--

[](#配置)

在使用此组件之前，你需要去[高德开放平台](https://lbs.amap.com/dev/index)注册帐号，并申请应用，获取应用的API Key.

Usage
-----

[](#usage)

```
use Lepig\Weather\Weather;

$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

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

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

[](#获取实时天气)

```
$weather->getWeather('滁州');
```

返回结果示例：

```
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "lives": [
        {
            "province": "安徽",
            "city": "滁州市",
            "adcode": "341100",
            "weather": "多云",
            "temperature": "2",
            "winddirection": "西北",
            "windpower": "≤3",
            "humidity": "84",
            "reporttime": "2019-02-19 11:17:22"
        }
    ]
}
```

获取最近几天的天气
---------

[](#获取最近几天的天气)

```
$weather->getWeather('滁州', 'all');
```

返回结果示例：

```
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "forecasts": [
        {
            "city": "滁州市",
            "adcode": "341100",
            "province": "安徽",
            "reporttime": "2019-02-19 11:17:22",
            "casts": [
                {
                    "date": "2019-02-19",
                    "week": "2",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "5",
                    "nighttemp": "2",
                    "daywind": "西北",
                    "nightwind": "西北",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-02-20",
                    "week": "3",
                    "dayweather": "小雨",
                    "nightweather": "阴",
                    "daytemp": "6",
                    "nighttemp": "3",
                    "daywind": "东北",
                    "nightwind": "东北",
                    "daypower": "4",
                    "nightpower": "4"
                },
                {
                    "date": "2019-02-21",
                    "week": "4",
                    "dayweather": "小雨",
                    "nightweather": "中雨",
                    "daytemp": "10",
                    "nighttemp": "0",
                    "daywind": "东北",
                    "nightwind": "东北",
                    "daypower": "4",
                    "nightpower": "4"
                },
                {
                    "date": "2019-02-22",
                    "week": "5",
                    "dayweather": "多云",
                    "nightweather": "晴",
                    "daytemp": "4",
                    "nighttemp": "0",
                    "daywind": "北",
                    "nightwind": "北",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                }
            ]
        }
    ]
}
```

独立的方法调用
-------

[](#独立的方法调用)

### 获取实时天气

[](#获取实时天气-1)

```
$weather->getLiveWeather('滁州');
```

### 获取未来几天天气预报

[](#获取未来几天天气预报)

```
$weather->getForecastsWeather('滁州');
```

参数说明
----

[](#参数说明)

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

> $city - 城市名称或城市adcode $type - 返回内容类型： base-&gt;返回实时天气 all-&gt;返回预报天气 $format - 输出的数据格式，默认为json。 可选xml

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

[](#在laravel中使用)

在Laravel中和之前的安装方式一致。申请的key值需要配置在`config/services.php`中：

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

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

```
WEATHER_API_KEY=xxxxxxxxxxxxxxxxxxxxx
```

说明
--

[](#说明)

实例`$weather`的获取可以通过参数注入的方式，也可以通过服务名的方式。

### 通过参数注入

[](#通过参数注入)

```
public function show(Weather $weather, $city)
{
    return $weather->getWeather($city);
}
```

### 通过服务名方式

[](#通过服务名方式)

```
public function show($city)
{
    return app('weather')->getWeather($city, 'all', 'xml');
}
```

TODO

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

[](#contributing)

You can contribute in one of three ways:

1. File bug reports using the [issue tracker](https://github.com/lepig/weather/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/lepig/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 ~1 days

Total

2

Last Release

2640d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d2ea23d453051ae6f977dc8b6840d335de36eac34a982f62b8fc1ef07695b1f?d=identicon)[lepig](/maintainers/lepig)

---

Top Contributors

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

### Embed Badge

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

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