承接 zhoubohan/weather 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

zhoubohan/weather

Composer 安装命令:

composer require zhoubohan/weather

包简介

a weather sdk

README 文档

README

a weather sdk.

Build Status StyleCI build status

安装

$ composer require zhoubohan/weather -vvv

配置

在使用本扩展之前,你需要去和风天气注册账号,然后创建应用,获取应用的 API Key。

使用

use Zhoubohan\Weather\Weather;

$key = 'xxxxxxxxxxxxxxxxxxxxxx';

$c = new Weather($key);

获取实时天气

$res = $c->getLiveWeather('北京');

示例:

{
    "HeWeather6": [
        {
            "basic": {
                "cid": "CN101010100",
                "location": "北京",
                "parent_city": "北京",
                "admin_area": "北京",
                "cnty": "中国",
                "lat": "39.90498734",
                "lon": "116.4052887",
                "tz": "+8.00"
            },
            "update": {
                "loc": "2018-09-29 13:46",
                "utc": "2018-09-29 05:46"
            },
            "status": "ok",
            "now": {
                "cloud": "50",
                "cond_code": "100",
                "cond_txt": "",
                "fl": "60.8",
                "hum": "21",
                "pcpn": "0.0",
                "pres": "1014",
                "tmp": "68.0",
                "vis": "56.3",
                "wind_deg": "297",
                "wind_dir": "西北风",
                "wind_sc": "3",
                "wind_spd": "27.4"
            }
        }
    ]
}

获取天气预报

$res = $c->getForecastWeather('北京');

示例:

{
    "HeWeather6": [
        {
            "basic": {
                "cid": "CN101010100",
                "location": "北京",
                "parent_city": "北京",
                "admin_area": "北京",
                "cnty": "中国",
                "lat": "39.90498734",
                "lon": "116.4052887",
                "tz": "+8.00"
            },
            "update": {
                "loc": "2018-09-29 13:46",
                "utc": "2018-09-29 05:46"
            },
            "status": "ok",
            "daily_forecast": [
                {
                    "cond_code_d": "100",
                    "cond_code_n": "100",
                    "cond_txt_d": "",
                    "cond_txt_n": "",
                    "date": "2018-09-29",
                    "hum": "37",
                    "mr": "20:41",
                    "ms": "10:00",
                    "pcpn": "0.0",
                    "pop": "0",
                    "pres": "1015",
                    "sr": "06:09",
                    "ss": "17:58",
                    "tmp_max": "69.8",
                    "tmp_min": "50.0",
                    "uv_index": "5",
                    "vis": "32.2",
                    "wind_deg": "4",
                    "wind_dir": "北风",
                    "wind_sc": "3-4",
                    "wind_spd": "37.0",
                    "wind_spd_d": "0.0",
                    "wind_spd_n": "0.0"
                },
                {
                    "cond_code_d": "100",
                    "cond_code_n": "100",
                    "cond_txt_d": "",
                    "cond_txt_n": "",
                    "date": "2018-09-30",
                    "hum": "34",
                    "mr": "21:23",
                    "ms": "11:05",
                    "pcpn": "0.0",
                    "pop": "0",
                    "pres": "1014",
                    "sr": "06:10",
                    "ss": "17:56",
                    "tmp_max": "68.0",
                    "tmp_min": "55.4",
                    "uv_index": "5",
                    "vis": "32.2",
                    "wind_deg": "290",
                    "wind_dir": "西北风",
                    "wind_sc": "4-5",
                    "wind_spd": "49.9",
                    "wind_spd_d": "0.0",
                    "wind_spd_n": "0.0"
                },
                {
                    "cond_code_d": "100",
                    "cond_code_n": "100",
                    "cond_txt_d": "",
                    "cond_txt_n": "",
                    "date": "2018-10-01",
                    "hum": "39",
                    "mr": "22:11",
                    "ms": "12:10",
                    "pcpn": "0.0",
                    "pop": "7",
                    "pres": "1018",
                    "sr": "06:11",
                    "ss": "17:55",
                    "tmp_max": "71.6",
                    "tmp_min": "51.8",
                    "uv_index": "6",
                    "vis": "32.2",
                    "wind_deg": "4",
                    "wind_dir": "北风",
                    "wind_sc": "4-5",
                    "wind_spd": "41.8",
                    "wind_spd_d": "0.0",
                    "wind_spd_n": "0.0"
                }
            ]
        }
    ]
}

获取生活指数

$res = $c->getLifestyleWeather('北京');

示例:

{
    "HeWeather6": [
        {
            "basic": {
                "cid": "CN101010100",
                "location": "北京",
                "parent_city": "北京",
                "admin_area": "北京",
                "cnty": "中国",
                "lat": "39.90498734",
                "lon": "116.4052887",
                "tz": "+8.00"
            },
            "update": {
                "loc": "2018-09-29 13:46",
                "utc": "2018-09-29 05:46"
            },
            "status": "ok",
            "lifestyle": [
                {
                    "type": "comf",
                    "brf": "舒适",
                    "txt": "白天不太热也不太冷,风力不大,相信您在这样的天气条件下,应会感到比较清爽和舒适。"
                },
                {
                    "type": "drsg",
                    "brf": "较舒适",
                    "txt": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。"
                },
                {
                    "type": "flu",
                    "brf": "较易发",
                    "txt": "天气较凉,较易发生感冒,请适当增加衣服。体质较弱的朋友尤其应该注意防护。"
                },
                {
                    "type": "sport",
                    "brf": "较适宜",
                    "txt": "天气较好,但因风力稍强,户外可选择对风力要求不高的运动,推荐您进行室内运动。"
                },
                {
                    "type": "trav",
                    "brf": "适宜",
                    "txt": "天气较好,风稍大,但温度适宜,是个好天气哦。适宜旅游,您可以尽情地享受大自然的无限风光。"
                },
                {
                    "type": "uv",
                    "brf": "中等",
                    "txt": "属中等强度紫外线辐射天气,外出时建议涂擦SPF高于15、PA+的防晒护肤品,戴帽子、太阳镜。"
                },
                {
                    "type": "cw",
                    "brf": "较适宜",
                    "txt": "较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。"
                },
                {
                    "type": "air",
                    "brf": "",
                    "txt": "气象条件有利于空气污染物稀释、扩散和清除,可在室外正常活动。"
                }
            ]
        }
    ]
}

在 Laravel 中使用

在 Laravel 中使用也是同样的安装方式,配置写在 config/services.php 中:

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

然后在 .env 中配置 WEATHER_API_KEY

WEATHER_API_KEY=xxxxxxxxxxxxxxxxxxxxx

可以用两种方式来获取 Overtrue\Weather\Weather 实例:

方法参数注入

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

服务名访问

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

参考

License

MIT

zhoubohan/weather 适用场景与选型建议

zhoubohan/weather 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 49 次下载、GitHub Stars 达 7, 最近一次更新时间为 2018 年 09 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 zhoubohan/weather 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 zhoubohan/weather 我们能提供哪些服务?
定制开发 / 二次开发

基于 zhoubohan/weather 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-29