PHP code example of aliliin / weather

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

    

aliliin / weather example snippets


use Aliliin\Weather\Weather;

$key = 'kkkkkkkkkkkkkkkkkkkkkk';

$weather = new Weather($key);

$response = $weather->getLiveWeather('北京');

$response = $weather->getLiveWeather('北京', 'xml');

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

    .
    .
    .
    public function getWeatherInfo(Weather $weather) 
    {
        $response = $weather->getLiveWeather('北京');
    }
    .
    .
    .

    .
    .
    .
    public function getWeatherInfo() 
    {
        $response = app('weather')->getLiveWeather('北京');
    }
    .
    .
    .


$response = $weather->getForecastsWeather('北京');
xml
<response>
    <status>1</status>
    <count>1</count>
    <info>OK</info>
    <infocode>10000</infocode>
    <lives type="list">
        <live>
            <province>北京</province>
            <city>北京市</city>
            <adcode>110000</adcode>
            <weather>晴</weather>
            <temperature>0</temperature>
            <winddirection>南</winddirection>
            <windpower>≤3</windpower>
            <humidity>26</humidity>
            <reporttime>2019-01-10 18:49:58</reporttime>
        </live>
    </lives>
</response>