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

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

crackersw/weather
=================

获取天气预报SDK

0.2(4y ago)19MITPHP

Since Apr 22Pushed 3y ago1 watchersCompare

[ Source](https://github.com/CrackerSW/weather)[ Packagist](https://packagist.org/packages/crackersw/weather)[ RSS](/packages/crackersw-weather/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

 weather
=========

[](#-weather-)

 基于高德开放API获取天气预报SDK.

- crackersw/weater

### 安装

[](#安装)

```
composer require crackersw/weather -vvv
```

### 配置

[](#配置)

在使用本扩展之前，你需要去高德开放平台注册账号，然后创建应用，获取应用的API Key。

### 使用

[](#使用)

```
use CrackerSw\Weather\Weather;
$key = "xxxxxxxxxxxxxxxxxxxxx";
$weather = new Weather($key);
```

### 获取实时天气

[](#获取实时天气)

```
$response = $weather->getLiveWeather("无锡");
```

返回示例

```
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "lives": [
        {
            "province": "江苏",
            "city": "无锡市",
            "adcode": "320200",
            "weather": "多云",
            "temperature": "28",
            "winddirection": "西",
            "windpower": "≤3",
            "humidity": "40",
            "reporttime": "2022-04-22 13:37:16"
        }
    ]
}
```

### 获取近期天气预报

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

```
$response = $weather->getForecastsWeather("无锡");
```

返回示例

```
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "forecasts": [
        {
            "city": "无锡市",
            "adcode": "320200",
            "province": "江苏",
            "reporttime": "2022-04-22 13:37:16",
            "casts": [
                {
                    "date": "2022-04-22",
                    "week": "5",
                    "dayweather": "多云",
                    "nightweather": "中雨",
                    "daytemp": "30",
                    "nighttemp": "19",
                    "daywind": "南",
                    "nightwind": "南",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2022-04-23",
                    "week": "6",
                    "dayweather": "小雨",
                    "nightweather": "多云",
                    "daytemp": "26",
                    "nighttemp": "16",
                    "daywind": "东南",
                    "nightwind": "东南",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2022-04-24",
                    "week": "7",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "29",
                    "nighttemp": "18",
                    "daywind": "东南",
                    "nightwind": "东南",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2022-04-25",
                    "week": "1",
                    "dayweather": "暴雨",
                    "nightweather": "小雨",
                    "daytemp": "28",
                    "nighttemp": "21",
                    "daywind": "东南",
                    "nightwind": "东南",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                }
            ]
        }
    ]
}
```

### 获取XML格式返回值

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

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

```
$response = $weather->getLiveWeather("无锡","xml");
```

返回示例

```

    1
    1
    OK
    10000

            江苏
            无锡市
            320200
            多云
            28
            西
            ≤3
            40
            2022-04-22 13:37:16

```

### 参数说明

[](#参数说明)

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

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

### 在Laravel中使用

[](#在laravel中使用)

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

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

然后在`.env`中配置`WEATHER_API_KEY`:

```
WEATHER_API_KEY=xxxxxxxxxxxxxxxxxxxxx
```

可以用两种方式来获取`CrackerSw\Weather\Weather`实例:

**方法参数注入**

```
    .
    .
    .
    public function getWeather(Weather $weather)
    {
        $response = $weather->getLiveWeather('无锡');
    }
    .
    .
    .
```

**服务名访问**

```
    .
    .
    .
    public function getWeather(Weather $weather)
    {
        $response = app('weather')->getLiveWeather('无锡');
    }
    .
    .
    .
```

License
-------

[](#license)

MIT

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

1487d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

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

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

PHPackages © 2026

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