PHP code example of wenslim / weather

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

    

wenslim / weather example snippets


$response = $weather->getLiveWeather('上海');

{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "forecasts": [
    {
        "city": "上海市",
        "adcode": "310000",
        "province": "上海",
        "reporttime": "2019-06-08 10:49:45",
        "casts": [
        {
            "date": "2019-06-08",
            "week": "6",
            "dayweather": "多云",
            "nightweather": "多云",
            "daytemp": "29",
            "nighttemp": "21",
            "daywind": "东南",
            "nightwind": "东南",
            "daypower": "≤3",
            "nightpower": "≤3"
        },
        {
            "date": "2019-06-09",
            "week": "7",
            "dayweather": "多云",
            "nightweather": "多云",
            "daytemp": "30",
            "nighttemp": "22",
            "daywind": "东南",
            "nightwind": "东南",
            "daypower": "≤3",
            "nightpower": "≤3"
        },
        {
            "date": "2019-06-10",
            "week": "1",
            "dayweather": "小雨",
            "nightweather": "多云",
            "daytemp": "30",
            "nighttemp": "21",
            "daywind": "东北",
            "nightwind": "东北",
            "daypower": "4",
            "nightpower": "4"
        },
        {
            "date": "2019-06-11",
            "week": "2",
            "dayweather": "多云",
            "nightweather": "多云",
            "daytemp": "29",
            "nighttemp": "21",
            "daywind": "东",
            "nightwind": "东",
            "daypower": "4",
            "nightpower": "4"
        }]
    }]
}

<response>
    <status>1</status>
    <count>1</count>
    <info>OK</info>
    <infocode>10000</infocode>
    <lives type="list">
        <live>
            <province>上海</province>
            <city>上海市</city>
            <adcode>310000</adcode>
            <weather>晴</weather>
            <temperature>26</temperature>
            <winddirection>西北</winddirection>
            <windpower>≤3</windpower>
            <humidity>69</humidity>
            <reporttime>2019-06-09 11:18:31
            </reporttime>
        </live>
    </lives>
</response>

use Wenslim\Weather\Weather;

public function show(Weather $weather)
{
    $response = $weather->getLiveWeather('上海');
}

public function show(Weather $weather)
{
    $response = app('weather')->getLiveWeather('上海');
}