sssword/weather

0.0.2 2019-01-22 14:22 UTC

This package is auto-updated.

Last update: 2024-09-23 04:39:28 UTC


README

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

Build Status

安装Installing

$ composer require sssword/weather -vvv

配置

在使用本扩展之前,你需要去 高德开放平台 注册账号,然后创建应用,获取应用的 API Key。

使用Usage

use Sssword\Weather\Weather;

$key = '高德开放平台APP Key';

$weather = new Weather($key);

获取实时天气

$response = $weather->getWeather('230100');

示例:

{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "lives": [
        {
            "province": "黑龙江",
            "city": "哈尔滨市",
            "adcode": "230100",
            "weather": "多云",
            "temperature": "-6",
            "winddirection": "西",
            "windpower": "≤3",
            "humidity": "53",
            "reporttime": "2019-01-22 17:12:22"
        }
    ]
}

获取预报天气

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

示例:

{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "forecasts": [
        {
            "city": "哈尔滨市",
            "adcode": "230100",
            "province": "黑龙江",
            "reporttime": "2019-01-22 17:12:22",
            "casts": [
                {
                    "date": "2019-01-22",
                    "week": "2",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "-3",
                    "nighttemp": "-17",
                    "daywind": "西",
                    "nightwind": "西",
                    "daypower": "4",
                    "nightpower": "4"
                },
                {
                    "date": "2019-01-23",
                    "week": "3",
                    "dayweather": "",
                    "nightweather": "",
                    "daytemp": "-8",
                    "nighttemp": "-20",
                    "daywind": "西北",
                    "nightwind": "西北",
                    "daypower": "4",
                    "nightpower": "4"
                },
                {
                    "date": "2019-01-24",
                    "week": "4",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "-7",
                    "nighttemp": "-18",
                    "daywind": "西北",
                    "nightwind": "西北",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-01-25",
                    "week": "5",
                    "dayweather": "阵雪",
                    "nightweather": "多云",
                    "daytemp": "-9",
                    "nighttemp": "-19",
                    "daywind": "西北",
                    "nightwind": "西北",
                    "daypower": "4",
                    "nightpower": "4"
                }
            ]
        }
    ]
}

参数说明

array | string  getWeather(string $city, string $type = 'base', string $format = 'json')
  • $city - 城市,例如 "哈尔滨";
  • $type - 返回内容类型,base: 返回实况天气,all: 返回预报天气;
  • $format - 输出数据格式,json: JSON格式,xml: XML格式;

参考

贡献Contributing

你可以通过以下三种方式之一进行贡献

  1. 使用 问题跟踪器 提交错误报告。
  2. 问题跟踪器 上回答问题或修复错误。
  3. 贡献新功能或更新 wiki。

代码贡献过程并不正式。你只需确保遵循 PSR-0、PSR-1 和 PSR-2 编码规范。任何新的代码贡献都必须附有适用的单元测试。

许可证

MIT