一、获取AK
官网地址:https://api.map.baidu.com/lbsapi/cloud/index.htm
点击地图API产品,选择web服务API
该套API免费对外开放,使用前请先申请密钥(key)
点击创建应用
提交后会生成AK,
二、天气查询
进入webApi服务
注意:根据经纬度查询天气是高级权限,需要付费。
使用postman调用接口:https://api.map.baidu.com/weather/v1/?district_id=420100&data_type=all&ak=你的AK
返回结果如下所示:
{ "status": 0, "result": { "location": { "country": "中国", "province": "湖北省", "city": "武汉市", "name": "武汉", "id": "420100" }, "now": { "text": "晴", "temp": 19, "feels_like": 18, "rh": 27, "wind_class": "3级", "wind_dir": "西南风", "uptime": "20230313144500" }, "forecasts": [{ "text_day": "晴", "text_night": "晴", "high": 20, "low": 2, "wc_day": "<3级", "wd_day": "静风", "wc_night": "<3级", "wd_night": "静风", "date": "2023-03-13", "week": "星期一" }, { "text_day": "多云", "text_night": "多云", "high": 25, "low": 9, "wc_day": "3~4级", "wd_day": "南风", "wc_night": "<3级", "wd_night": "静风", "date": "2023-03-14", "week": "星期二" }, { "text_day": "多云", "text_night": "阴", "high": 24, "low": 11, "wc_day": "3~4级", "wd_day": "东北风", "wc_night": "3~4级", "wd_night": "东北风", "date": "2023-03-15", "week": "星期三" }, { "text_day": "小雨", "text_night": "中雨", "high": 21, "low": 8, "wc_day": "<3级", "wd_day": "静风", "wc_night": "<3级", "wd_night": "静风", "date": "2023-03-16", "week": "星期四" }, { "text_day": "小雨", "text_night": "阴", "high": 10, "low": 7, "wc_day": "3~4级", "wd_day": "北风", "wc_night": "<3级", "wd_night": "静风", "date": "2023-03-17", "week": "星期五" }] }, "message": "success" }
标签:baidu,web,text,AK,API,day,百度 From: https://www.cnblogs.com/zwh0910/p/17211445.html