PHP code example of lazyuu / hweather

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

    

lazyuu / hweather example snippets


// 用户名和秘钥通过登录“和风天气”官网获取
$weather = new \Liron\Heweather\Weather(
    'xxxx', // 用户名
    'xxx', // 秘钥
    false // 是否为付费用户, 默认为false
);


/**
 * 请求示例
 */
// 获取3-10天天气预报 (传参时候可以省去 username、t、sign、key 字段,请求时会自动补全)
$res = $weather->forecast([
    'location' => 'auto_ip',
]);


print_r($res); // api response


php artisan vendor:publish --provider=Liron\Heweather\ServiceProvider


/**
 * 和风天气配置
 */
return [
    // 是否为付费用户
    'paying'    => env('HEWEATHER_PAYING', false),
    // 用户名
    'username'  => env('HEWEATHER_USERNAME', ''),
    // 秘钥
    'key'       => env('HEWEATHER_KEY', ''),
];

// 可直接使用 Weather facade类
$res = \Weather::forecast([
    'location' => 'auto_ip'
])