PHP code example of lanxr / weather
1. Go to this page and download the library: Download lanxr/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/ */
lanxr / weather example snippets
use Lanxr\Weather\Weather;
$key = 'xxxxxxxxxxxxxxxxxxxxxx';
$weather = new Weather($key);
$response = $weather->getLiveWeather('贵阳');
$response = $weather->getForecastsWeather('贵阳');
$response = $weather->getLiveWeather('贵阳', 'xml');
.
.
.
'weather' => [
'key' => env('WEATHER_API_KEY'),
],
.
.
.
public function show(Weather $weather)
{
$response = $weather->getLiveWeather('贵阳');
}
.
.
.
.
.
.
public function show()
{
$response = app('weather')->getLiveWeather('贵阳');
}
.
.
.
json
{
"status": "1",
"count": "1",
"info": "OK",
"infocode": "10000",
"forecasts": [
{
"city": "贵阳市",
"adcode": "520100",
"province": "贵州",
"reporttime": "2020-09-02 21:53:26",
"casts": [
{
"date": "2020-09-02",
"week": "3",
"dayweather": "多云",
"nightweather": "多云",
"daytemp": "31",
"nighttemp": "20",
"daywind": "东北",
"nightwind": "东北",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2020-09-03",
"week": "4",
"dayweather": "中雨",
"nightweather": "阵雨",
"daytemp": "29",
"nighttemp": "20",
"daywind": "东",
"nightwind": "东",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2020-09-04",
"week": "5",
"dayweather": "多云",
"nightweather": "阵雨",
"daytemp": "29",
"nighttemp": "21",
"daywind": "南",
"nightwind": "南",
"daypower": "≤3",
"nightpower": "≤3"
},
{
"date": "2020-09-05",
"week": "6",
"dayweather": "阵雨",
"nightweather": "阵雨",
"daytemp": "27",
"nighttemp": "20",
"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>520100</adcode>
<weather>多云</weather>
<temperature>23</temperature>
<winddirection>北</winddirection>
<windpower>≤3</windpower>
<humidity>78</humidity>
<reporttime>2020-09-02 21:53:26</reporttime>
</live>
</lives>
</response>