matthewhallcom/pirate-weather-php

海盗天气API的PHP库。

v1.1.0 2023-05-10 15:48 UTC

This package is auto-updated.

Last update: 2024-09-10 18:46:55 UTC


README

PHP库,用于海盗天气API。

这是由 dmitry-ivanov/dark-sky-api 包的分支。

用法

  1. 通过Composer安装包

    composer require matthewhallcom/pirate-weather-php
  2. 使用 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,您必须自己注册服务提供者和别名!

  1. 发布配置

    php artisan vendor:publish --provider="MatthewHallCom\PirateWeather\Adapters\Laravel\PirateWeatherServiceProvider"
  2. .env文件中设置您的密钥

    PIRATE_WEATHER_KEY="Your-Secret-Key"
  3. 使用 PirateWeather 门面

    use PirateWeather;
    
    $forecast = PirateWeather::location(46.482, 30.723)
        ->forecast('daily');
    
    echo $forecast->daily()->summary();

许可协议

Pirate Weather PHP是开源软件,许可协议为MIT许可证