PHP code example of livissnack / weather

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

    

livissnack / weather example snippets


use Livissnack\Weather\Weather;

$ak = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$weather = new Weather($ak);

// 返回数组格式
$response = $weather->getWeather('深圳');

// 批量获取
$response = $weather->getWeather('深圳|北京');

// 返回 XML 格式
$response = $weather->getWeather('深圳', 'xml');

// 按坐标获取
$response = $weather->getWeather('116.30,39.98', 'json');

// 批量坐标获取
$response = $weather->getWeather('116.43,40.75|120.22,43,33', 'json');

// 自定义坐标格式(coord_type)
$response = $weather->getWeather('116.306411,39.981839', 'json', 'bd09ll');

	.
	.
	.
	'weather' => [
            'ak' => env('BAIDU_WEATHER_AK'),
            'sn' => env('BAIDU_WEATHER_SN'), 
        ],

use Livissnack\Weather\Weather;

...

public function edit(Weather $weather) 
{
    $response = $weather->get('深圳');
}

public function edit() 
{
    $response = app('weather')->get('深圳');
}