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

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

herensi/weather
===============

A weather SDK.

1.0.0(7y ago)015MITPHP

Since Aug 21Pushed 7y agoCompare

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

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

Weather
=======

[](#weather)

🌈 基于百度地图接口的 PHP 天气信息组件。

[![Build Status](https://camo.githubusercontent.com/66c2975ae0688fd25e59dd711754cb806451f9aa46015cd1f1fedd6396fcddb2/68747470733a2f2f7472617669732d63692e6f72672f686572656e73692f776561746865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/herensi/weather)[![StyleCI build status](https://camo.githubusercontent.com/21f75e86a3678ccb4f7801a145e91c5597b46e3f409c493375614b23ba0e9622/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134353531343130382f736869656c64)](https://camo.githubusercontent.com/21f75e86a3678ccb4f7801a145e91c5597b46e3f409c493375614b23ba0e9622/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134353531343130382f736869656c64)

安装
--

[](#安装)

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

配置
--

[](#配置)

在使用本拓展之前，你需要去 [百度地图](http://lbsyun.baidu.com/index.php?title=car/api/weather) 注册账号，然后创建应用，获取应用的 `ak` 值

使用
--

[](#使用)

使用
--

[](#使用-1)

```
use Herensi\Weather\Weather;

$ak = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$weather = new Weather($ak);

// 返回数组格式
$response = $weather->getWeather('深圳');

// 批量获取
$response = $weather->getWeather('深圳|北京');

// 返回 XML 格式
$response = $weather->getWeather('深圳', 'xml');

// 按坐标获取
$response = $weather->getWeather('116.30,39.98', 'json');

// 批量坐标获取
$response = $weather->getWeather('116.43,40.75|120.22,43,33', 'json');

// 自定义坐标格式（coord_type）
$response = $weather->getWeather('116.306411,39.981839', 'json', 'bd09ll');
```

### 参数说明

[](#参数说明)

```
array | string   getWeather(string $location, string $format = 'json', string $coordType = null)

```

> 参数说明：
>
> - `$location` - 支持经纬度和城市名两种形式，一次请求最多支持 15 个城市，之间用 "|" 分隔，同一个城市的经纬度之间用 "," 分隔。举例：`$location = "116.43,40.75|120.22,43,33"` 或者是 `$location = "北京|上海|广州"` 。
> - `$format` - 输出的数据格式，默认为 json 格式，当 output 设置为 ’xml’ 时，输出的为 xml 格式的数据。
> - `$coordType` - 请求参数坐标类型，默认为 `gcj02` 经纬度坐标。允许的值为 `bd09ll`、`bd09mc`、`gcj02`、`wgs84`。`bd09ll` 表示百度经纬度坐标，`bd09mc`表示百度墨卡托坐标，`gcj02` 表示经过国测局加密的坐标。`wgs84` 表示 `gps` 获取的坐标。
> - 详情说明请参考官方：

### 在 Laravel 中使用

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

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

```
	.
	.
	.
	 'weather' => [
        'ak' => env('BAIDU_WEATHER_AK'),
        'sn' => env('BAIDU_WEATHER_SN'),
    ],
```

然后在 `.env` 中配置（`BAIDU_WEATHER_SN` 为可选）：

```
BAIDU_WEATHER_AK=
BAIDU_WEATHER_SN=
```

可以用两种方式来获取 `Herensi\Weather\Weather` 实例：

#### 方法参数注入

[](#方法参数注入)

```
use Herensi\Weather\Weather;

...

public function edit(Weather $weather)
{
    $response = $weather->get('深圳');
}
```

#### 服务名访问

[](#服务名访问)

```
	public function edit()
	{
		$response = app('weather')->get('深圳');
	}
```

参考
--

[](#参考)

- [百度地图天气接口](http://lbsyun.baidu.com/index.php?title=car/api/weather)

License
-------

[](#license)

MIT

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

2824d ago

Major Versions

0.0.1 → 1.0.02018-08-21

### Community

Maintainers

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

---

Tags

weather-sdk

### Embed Badge

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

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