PHP code example of sssword / weather

1. Go to this page and download the library: Download sssword/weather library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sssword / weather example snippets


use Sssword\Weather\Weather;

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

$weather = new Weather($key);

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

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

array | string  getWeather(string $city, string $type = 'base', string $format = 'json')
json
{
    "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"
                }
            ]
        }
    ]
}