thank-song/weather is a Laravel package for laravel package for openweather api..
It currently has 0 GitHub stars and 4 downloads on Packagist (latest version V1.0.0).
Install it with composer require thank-song/weather.
Discover more Laravel packages by thank-song
or browse all Laravel packages to compare alternatives.
Last updated
这是一个用于获取天气数据的 Laravel 扩展包,支持通过城市名称、经纬度等方式调用 OpenWeather 接口。
composer require thank-song/weather
可选步骤,发布配置文件以便修改 API Key:
php artisan vendor:publish --tag=config
发布后会在 config/openweather.php 中看到配置项。
需要配置 api_key 项。
参见:OpenWeather API
use Weather;
//通过城市名称获取天气数据
$response = Weather::getByCity('Hangzhou');
//通过经纬度获取天气数据
//$response = Weather::getByCoords(30.2711, 120.1555);
//通过城市ID获取天气数据
//$response = Weather::getByCityId(1831806);
//通过邮编获取天气数据
//$response = Weather::getByZip(310000);
// $response 为一个Response对象,可用方法如下:
echo $response->getTemp();
echo $response->getMinTemp();
var_dump($response->getWeather());
var_dump($response->getMain());
//...
$weather = app('weather');
$response = $weather::getByCity('Hangzhou');
$response->getTemp():当前温度$response->getMinTemp():最低温度$response->getMaxTemp():最高温度$response->getWeather()[0]['description']:天气描述