项目作者: liron-li

项目描述 :
和风天气sdk
高级语言: PHP
项目地址: git://github.com/liron-li/heweather.git
创建时间: 2018-05-24T12:22:18Z
项目社区:https://github.com/liron-li/heweather

开源协议:

下载


liron-li/heweather

和风天气sdk 官方api文档:https://www.heweather.com/documents/api/s6

安装

  1. composer require liron-li/heweather

使用

  1. // 用户名和秘钥通过登录“和风天气”官网获取
  2. $weather = new \Liron\Heweather\Weather(
  3. 'xxxx', // 用户名
  4. 'xxx', // 秘钥
  5. false // 是否为付费用户, 默认为false
  6. );
  7. /**
  8. * 请求示例
  9. */
  10. // 获取3-10天天气预报 (传参时候可以省去 username、t、sign、key 字段,请求时会自动补全)
  11. $res = $weather->forecast([
  12. 'location' => 'auto_ip',
  13. ]);
  14. print_r($res); // api response

在Laravel中使用

1.安装

  1. composer require liron-li/heweather

4.注册服务提供者

注意: laravel5.5及以上版本可以跳过此步骤

编辑config/app.php

  1. // 在 providers 数组中加入
  2. 'providers' => [
  3. // ...
  4. Liron\Heweather\ServiceProvider::class
  5. // ...
  6. ]
  7. // 在 aliases 数组中加入
  8. 'aliases' => [
  9. // ...
  10. 'Weather' => Liron\Heweather\Facade::class
  11. // ...
  12. ]

2.发布配置文件

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

3.修改config/weather.php配置

  1. <?php
  2. /**
  3. * 和风天气配置
  4. */
  5. return [
  6. // 是否为付费用户
  7. 'paying' => env('HEWEATHER_PAYING', false),
  8. // 用户名
  9. 'username' => env('HEWEATHER_USERNAME', ''),
  10. // 秘钥
  11. 'key' => env('HEWEATHER_KEY', ''),
  12. ];

使用示例

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

API列表

  • Weather
    • forecast (3-10天天气预报)
    • now (实况天气)
    • hourly (逐小时预报)
    • lifestyle (生活指数)
    • weather (常规天气数据集合)
    • gridMinute (分钟级降雨(邻近预报))
    • gridNow (格点实况天气)
    • gridForecast (格点7天预报)
    • gridHourly (格点逐小时预报)
    • alarm (分钟级降雨(邻近预报))
    • alarmAll (天气灾害预警集合)
    • scenic (景点天气预报)
    • airNow (空气质量实况)
    • airForecast (空气质量7天预报)
    • airHourly (空气质量逐小时预报)
    • air (空气质量数据集合)
    • historical (历史天气)
    • solarSunriseSunset (日出日落)
    • mapCloudmap (卫星云图)
    • solarSolarElevationAngle (太阳高度)
    • find (城市搜索)
    • top (热门城市列表)