itan/weather

a weather SDK

dev-master 2019-09-25 11:15 UTC

This package is auto-updated.

Last update: 2024-04-25 21:38:38 UTC


README

##简介

基于 高德开放平台 的 PHP 天气信息组件。

安装

$ composer require itan/weather:dev-master

使用

use Itan\Weather\Weather;

$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$weather = new Weather($key);

####获取实时天气

$response = $weather->getWeather('杭州');

####示例

{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "lives": [
        {
            "province": "广东",
            "city": "深圳市",
            "adcode": "440300",
            "weather": "中雨",
            "temperature": "27",
            "winddirection": "西南",
            "windpower": "5",
            "humidity": "94",
            "reporttime": "2018-08-21 16:00:00"
        }
    ]
}

####获取近期天气预报

$response = $weather->getWeather('杭州', 'all');

####获取 XML 格式返回值 第三个参数为返回值类型,可选 json 与 xml,默认 json:

$response = $weather->getWeather('杭州', 'all', 'xml');

参考

高德开放平台天气接口

License

MIT