PHPackages                             livissnack/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. [API Development](/categories/api)
4. /
5. livissnack/weather

ActiveLibrary[API Development](/categories/api)

livissnack/weather
==================

A weather SDK

1.0.0(7y ago)110MITPHP

Since Aug 21Pushed 7y ago1 watchersCompare

[ Source](https://github.com/livissnack/weather)[ Packagist](https://packagist.org/packages/livissnack/weather)[ RSS](/packages/livissnack-weather/feed)WikiDiscussions master Synced yesterday

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

Weather
=======

[](#weather)

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

[![Build Status](https://camo.githubusercontent.com/e37cc2c45224d3010240bdbcdde25c192bc5cd344511965e2135a065daabf84b/68747470733a2f2f7472617669732d63692e6f72672f6c69766973736e61636b2f776561746865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/livissnack/weather)[![StyleCI build status](https://camo.githubusercontent.com/695f0c8a9c8dea42d31d0df331dad1c08557bc0f3353d1748e429dc2ba54f4d8/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134343831383030342f736869656c64)](https://camo.githubusercontent.com/695f0c8a9c8dea42d31d0df331dad1c08557bc0f3353d1748e429dc2ba54f4d8/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134343831383030342f736869656c64) [![Issues](https://camo.githubusercontent.com/0826081c52d9f0aa4bd5b1f6a3e62e37c76ffbf16283f36d30667f14e3f57175/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6c69766973736e61636b2f776561746865722e737667)](https://github.com/livissnack/weather/issues) [![Forks](https://camo.githubusercontent.com/1eb975bc3b2f06ecc897eb29650c6f81cd274c16a1bcbdae89323e3a82ea506a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6c69766973736e61636b2f776561746865722e737667)](https://camo.githubusercontent.com/1eb975bc3b2f06ecc897eb29650c6f81cd274c16a1bcbdae89323e3a82ea506a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6c69766973736e61636b2f776561746865722e737667)

安装
--

[](#安装)

```
$ composer require livissnack/weather
```

配置
--

[](#配置)

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

使用
--

[](#使用)

```
use Livissnack\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=
```

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

#### 方法参数注入

[](#方法参数注入)

```
use Livissnack\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)

the MIT License,

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

2870d ago

Major Versions

0.0.1 → 1.0.02018-08-21

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17075935?v=4)[livissnack](/maintainers/livissnack)[@livissnack](https://github.com/livissnack)

---

Top Contributors

[![livissnack](https://avatars.githubusercontent.com/u/17075935?v=4)](https://github.com/livissnack "livissnack (12 commits)")

### Embed Badge

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

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

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.2M46](/packages/tencentcloud-tencentcloud-sdk-php)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

252.5k](/packages/eslazarev-wildberries-sdk)[files.com/files-php-sdk

Files.com PHP SDK

2478.1k](/packages/filescom-files-php-sdk)[aimeos/prisma

A powerful PHP package for integrating media related Large Language Models (LLMs) into your applications

1942.4k4](/packages/aimeos-prisma)[volcengine/volcengine-php-sdk

118.7k](/packages/volcengine-volcengine-php-sdk)[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)
