【转载】C#挪用国家气象局天气预报接口

时间:2022-02-19 08:22:38

今日北京天气:15℃~5℃ 阵雨转阴,寒风3-4级,天气冷,建议着棉服、羽绒服、皮夹克加羊毛衫等冬季打扮。大哥体弱者宜着厚棉衣、冬大衣 或厚羽绒服。 洗车指数:不宜。紫外线指数:最弱。晨练指数:较不宜.舒适指数:较舒适。

还好,国家气象局供给相关接口,再此暗示感谢感动,虽然小我私家感受该api设计思路有待提高,但是对比于其他部委【如交通部】来说,气象局这个冷衙门有开源、开放的心态,对比而言,相当了不起。等候后期能在接口规范、可供给盘问都市数量等方面继续提高。

二.接口说明

据我所知,气象局供给三个天气盘问接口,如下:

1、实时天气接口

地点: sk/【都市代码】.html

例如:盘问北京实时天气

功效:

{"weatherinfo":{"city":"北京","cityid":"101010100","temp":"13","WD":"南风","WS":"2","SD":"59%","WSE":"2","time":"10:30","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB"}}

2、今日天气接口

地点:【都市代码】.html

例如:盘问北京今日天气

功效:

{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"15","temp2":"5℃","weather":"阵雨转阴","img1":"d3.gif","img2":"n2.gif","ptime":"08:00"}}

3、今日及未来天气接口【内容最详细】

地点:【都市代码】.html

例如:盘问北京今日及未来天气

功效:

{"weatherinfo":{"city":"北京","city_en":"beijing","date_y":"2013年10月22日","date":"","week":"星期二","fchh":"08","cityid":"101010100","temp1":"15℃~5℃","temp2":"15℃~4℃………【省略】"index_tr":"适宜","index_co":"较舒适","st1":"11","st2":"1","st3":"13","st4":"5","st5":"14","st6":"4","index_cl":"较不宜","index_ls":"不太适宜","index_ag":"不易发"}}

字段说明:我恰好是挪用这个接口,所以下面通过对应的实体及属性来说明上述返回功效中各字段的含义

/// <summary> /// 天气盘问功效信息实体 /// </summary> public class WeatherinfoModel { /// <summary> /// 都市名称 /// </summary> public String city{get;set;} /// <summary> /// 都市英文名称==拼音 /// </summary> public String city_en{get;set;} /// <summary> /// 今日时间【年-月-日】 /// </summary> public String date_y{get;set;} /// <summary> /// 为空,,无用 /// </summary> public String date{get;set;} /// <summary> /// 星期几 /// </summary> public String week{get;set;} /// <summary> /// 系统更新时间 /// </summary> public String fchh{get;set;} /// <summary> /// 都市代码 /// </summary> public String cityid{get;set;} /// <summary> /// 今天及之后五天的摄氏温度 /// </summary> public String temp1{get;set;} public String temp2{get;set;} public String temp3{get;set;} public String temp4{get;set;} public String temp5{get;set;} public String temp6{get;set;} /// <summary> /// 今天及之后五天的华氏温度 /// </summary> public String tempF1{get;set;} public String tempF2{get;set;} public String tempF3{get;set;} public String tempF4{get;set;} public String tempF5{get;set;} public String tempF6{get;set;} /// <summary> /// 今天及之后五天的天气描述 /// </summary> public String weather1{get;set;} public String weather2{get;set;} public String weather3{get;set;} public String weather4{get;set;} public String weather5{get;set;} public String weather6{get;set;} /// <summary> /// 天气描述图片序号 /// </summary> public String img1{get;set;} public String img2{get;set;} public String img3{get;set;} public String img4{get;set;} public String img5{get;set;} public String img6{get;set;} public String img7{get;set;} public String img8{get;set;} public String img9{get;set;} public String img10{get;set;} public String img11{get;set;} public String img12{get;set;} public String img_single{get;set;} /// <summary> /// 图片名称 /// </summary> public String img_title1{get;set;} public String img_title2{get;set;} public String img_title3{get;set;} public String img_title4{get;set;} public String img_title5{get;set;} public String img_title6{get;set;} public String img_title7{get;set;} public String img_title8{get;set;} public String img_title9{get;set;} public String img_title10{get;set;} public String img_title11{get;set;} public String img_title12{get;set;} public String img_title_single{get;set;} /// <summary> /// 今天及之后五天的风速描述 /// </summary> public String wind1{get;set;} public String wind2{get;set;} public String wind3{get;set;} public String wind4{get;set;} public String wind5{get;set;} public String wind6{get;set;} /// <summary> /// 风速级别描述 /// </summary> public String fx1{get;set;} public String fx2{get;set;} public String fl1{get;set;} public String fl2{get;set;} public String fl3{get;set;} public String fl5{get;set;} public String fl6{get;set;} /// <summary> /// 今天穿衣指数 /// </summary> public String index{get;set;} public String index_d{get;set;} /// <summary> /// 48小时穿衣指数 /// </summary> public String index48{get;set;} public String index48_d{get;set;} /// <summary> /// 紫外线及48小时紫外线 /// </summary> public String index_uv{get;set;} public String index48_uv{get;set;} /// <summary> /// 洗车 /// </summary> public String index_xc{get;set;} /// <summary> /// 旅游 /// </summary> public String index_tr{get;set;} /// <summary> /// 舒适指数 /// </summary> public String index_co{get;set;} /// <summary> /// ?? /// </summary> public String st1{get;set;} public String st2{get;set;} public String st3{get;set;} public String st4{get;set;} public String st5{get;set;} public String st6{get;set;} /// <summary> /// 晨练 /// </summary> public String index_cl{get;set;} /// <summary> /// 晾晒 /// </summary> public String index_ls{ get; set; } /// <summary> /// 过敏 /// </summary> public String index_ag{get;set;} }