天气预报

最后更新于:2022-04-02 08:23:54

## 天气预报 >[danger]### 免费接口,每日100次免费调用,会员可不限次数调用,购买[API会员](https://market.topthink.com/product/210) ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/39/ad/39adaf227b128836bf06dfc400e855b7_236x239.png =x120) > 查询天气情况:温度、湿度、AQI、天气、风向、生活指数等 ## 接口调用([调用须知](https://docs.topthink.com/think-api/1835086)) ## 接口1:根据城市查询天气 ### 请求地址 ``` GET https://api.topthink.com/weather/query ``` ### 请求参数 | 名称 | 必填 | 类型 | 说明 | | --- | --- | --- | --- | | appCode| 是| string|用户授权码,参考[API调用](https://docs.topthink.com/think-api/1835086) | | city | 是 | string | 要查询的城市名称/id,城市名称如:温州、上海、北京| ### 返回参数 | 名称 | 类型 | 说明 | | --- | --- | --- | | city | string| 城市名 | | realtime | \- | 当前天气详情情况 | | info | string | 天气情况,如:晴、多云 | | wid | string | 天气标识id,可参考小接口2 | | temperature | string | 温度,可能为空 | | humidity | string | 湿度,可能为空 | | direct | string | 风向,可能为空 | | power | string | 风力,可能为空 | | aqi | string | 空气质量指数,可能为空 | | future | \- | 近5天天气情况 | | date | string | 日期 | | temperature | string | 温度,最低温/最高温 | | weather | string | 天气情况 | | direct | string | 风向 | ## SDK调用 ``` $client = new Client("YourAppCode"); $result = $client->weatherQuery() ->withCity('上海') ->request(); dump($result); ``` 返回数据示例: ~~~ { "message": "查询成功", "data": { "city": "上海", "realtime": { "temperature": "4", "humidity": "82", "info": "阴", "wid": "02", "direct": "西北风", "power": "3级", "aqi": "80" }, "future": [ { "date": "2019-02-22", "temperature": "1/7℃", "weather": "小雨转多云", "wid": { "day": "07", "night": "01" }, "direct": "北风转西北风" }, { "date": "2019-02-23", "temperature": "2/11℃", "weather": "多云转阴", "wid": { "day": "01", "night": "02" }, "direct": "北风转东北风" }, { "date": "2019-02-24", "temperature": "6/12℃", "weather": "多云", "wid": { "day": "01", "night": "01" }, "direct": "东北风转北风" }, { "date": "2019-02-25", "temperature": "5/12℃", "weather": "小雨转多云", "wid": { "day": "07", "night": "01" }, "direct": "东北风" }, { "date": "2019-02-26", "temperature": "5/11℃", "weather": "多云转小雨", "wid": { "day": "01", "night": "07" }, "direct": "东北风" } ] }, "code": 0 } ~~~ ## 接口2:根据城市查询生活指数 ### 请求地址 ``` GET https://api.topthink.com/weather/life ``` ### 请求参数 | 名称 | 必填 | 类型 | 说明 | | --- | --- | --- | --- | | appCode| 是| string|用户授权码,参考[API调用](https://docs.topthink.com/think-api/1835086) | | city | 是 | string | 要查询的城市名称/id,城市名称如:温州、上海、北京| ### 返回参数 | 名称 | 类型 | 说明 | | --- | --- | --- | | city | string| 城市名 | | life | \- | 生活指数 | | kongtiao | array | 空调指数 | | guomin| array | 过敏指数 | | shushidu | array | 舒适度 | | chuanyi| array | 穿衣指数 | | diaoyu| array| 钓鱼指数 | | ganmao | array| 感冒指数 | | ziwaixian| array | 紫外线指数 | | xiche| array| 洗车指数 | | yundong | array| 运动指数 | | daisan| array | 带伞指数 | ## SDK调用 ``` $client = new Client("YourAppCode"); $result = $client->weatherLife() ->withCity('北京') ->request(); dump($result); ``` 返回数据示例: ~~~ { "message": "查询成功", "data": { "city": "北京", "life": { "kongtiao": {/*空调开启*/ "v": "开启制暖空调",/*指数*/ "des": "您将感到有些冷,可以适当开启制暖空调调节室内温度,以免着凉感冒。"/*指数详情*/ }, "guomin": {/*过敏*/ "v": "极不易发", "des": "天气条件极不易诱发过敏,可放心外出,享受生活。" }, "shushidu": {/*舒适度*/ "v": "较不舒适", "des": "白天天气晴好,但仍会使您感觉偏冷,不很舒适,请注意适时添加衣物,以防感冒。" }, "chuanyi": {/*穿衣*/ "v": "冷", "des": "天气冷,建议着棉服、羽绒服、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣、冬大衣或厚羽绒服。" }, "diaoyu": {/*钓鱼*/ "v": "不宜", "des": "天气冷,不适合垂钓。" }, "ganmao": {/*感冒*/ "v": "较易发", "des": "昼夜温差较大,较易发生感冒,请适当增减衣服。体质较弱的朋友请注意防护。" }, "ziwaixian": {/*紫外线*/ "v": "弱", "des": "紫外线强度较弱,建议出门前涂擦SPF在12-15之间、PA+的防晒护肤品。" }, "xiche": {/*洗车*/ "v": "较适宜", "des": "较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。" }, "yundong": {/*运动*/ "v": "较不宜", "des": "天气较好,但考虑天气寒冷,推荐您进行室内运动,户外运动时请注意保暖并做好准备活动。" }, "daisan": {/*带伞*/ "v": "不带伞", "des": "天气较好,您在出门的时候无须带雨伞。" } } }, "code": 0 } ~~~ ## 接口3:天气种类列表(可内置 无需每次读取) ### 请求地址 ``` GET https://api.topthink.com/weather/wids ``` ### 请求参数 无 ### 返回参数 参考返回示例 ## SDK调用 ``` $client = new Client("YourAppCode"); $result = $client->weatherWids() ->request(); dump($result); ``` 返回数据示例: ~~~ { "message": "查询成功", "data": [ { "wid": "00", "weather": "晴" }, { "wid": "01", "weather": "多云" }, { "wid": "02", "weather": "阴" }, { "wid": "03", "weather": "阵雨" }, { "wid": "04", "weather": "雷阵雨" }, { "wid": "05", "weather": "雷阵雨伴有冰雹" }, { "wid": "06", "weather": "雨夹雪" }, { "wid": "07", "weather": "小雨" }, { "wid": "08", "weather": "中雨" }, { "wid": "09", "weather": "大雨" }, { "wid": "10", "weather": "暴雨" }, { "wid": "11", "weather": "大暴雨" }, { "wid": "12", "weather": "特大暴雨" }, { "wid": "13", "weather": "阵雪" }, { "wid": "14", "weather": "小雪" }, { "wid": "15", "weather": "中雪" }, { "wid": "16", "weather": "大雪" }, { "wid": "17", "weather": "暴雪" }, { "wid": "18", "weather": "雾" }, { "wid": "19", "weather": "冻雨" }, { "wid": "20", "weather": "沙尘暴" }, { "wid": "21", "weather": "小到中雨" }, { "wid": "22", "weather": "中到大雨" }, { "wid": "23", "weather": "大到暴雨" }, { "wid": "24", "weather": "暴雨到大暴雨" }, { "wid": "25", "weather": "大暴雨到特大暴雨" }, { "wid": "26", "weather": "小到中雪" }, { "wid": "27", "weather": "中到大雪" }, { "wid": "28", "weather": "大到暴雪" }, { "wid": "29", "weather": "浮尘" }, { "wid": "30", "weather": "扬沙" }, { "wid": "31", "weather": "强沙尘暴" }, { "wid": "53", "weather": "霾" } ], "code": 0 } ~~~
';