定制 lepig/weather 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lepig/weather

Composer 安装命令:

composer require lepig/weather

包简介

A weather SDK.

README 文档

README

Build Status

A weather SDK..

Installing

$ composer require lepig/weather -vvv

配置

在使用此组件之前,你需要去高德开放平台注册帐号,并申请应用,获取应用的API Key.

Usage

use Lepig\Weather\Weather;

$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$weather = new Weather($key);

获取实时天气

$weather->getWeather('滁州');

返回结果示例:

{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "lives": [
        {
            "province": "安徽",
            "city": "滁州市",
            "adcode": "341100",
            "weather": "多云",
            "temperature": "2",
            "winddirection": "西北",
            "windpower": "≤3",
            "humidity": "84",
            "reporttime": "2019-02-19 11:17:22"
        }
    ]
}

获取最近几天的天气

$weather->getWeather('滁州', 'all');

返回结果示例:

{
    "status": "1",
    "count": "1",
    "info": "OK",
    "infocode": "10000",
    "forecasts": [
        {
            "city": "滁州市",
            "adcode": "341100",
            "province": "安徽",
            "reporttime": "2019-02-19 11:17:22",
            "casts": [
                {
                    "date": "2019-02-19",
                    "week": "2",
                    "dayweather": "多云",
                    "nightweather": "多云",
                    "daytemp": "5",
                    "nighttemp": "2",
                    "daywind": "西北",
                    "nightwind": "西北",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                },
                {
                    "date": "2019-02-20",
                    "week": "3",
                    "dayweather": "小雨",
                    "nightweather": "",
                    "daytemp": "6",
                    "nighttemp": "3",
                    "daywind": "东北",
                    "nightwind": "东北",
                    "daypower": "4",
                    "nightpower": "4"
                },
                {
                    "date": "2019-02-21",
                    "week": "4",
                    "dayweather": "小雨",
                    "nightweather": "中雨",
                    "daytemp": "10",
                    "nighttemp": "0",
                    "daywind": "东北",
                    "nightwind": "东北",
                    "daypower": "4",
                    "nightpower": "4"
                },
                {
                    "date": "2019-02-22",
                    "week": "5",
                    "dayweather": "多云",
                    "nightweather": "",
                    "daytemp": "4",
                    "nighttemp": "0",
                    "daywind": "",
                    "nightwind": "",
                    "daypower": "≤3",
                    "nightpower": "≤3"
                }
            ]
        }
    ]
}

独立的方法调用

获取实时天气

$weather->getLiveWeather('滁州');

获取未来几天天气预报

$weather->getForecastsWeather('滁州');

参数说明

array | string   getWeather(string $city, string $type = 'base', string $format = 'json')

$city - 城市名称或城市adcode $type - 返回内容类型: base->返回实时天气 all->返回预报天气 $format - 输出的数据格式,默认为json。 可选xml

在Laravel中使用

在Laravel中和之前的安装方式一致。申请的key值需要配置在config/services.php中:

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

然后在.env文件中配置上WEATHER_API_KEY

WEATHER_API_KEY=xxxxxxxxxxxxxxxxxxxxx

说明

实例$weather的获取可以通过参数注入的方式,也可以通过服务名的方式。

通过参数注入

public function show(Weather $weather, $city)
{
    return $weather->getWeather($city);
}

通过服务名方式

public function show($city)
{
    return app('weather')->getWeather($city, 'all', 'xml');
}

TODO

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

License

MIT

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固