PHP code example of nick233333 / weather

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

    

nick233333 / weather example snippets


use Nick233333\Weather\Weather;

$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$weather = new Weather($key);

$response = $weather->getLiveWeather('深圳');

$response = $weather->getLiveWeather('深圳', 'xml');

    .
    .
    .
     'weather' => [
        'key' => env('WEATHER_API_KEY'),
    ],

    .
    .
    .
    public function edit(Weather $weather) 
    {
        $response = $weather->getLiveWeather('深圳');
    }
    .
    .
    .

    .
    .
    .
    public function edit() 
    {
        $response = app('weather')->getLiveWeather('深圳');
    }
    .
    .
    .


$response = $weather->getForecastsWeather('深圳');
json

{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "forecasts": [
        {
            "city": "深圳市",
            "adcode": "440300",
            "province": "广东",
            "reporttime": "2019-05-01 09:44:31",
            "casts": [
                {
                    "date": "2019-05-01",
                    "week": "3",
                    "dayweather": "阴",
                    "nightweather": "阴",
                    "daytemp": "28",
                    "nighttemp": "22",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-05-02",
                    "week": "4",
                    "dayweather": "阴",
                    "nightweather": "多云",
                    "daytemp": "27",
                    "nighttemp": "22",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-05-03",
                    "week": "5",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "28",
                    "nighttemp": "21",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-05-04",
                    "week": "6",
                    "dayweather": "多云",
                    "nightweather": "阵雨",
                    "daytemp": "28",
                    "nighttemp": "24",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                }
            ]
        }
    ]
}