PHP code example of pudongping / weather

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

    

pudongping / weather example snippets


use Pudongping\Weather\Weather;

$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$weather = new Weather($key);

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

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



return [
    'key' => env('WEATHER_API_KEY'),
];



public function showWeather(Weather $weather) 
{
    $response = $weather->getLiveWeather('上海');
    
    // 或者直接使用城市的 adcode 传参
    // $response = $weather->getLiveWeather('310000');

}



public function showWeather()
{
    $response = app('weather')->getLiveWeather('上海');
    
    // 或者直接使用城市的 adcode 传参
    // $response = app('weather')->getLiveWeather('310000');
    
}


$response = $weather->getForecastsWeather('上海');
sh
php artisan vendor:publish --provider="Pudongping\Weather\ServiceProvider"