sejurplacut/openweather

Openweather API 集成

dev-master 2015-02-08 09:24 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:36:25 UTC


README

为 Laravel 框架提供的 Openweather API 集成。使用多个参数获取当前天气或每日预报。

安装

使用 composer

"require": {
    "sejurplacut/openweather": "dev-master"
}

设置

  1. 将以下内容添加到您的 config/app.php 文件中的服务提供者数组

     'Sejurplacut\Openweather\Provider\OpenweatherServiceProvider'
    
  2. 将以下内容添加到您的 config/app.php 文件中的别名数组

     'OpenWeather' => 'Sejurplacut\OpenWeather\Facades\Openweather'
    
  3. 发布配置文件

    php artisan config:publish sejurplacut/openweather

注意:请谨慎更改端点选项。

使用方法

获取每日预报。

$data = Openweather::getInstance()->getDailyForecast(array(
    'cityName'     => 'Paris',
    'latitude'     => '',
    'longitude'    => '',
    'days'         => ''
    'units'        => 'metric',
    'languageCode' => 'en',
));

获取当前天气状况。

$data = Openweather::getInstance()->getCurrentWeather(array(
    'cityName' => 'Paris',
    'latitude' => '',
    'longitude' => '',
    'radius' => '',
    'units' => 'metric',
    'languageCode' => 'en',
));