softlabnet / weather
天气测试示例
Requires
- php: >=7.1.0
- guzzlehttp/guzzle: ^6.2
- illuminate/support: 5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*
This package is auto-updated.
Last update: 2024-09-19 17:47:55 UTC
README
该包旨在通过第三方资源获取天气数据
安装
Packagist 更新缓慢,我放置了一个连接到链接的组件。需要额外进入 packages 文件夹并从 GitHub 克隆
git clone https://github.com/softlab2/weather.git
使用 Composer
composer require softlabnet/weather
发布配置文件
php artisan vendor:publish --provider="Softlab\Weather\WeatherServiceProvider" --tag="weather"
描述
该包提供网站使用的天气 API。
可以使用多个数据源,通过 .env 文件中的 WEATHER_SOURCE 变量来更改数据源,默认为 yandex。
在应用程序服务提供者中注册数据源
$this->app['weather']->add('yandex', \Softlab\Weather\Sources\YandexSource::class);
数据源类必须扩展基本类 \Softlab\Weather\Source 并实现 \Softlab\Weather\SourceInterface 接口
方法生成对数据源的请求
public function prepareRequest( Point $point ) : WeatherRequest;
方法将数据源响应转换为标准格式 public function prepareResponse( $data ) : WeatherResponse;
数据源配置:url、API 密钥等位于 config/weather.php 文件中
为了不每次都从源请求数据,每个点的数据都保存在缓存中。
目前只从响应中提取温度。