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

ActiveLibrary

zhanxin/weather
===============

通过IPv4、IPv6查询天气

020PHP

Since Jun 16Pushed 4y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Weather
=======

[](#weather)

基于纯真IP库与百度天气API的支持IPv4、IPv6天气组件。

> 百度接口文档链接在文末

安装
--

[](#安装)

```
$ composer require zhanxin/weather
```

配置
--

[](#配置)

在使用本扩展之前，你需要去 [百度开放平台](https://lbs.baidu.com/apiconsole/key) 注册账号，然后创建应用，获取应用的 AK。

使用
--

[](#使用)

```
use Zx\Weather\Weather;

$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

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

### 获取天气信息

[](#获取天气信息)

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

示例：

```
{
	"status": 0,
	"result": {
		"location": {
			"country": "中国",
			"province": "广东省",
			"city": "广州市",
			"name": "广州",
			"id": "440100"
		},
		"now": {
			"text": "多云",
			"temp": 30,
			"feels_like": 36,
			"rh": 74,
			"wind_class": "2级",
			"wind_dir": "东南风",
			"uptime": "20210615111500"
		},
		"forecasts": [{
			"text_day": "雷阵雨",
			"text_night": "雷阵雨",
			"high": 33,
			"low": 26,
			"wc_day": "3~4级",
			"wd_day": "西南风",
			"wc_night": "
