phantom / weather

一个简单的开放天气API客户端

安装: 57

依赖者: 0

建议者: 0

安全: 0

类型:

0.0.3 2015-11-17 12:53 UTC

This package is auto-updated.

Last update: 2024-08-28 08:32:17 UTC


README

此扩展允许从某些天气提供商获取天气信息

当前实现

  • Open Weather

安装

您可以通过以下方式安装此组件

1- 更新Composer后发布配置:php artisan config:publish phantom/weather

2- 您必须在 http://openweathermap.org/api 上创建一个账户。然后,将app_id放入配置文件 /packages/phantom/weather/open-weather.php

3- 将此服务提供者添加到您的 /Config/app.php 的 providers 数组中 'Phantom\Weather\WeatherServiceProvider',

用法

创建对象

    $weather = \App::make('open-weather');

通过城市名称获取

	$weather->getCurrentByCityName('Lisbon', 'PT');
	$weather->getDailyByCityName($city_name, $county_code,$days_count);
	$weather->getHourlyByCityName($city_name, $county_code,$hours_count));

通过城市ID获取

    $weather->getCurrentById($id);
    $weather->getDailyById($id,$days_count);
    $weather->getHourlyById($id,$hours_count));

通过城市坐标获取

    $weather->getCurrentByCoordinates($lat, $lon);
    $weather->getDailyByCoordinates($lat, $lon,$days_count);
    $weather->getHourlyByCoordinates($lat, $lon,$hours_count));

通过城市邮编获取

    $weather->getCurrentByZipCode($zip_code, $country_code);

如果发生错误,函数将抛出错误,您可以使用try catch捕获它,并对其进行处理。