微信公眾號接入百度天氣API介面
阿新 • • 發佈:2020-12-09
技術標籤:微信公眾號開發javapythonphpjsonhttp
介面功能介紹
基礎服務
http://api.map.baidu.com/weather/v1/?district_id=222405&data_type=all&ak=你的ak //GET請求
高階許可權(國內經緯度天氣查詢)
http://api.map.baidu.com/weather/v1/?location=116.40387,39.91489&data_type=all&ak=你的ak //GET請求
注意:經緯度天氣查詢是付費服務,僅限高階許可權使用者使用,您可以聯絡我們開通15天試用並瞭解更多資訊。
key:http://lbs.baidu.com/index.php?title=webapi/weather
引數名 | 資料型別 | 是否必傳 | 預設值 | 描述資訊 |
---|---|---|---|---|
district_id | string | 否 | 無 | 區縣的行政區劃編碼,和location二選一 |
location | double | 否 | 無 | 經緯度,經度在前緯度在後,逗號分隔。支援型別:bd09mc/bd09ll/wgs84/gcj02。開通高階許可權後才能使用 |
ak | string | 是 | 無 | 開發者金鑰,可在API控制檯申請獲得 |
data_type | string | 是 | 無 | 請求資料型別。資料型別有:now/fc/index/alert/fc_hour/all,控制返回內容 |
output | string | 否 | json | 返回格式,目前支援json/xml |
coordtype | string | 否 | bd09ll | 支援型別:wgs84/bd09ll/bd09mc/gcj02 |
注意:如果district_id和location同時傳,預設以district_id為準;下列返回結果引數中,欄位型別為高階欄位的,僅在開通高階許可權之後才會展示,否則不展示。
返回結果引數
天氣現象、風力、風向、生活指數、預警事件取值可在資源下載中檢視。
引數名 | 引數型別 | 描述資訊 | 返回條件 | 異常值 | 欄位型別 |
---|---|---|---|---|---|
address | Object | 地理位置資訊 | - | - | 基礎欄位 |
country | String | 國家名稱 | 始終返回 | - | 基礎欄位 |
province | String | 省份名稱 | 始終返回 | - | 基礎欄位 |
city | String | 城市名稱 | 始終返回 | - | 基礎欄位 |
name | String | 區縣名稱 | 始終返回 | - | 基礎欄位 |
id | String | 區縣id | 始終返回 | - | 基礎欄位 |
now | Object | 實況資料 | - | - | 基礎欄位 |
temp | Int | 溫度(℃) | 始終返回 | 999999 | 基礎欄位 |
feels_like | Int | 體感溫度(℃) | data_type=now/all | 999999 | 基礎欄位 |
rh | Int | 相對溼度(%) | data_type=now/all | 999999 | 基礎欄位 |
wind_class | String | 風力等級 | data_type=now/all | “暫無” | 基礎欄位 |
wind_dir | String | 風向描述 | data_type=now/all | “暫無” | 基礎欄位 |
text | String | 天氣現象 | data_type=now/all | “暫無” | 基礎欄位 |
uptime | String | 資料更新時間,北京時間 | data_type=now/all | - | 基礎欄位 |
forecasts | ObjectArray | 預報資料 | - | - | 基礎欄位 |
date | String | 日期,北京時區 | data_type=fc/all | - | 基礎欄位 |
week | String | 星期,北京時區 | data_type=fc/all | - | 基礎欄位 |
high | Int | 最高溫度(℃) | data_type=fc/all | 999999 | 基礎欄位 |
low | Int | 最低溫度(℃) | data_type=fc/all | 999999 | 基礎欄位 |
wc_day | String | 白天風力 | data_type=fc/all | “暫無” | 基礎欄位 |
wc_night | String | 晚上風力 | data_type=fc/all | “暫無” | 基礎欄位 |
wd_day | String | 白天風向 | data_type=fc/all | “暫無” | 基礎欄位 |
wd_night | String | 晚上風向 | data_type=fc/all | “暫無” | 基礎欄位 |
text_day | String | 白天天氣現象 | data_type=fc/all | “暫無” | 基礎欄位 |
text_night | String | 晚上天氣現象 | data_type=fc/all | “暫無” | 基礎欄位 |
示例程式碼
{
"status": 0,
"result": {
"location": {
"country": "中國",
"province": "北京市",
"city": "北京市",
"name": "北京",
"id": "110100"
},
"now": {
"text": "晴",
"temp": 0,
"feels_like": 0,
"rh": 27,
"wind_class": "2級",
"wind_dir": "南風",
"uptime": "20201208162500"
},
"forecasts": [{
"text_day": "多雲",
"text_night": "多雲",
"high": 2,
"low": -6,
"wc_day": "<3級",
"wd_day": "南風",
"wc_night": "<3級",
"wd_night": "南風",
"date": "2020-12-08",
"week": "星期二"
}, {
"text_day": "晴",
"text_night": "晴",
"high": 4,
"low": -5,
"wc_day": "<3級",
"wd_day": "西南風",
"wc_night": "<3級",
"wd_night": "北風",
"date": "2020-12-09",
"week": "星期三"
}, {
"text_day": "晴",
"text_night": "晴",
"high": 6,
"low": -4,
"wc_day": "<3級",
"wd_day": "西南風",
"wc_night": "<3級",
"wd_night": "北風",
"date": "2020-12-10",
"week": "星期四"
}, {
"text_day": "多雲",
"text_night": "多雲",
"high": 4,
"low": -5,
"wc_day": "<3級",
"wd_day": "南風",
"wc_night": "<3級",
"wd_night": "北風",
"date": "2020-12-11",
"week": "星期五"
}, {
"text_day": "多雲",
"text_night": "多雲",
"high": 5,
"low": -5,
"wc_day": "<3級",
"wd_day": "西南風",
"wc_night": "4~5級",
"wd_night": "北風",
"date": "2020-12-12",
"week": "星期六"
}]
},
"message": "success"
}