PHP code example of everan / weather

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

    

everan / weather example snippets


use Everan\Weather\Weather;

$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$weather = new Weather($key);

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

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

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

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

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


{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "lives": [
        {
            "province": "广东",
            "city": "深圳市",
            "adcode": "440300",
            "weather": "阴",
            "temperature": "20",
            "winddirection": "东",
            "windpower": "6",
            "humidity": "82",
            "reporttime": "2018-11-03 12:00:00"
        }
    ]
}

$response = $weather->getForecastsWeather('深圳');
json
{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "forecasts": [
        {
            "city": "深圳市",
            "adcode": "440300",
            "province": "广东",
            "reporttime": "2018-11-03 11:00:00",
            "casts": [
                {
                    "date": "2018-11-03",
                    "week": "6",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "24",
                    "nighttemp": "19",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2018-11-04",
                    "week": "7",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "26",
                    "nighttemp": "22",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2018-11-05",
                    "week": "1",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "27",
                    "nighttemp": "23",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2018-11-06",
                    "week": "2",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "26",
                    "nighttemp": "21",
                    "daywind": "无风向",
                    "nightwind": "无风向",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                }
            ]
        }
    ]
}
xml
<response>
    <status>1</status>
    <count>1</count>
    <info>OK</info>
    <infocode>10000</infocode>
    <lives type="list">
        <live>
            <province>广东</province>
            <city>深圳市</city>
            <adcode>440300</adcode>
            <weather>阴</weather>
            <temperature>20</temperature>
            <winddirection>东</winddirection>
            <windpower>6</windpower>
            <humidity>82</humidity>
            <reporttime>2018-11-03 12:00:00</reporttime>
        </live>
    </lives>
</response>