PHP code example of cherrybeal / weather
1. Go to this page and download the library: Download cherrybeal/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/ */
cherrybeal / weather example snippets
use Cherrybeal\Weather\Weather;
$key = 'xxxxxxxx';
$weather = new Weather($key);
$response = $weather->getLiveWeather('长沙');
$response = $weather->getForecastsWeather('长沙', 'all');
$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('深圳');
}
json
{
"status": "1",
"count": "2",
"info": "OK",
"infocode": "10000",
"lives": [
{
"province": "湖南",
"city": "长沙市",
"adcode": "430100",
"weather": "晴",
"temperature": "7",
"winddirection": "西北",
"windpower": "≤3",
"humidity": "65",
"reporttime": "2019-01-22 21:17:37"
},
{
"province": "湖南",
"city": "长沙县",
"adcode": "430121",
"weather": "晴",
"temperature": "7",
"winddirection": "西北",
"windpower": "≤3",
"humidity": "65",
"reporttime": "2019-01-22 21:17:38"
}
]
}
json
{
"status": "1",
"count": "2",
"info": "OK",
"infocode": "10000",
"forecasts": [
{
"city": "长沙市",
"adcode": "430100",
"province": "湖南",
"reporttime": "2019-01-22 21:17:38",
"casts": [
{
"date": "2019-01-22",
"week": "2",
"dayweather": "晴",
"nightweather": "晴",
"daytemp": "14",
"nighttemp": "3",
"daywind": "东南",
"nightwind": "东南",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2019-01-23",
"week": "3",
"dayweather": "晴",
"nightweather": "晴",
"daytemp": "15",
"nighttemp": "3",
"daywind": "东",
"nightwind": "东",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2019-01-24",
"week": "4",
"dayweather": "多云",
"nightweather": "多云",
"daytemp": "16",
"nighttemp": "4",
"daywind": "北",
"nightwind": "北",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2019-01-25",
"week": "5",
"dayweather": "多云",
"nightweather": "多云",
"daytemp": "12",
"nighttemp": "6",
"daywind": "北",
"nightwind": "北",
"daypower": "≤3",
"nightpower": "≤3"
}
]
},
{
"city": "长沙县",
"adcode": "430121",
"province": "湖南",
"reporttime": "2019-01-22 21:17:38",
"casts": [
{
"date": "2019-01-22",
"week": "2",
"dayweather": "晴",
"nightweather": "晴",
"daytemp": "13",
"nighttemp": "3",
"daywind": "东南",
"nightwind": "东南",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2019-01-23",
"week": "3",
"dayweather": "晴",
"nightweather": "晴",
"daytemp": "15",
"nighttemp": "3",
"daywind": "东",
"nightwind": "东",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2019-01-24",
"week": "4",
"dayweather": "多云",
"nightweather": "多云",
"daytemp": "16",
"nighttemp": "4",
"daywind": "北",
"nightwind": "北",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2019-01-25",
"week": "5",
"dayweather": "多云",
"nightweather": "多云",
"daytemp": "12",
"nighttemp": "6",
"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>27</temperature>
<winddirection>西南</winddirection>
<windpower>5</windpower>
<humidity>94</humidity>
<reporttime>2018-08-21 16:00:00</reporttime>
</live>
</lives>
</response>