goletter/hyperf-weather

QWeather client for Hyperf

Maintainers

Package info

github.com/goletter/hyperf-weather

pkg:composer/goletter/hyperf-weather

Transparency log

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-08-13 16:06 UTC

This package is auto-updated.

Last update: 2026-08-13 16:09:20 UTC


README

Hyperf 协程友好的和风天气(QWeather)扩展包,支持城市查询、实时天气、天气预报、逐小时天气、天气预警、空气质量和生活指数。

安装

composer require goletter/hyperf-weather
php bin/hyperf.php vendor:publish goletter/hyperf-weather

配置文件发布到 config/autoload/weather.php

配置

QWEATHER_API_KEY=your-key
QWEATHER_LANG=zh
QWEATHER_UNIT=m

weather.php

return [
    'default' => env('WEATHER_SERVICE', 'qweather'),
    'services' => [
        'qweather' => [
            'key' => env('QWEATHER_API_KEY', ''),
        ],
    ],
];

使用

use Goletter\Weather\Factory\WeatherFactory;

$client = $this->weather->get();

// 城市查询,返回 location id,可用于后续天气接口
$cities = $client->lookupCity('上海');

// 实时天气
$now = $client->now('101020100');

// 3 / 7 / 10 / 15 / 30 天天气预报
$forecast = $client->forecast('101020100', 3);

// 24 / 72 / 168 小时逐小时天气
$hourly = $client->hourly('101020100', 24);

// 天气预警
$warning = $client->warning('101020100');

// 空气质量
$air = $client->airNow('101020100');

// 生活指数,type=0 表示全部类型;days 支持 1 / 3
$indices = $client->indices('101020100', 0, 1);

// 穿衣指数,等同于 indices($location, 3, $days)
$dressing = $client->dressing('101020100');

// 穿搭推荐:组合实时天气 + 穿衣指数,返回 recommendation 文案
$outfit = $client->outfit('101020100');

动态 Key

$client = $this->weather->key($tenant->qweather_key, (string) $tenant->id);

$now = $client->now('101020100');

通用调用

$result = $client->call('/v7/weather/now', [
    'location' => '101020100',
]);

所有方法都会自动附加 keylangunit 参数。