wangyw / weather
这是一个测试的天气扩展包
0.0.3
2020-08-30 13:40 UTC
Requires
- php: ^7.0
- guzzlehttp/guzzle: ^6.5
Requires (Dev)
- mockery/mockery: ^1.3
- phpunit/phpunit: ^6.5
This package is auto-updated.
Last update: 2025-06-29 01:42:44 UTC
README
基于高德地图的测试包.
安装
B
$ composer require wangyw/weather -vvv
使用
use Wangyw\Weather\Weather;
$key = '*************';
$url = 'https://restapi.amap.com/v3/weather/weatherInfo';
$weather = new Weather('mock_key', $url);
获取实时天气
$response = $weather->getWeather('深圳', 'base', 'json');
参数说明
getWeather(string $cityName, string $type = 'base', string $format = 'json')
- $cityName -城市名
- $type -返回内容类型 base:实时天气 all:返回预报天气,默认为base
- $format -返回内容格式 默认为json ,可以指定为xml
在laravel中使用
- 在config文件中添加weather.php
return [
'weather' => [
'key' => '********',
'url' => 'https://restapi.amap.com/v3/weather/weatherInfo',
],
];
- 方法参数注入
public function getBaseWeather(Weather $weather) {
$response = $weather->getWeather('上海');
}
- 服务名域名访问
$response = app('weather')->getWeather('上海');
参考
License
MIT