matthewhallcom / pirate-weather-php
海盗天气API的PHP库。
v1.1.0
2023-05-10 15:48 UTC
Requires
- php: >=5.6
- ext-json: *
- guzzlehttp/guzzle: ^6.3|^7.0
- psr/http-message: ^1.0
Requires (Dev)
- illuminate/contracts: ^5.1|^6.0|^7.0|^8.0|^9.0|^10.0
- illuminate/support: ^5.1|^6.0|^7.0|^8.0|^9.0|^10.0
README
PHP库,用于海盗天气API。
这是由 dmitry-ivanov/dark-sky-api 包的分支。
用法
-
通过Composer安装包
composer require matthewhallcom/pirate-weather-php
-
使用
MatthewHallCom\PirateWeather\PirateWeather类use MatthewHallCom\PirateWeather\PirateWeather; $forecast = (new PirateWeather('secret-key')) ->location(46.482, 30.723) ->forecast('daily'); echo $forecast->daily()->summary();
时间机器请求
有时可能需要获取指定日期的天气
$timeMachine = (new PirateWeather('secret-key')) ->location(46.482, 30.723) ->timeMachine('2020-01-01', 'daily'); echo $timeMachine->daily()->summary();
您也可以获取多个日期的天气
$timeMachine = (new PirateWeather('secret-key')) ->location(46.482, 30.723) ->timeMachine(['2020-01-01', '2020-01-02', '2020-01-03'], 'daily'); echo $timeMachine['2020-01-02']->daily()->summary();
Laravel中的用法
如果您使用的是Laravel <5.5,您必须自己注册服务提供者和别名!
-
发布配置
php artisan vendor:publish --provider="MatthewHallCom\PirateWeather\Adapters\Laravel\PirateWeatherServiceProvider" -
在
.env文件中设置您的密钥PIRATE_WEATHER_KEY="Your-Secret-Key"
-
使用
PirateWeather门面use PirateWeather; $forecast = PirateWeather::location(46.482, 30.723) ->forecast('daily'); echo $forecast->daily()->summary();
许可协议
Pirate Weather PHP是开源软件,许可协议为MIT许可证。