PHP code example of izongchao / gweather
1. Go to this page and download the library: Download izongchao/gweather 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/ */
izongchao / gweather example snippets
use Izongchao\Gweather\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": "340100",
"province": "安徽",
"reporttime": "2019-05-20 09:21:20",
"casts": [
{
"date": "2019-05-20",
"week": "1",
"dayweather": "多云",
"nightweather": "阴",
"daytemp": "25",
"nighttemp": "13",
"daywind": "西北",
"nightwind": "西北",
"daypower": "4",
"nightpower": "4"
},
{
"date": "2019-05-21",
"week": "2",
"dayweather": "多云",
"nightweather": "多云",
"daytemp": "27",
"nighttemp": "15",
"daywind": "西",
"nightwind": "西",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2019-05-22",
"week": "3",
"dayweather": "晴",
"nightweather": "多云",
"daytemp": "32",
"nighttemp": "15",
"daywind": "西南",
"nightwind": "西南",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2019-05-23",
"week": "4",
"dayweather": "多云",
"nightweather": "多云",
"daytemp": "29",
"nighttemp": "18",
"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>340100</adcode>
<weather>多云</weather>
<temperature>23</temperature>
<winddirection>北</winddirection>
<windpower>4</windpower>
<humidity>20</humidity>
<reporttime>2019-05-20 09:21:20</reporttime>
</live>
</lives>
</response>