PHP code example of cannonsir / weather

1. Go to this page and download the library: Download cannonsir/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/ */

    

cannonsir / weather example snippets


use CannonSir\Weather\Weather;

$weather = new Weather('your api key');

$weather->getWeather('成都')
$weather->getLiveWeather('成都', 'json')

$weather->getWeather('成都', 'forecasts');

array|string getWeather(string $city, string $type = 'live', string $format = 'json')

'weather' => [
    'key' => env('AMAP_API_KEY')
]
json
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "forecasts": [
        {
            "city": "成都市",
            "adcode": "510100",
            "province": "四川",
            "reporttime": "2019-07-17 23:52:01",
            "casts": [
                {
                    "date": "2019-07-17",
                    "week": "3",
                    "dayweather": "多云",
                    "nightweather": "晴",
                    "daytemp": "29",
                    "nighttemp": "23",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-07-18",
                    "week": "4",
                    "dayweather": "阵雨",
                    "nightweather": "阵雨",
                    "daytemp": "31",
                    "nighttemp": "23",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-07-19",
                    "week": "5",
                    "dayweather": "阵雨",
                    "nightweather": "阵雨",
                    "daytemp": "31",
                    "nighttemp": "24",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-07-20",
                    "week": "6",
                    "dayweather": "阵雨",
                    "nightweather": "小雨",
                    "daytemp": "33",
                    "nighttemp": "23",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                }
            ]
        }
    ]
}