全国和国际天气预报API免费接口
中国国家气象局城市天气ID及天气预报接口
中国国家气象局城市天气ID及天气预报接口城市天气ID直辖市"北京","上海","天津","重庆""101010100","101020100","101030100","101040100"特别行政区"香港","澳门""101320101","101330101"黑龙江"哈尔滨","齐齐哈尔","牡丹江","大庆","伊春","双鸭山","鹤岗","鸡西","佳木斯","七台河","黑河","绥化","大兴安岭""101050101","101050201","101050301","101050901","1010 50801","101051301","101051201","101051101","101050401","1 01051002","101050601","101050501","101050701"吉林"长春","延吉","吉林","白山","白城","四平","松原","辽源","大安","通化""101060101","101060301","101060201","101060901","1010 60601","101060401","101060801","101060701","101060603","1 01060501"辽宁"沈阳","大连","葫芦岛","盘锦","本溪","抚顺","铁岭","辽阳","营口","阜新","朝阳","锦州","丹东","鞍山""101070101","101070201","101071401","101071301","101070501","101070401","101071101","101071001","101070801","1 01070901","101071201","101070701","101070601","101070301"内蒙古"呼和浩特","呼伦贝尔","锡林浩特","包头","赤峰","海拉尔","乌海","鄂尔多斯","通辽""101080101","101081001","101080901","101080201","1010 80601","101081001","101080301","101080701","101080501"河北"石家庄","唐山","张家口","廊坊","邢台","邯郸","沧州","衡水","承德","保定","秦皇岛""101090101","101090501","101090301","101090601","1010 90901","101091001","101090701","101090801","101090402","1 01090201","101091101"河南"郑州","开封","洛阳","平顶山","焦作","鹤壁","新乡","安阳","濮阳","许昌","漯河","三门峡","南阳","商丘","信阳","周口","驻马店""101180101","101180801","101180901","101180501","1011 81101","101181201","101180301","101180201","101181301","1 01180401","101181501","101181701","101180701","101181001" ,"101180601","101181401","101181601"山东"济南","青岛","淄博","威海","曲阜","临沂","烟台","枣庄","聊城","济宁","菏泽","泰安","日照","东营","德州","滨州","莱芜","潍坊""101120101","101120201","101120301","101121301","1011 20710","101120901","101120501","101121401","101121701","1 01120701","101121001","101120801","101121501","101121201","101120401","101121101","101121601","101120601"山西"太原","阳泉","晋城","晋中","临汾","运城","长治","朔州","忻州","大同","吕梁""101100101","101100301","101100601","101100401","1011 00701","101100801","101100501","101100901","101101001","1 01100201","101101101"江苏"南京","苏州","昆山","南通","太仓","吴县","徐州","宜兴","镇江","淮安","常熟","盐城","泰州","无锡","连云港","扬州","常州","宿迁""101190101","101190401","101190404","101190501","1011 90408","101190406","101190801","101190203","101190301","1 01190901","101190402","101190701","101191201","101190201" ,"101191001","101190601","101191101","101191301"安徽"合肥","巢湖","蚌埠","安庆","六安","滁州","马鞍山","阜阳","宣城","铜陵","淮北","芜湖","毫州","宿州","淮南","池州""101220101","101221601","101220201","101220601","1012 21501","101221101","101220501","101220801","101221401","1 01221301","101221201","101220301","101220901","101220701" ,"101220401","101221701"陕西"西安","韩城","安康","汉中","宝鸡","咸阳","榆林","渭南","商洛","铜川","延安""101110101","101110510","101110701","101110801","1011 10901","101110200","101110401","101110501","101110601","101111001","101110300"宁夏"银川","固原","中卫","石嘴山","吴忠""101170101","101170401","101170501","101170201","1011 70301"甘肃"兰州","白银","庆阳","酒泉","天水","武威","张掖","甘南","临夏","平凉","定西","金昌""101160101","101161301","101160401","101160801","1011 60901","101160501","101160701","101050204","101161101","1 01160301","101160201","101160601"青海"西宁","海北","海西","黄南","果洛","玉树","海东","海南""101150101","101150801","101150701","101150301","1011 50501","101150601","101150201","101150401"湖北"武汉","宜昌","黄冈","恩施","荆州","神农架","十堰","咸宁","襄阳","孝感","随州","黄石","荆门","鄂州""101200101","101200901","101200501","101201001","1012 00801","101201201","101201101","101200701","101200201","1 01200401","101201301","101200601","101201401","101200301"湖南"长沙","邵阳","常德","郴州","吉首","株洲","娄底","湘潭","益阳","永州","岳阳","衡阳","怀化","韶山","张家界""101250101","101250901","101250601","101250501","101251501","101250301","101250801","101250201","101250701","1 01251401","101251001","101250401","101251201","101250202" ,"101251101"浙江"杭州","湖州","金华","宁波","丽水","绍兴","衢州","嘉兴","台州","舟山","温州""101210101","101210201","101210901","101210401","1012 10801","101210501","101211001","101210301","101210601","1 01211101","101210701"江西"南昌","萍乡","九江","上饶","抚州","吉安","鹰潭","宜春","新余","景德镇","赣州""101240101","101240901","101240201","101240301","1012 40401","101240601","101241101","101240501","101241001","1 01240801","101240701"福建"福州","厦门","龙岩","南平","宁德","莆田","泉州","三明","漳州""101230101","101230201","101230701","101230901","1012 30301","101230401","101230501","101230801","101230601"贵州"贵阳","安顺","赤水","遵义","铜仁","六盘水","毕节","凯里","都匀""101260101","101260301","101260208","101260201","1012 60601","101260801","101260701","101260501","101260401"四川"成都","泸州","内江","凉山","阿坝","巴中","广元","乐山","绵阳","德阳","攀枝花","雅安","宜宾","自贡","甘孜州","达州","资阳","广安","遂宁","眉山","南充""101270101","101271001","101271201","101271601","1012 71901","101270901","101272101","101271401","101270401","1 01272001","101270201","101271701","101271101","101270301" ,"101271801","101270601","101271301","101270801","1012707 01","101271501","101270501"广东"广州","深圳","潮州","韶关","湛江","惠州","清远","东莞","江门","茂名","肇庆","汕尾","河源","揭阳","梅州","中山","德庆","阳江","云浮","珠海","汕头","佛山""101280101","101280601","101281501","101280201","1012 81001","101280301","101281301","101281601","101281101","1 01282001","101280901","101282101","101281201","101281901" ,"101280401","101281701","101280905","101281801","1012814 01","101280701","101280501","101280800"广西"南宁","桂林","阳朔","柳州","梧州","玉林","桂平","贺州","钦州","贵港","防城港","百色","北海","河池","来宾","崇左""101300101","101300501","101300510","101300301","1013 00601","101300901","101300802","101300701","101301101","1 01300801","101301401","101301001","101301301","101301201" ,"101300401","101300201"云南"昆明","保山","楚雄","德宏","红河","临沧","怒江","曲靖","思茅","文山","玉溪","昭通","丽江","大理""101290101","101290501","101290801","101291501","1012 90301","101291101","101291201","101290401","101290901","1 01290601","101290701","101291001","101291401","101290201"海南"海口","三亚","儋州","琼山","通什","文昌""101310101","101310201","101310205","101310102","1013 10222","101310212"新疆"乌鲁木齐","阿勒泰","阿克苏","昌吉","哈密","和田","喀什","克拉玛依","石河子","塔城","库尔勒","吐鲁番","伊宁""101130101","101131401","101130801","101130401","1011 31201","101131301","101130901","101130201","101130301","1 01131101","101130601","101130501","101131001"西藏"拉萨","阿里","昌都","那曲","日喀则","山南","林芝""101140101","101140701","101140501","101140601","1011 40201","101140301","101140401"台湾"台北","高雄""101340102","101340201"天气预报接口中国国家气象局天气预报接口总共提供了三个:/data/sk/101010100.html/data/cityinfo/101010100.html /data/101010100.html{"weatherinfo":{<!-- 基本信息 -->"city":"福州","city_en":"fuzhou","date_y":"2012年5月14日","date":"","week":"星期一","fchh":"08","cityid":"101230101",<!-- 从今天开始到第六天的每天的天气情况,这里的温度是摄氏温度 -->"temp1":"29℃~23℃","temp2":"26℃~20℃","temp3":"24℃~ 20℃","temp4":"25℃~20℃","temp5":"24℃~21℃","temp6":"25℃~22℃",<!-- 从今天开始到第六天的每天的天气情况,这里的温度是华氏温度 -->"tempF1":"84.2℉~73.4℉","tempF2":"78.8℉~68℉","tempF3 ":"75.2℉~68℉","tempF4":"77℉~68℉","tempF5":"75.2℉~69.8℉","tempF6":"77℉~71.6℉",<!-- 天气描述 -->"weather1":"阵雨转中雨","weather2":"中雨转小雨","weather3":"小雨","weather4":"小雨","weather5":"小雨转阵雨","weather6":"阵雨转小雨",<!-- 天气描述图片序号 -->"img1":"3","img2":"8","img3":"8","img4":"7","img5":"7","img 6":"99","img7":"7","img8":"99","img9":"7","img10":"3","img11":" 3","img12":"7","img_single":"3",<!-- 图片名称 -->"img_title1":"阵雨","img_title2":"中雨","img_title3":"中雨","img_title4":"小雨","img_title5":"小雨","img_title6":"小雨","img_title7":"小雨","img_title8":"小雨","img_title9":"小雨","img_title10":"阵雨","img_title11":"阵雨","img_title12":"小雨","img_title_single":"阵雨",<!-- 风速描述 -->"wind1":"微风","wind2":"微风","wind3":"微风","wind4":"微风","wind5":"微风","wind6":"微风","fx1":"微风","fx2":"微风", <!-- 风速级别描述 -->"fl1":"小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级",<!-- 今天穿衣指数 -->"index":"热","index_d":"天气较热,建议着短裙、短裤、短套装、T恤等夏季服装。
天气预报接口调用方法
天气预报接口调用方法天气预报是人们日常生活中非常关注的一个信息,它可以帮助我们合理安排出行时间,选择合适的服装和做好防御措施。
而如今,我们可以通过调用天气预报接口来获取实时的天气信息,方便快捷地了解各地的天气情况。
调用天气预报接口的方法有很多种,下面我将为大家介绍一种常用的调用方式。
我们需要去相关的网站或服务平台注册一个账号,并获取到相应的API Key。
API Key是用于标识我们的身份和权限的一串字符,类似于密码,所以需要妥善保管,以防泄露。
接下来,我们可以使用编程语言中的HTTP请求库,例如Python 中的requests库,来向天气预报接口发送请求。
在发送请求之前,我们需要构建一个URL,该URL包含了我们所需的参数,例如城市名称、日期等。
参数的具体内容可以根据接口文档来确定。
在构建URL之后,我们可以通过HTTP请求库发送GET请求,将URL作为参数传入。
接口会根据我们的请求,返回相应的天气信息。
在获取到响应之后,我们可以对返回的数据进行解析,提取出我们需要的天气信息。
解析数据的过程中,我们可以使用JSON解析库来处理返回的JSON数据。
JSON是一种轻量级的数据交换格式,常用于Web应用中的数据传输。
通过JSON解析库,我们可以将返回的JSON数据转换为Python对象,方便我们进行进一步的处理和使用。
在获取到天气信息之后,我们可以根据自己的需求进行展示和处理。
例如,我们可以将天气信息显示在我们的网页或移动应用中,或者根据不同的天气条件进行相应的提醒和操作。
除了以上介绍的方法外,还有其他一些调用天气预报接口的方式,例如通过命令行工具或者可视化工具来进行操作。
不同的方式适用于不同的场景和需求,我们可以根据自己的实际情况选择合适的方法。
总结起来,调用天气预报接口的方法主要包括注册账号获取API Key、构建URL和发送请求、解析返回的数据以及展示和处理数据等步骤。
通过合理利用天气预报接口,我们可以方便地获取到实时的天气信息,为我们的生活带来便利。
【转载】C#调用国家气象局天气预报接口
【转载】C#调⽤国家⽓象局天⽓预报接⼝⼀.需求最近,刚好项⽬中有天⽓预报查询功能的需求,要求录⼊城市名称,获取该城市今⽇天⽓信息及相关⽓象⽣活辅助信息等。
例如:查询北京市天⽓结果为:今⽇北京天⽓:15℃~5℃阵⾬转阴,北风3-4级,天⽓冷,建议着棉服、⽻绒服、⽪夹克加⽺⽑衫等冬季服装。
年⽼体弱者宜着厚棉⾐、冬⼤⾐或厚⽻绒服。
洗车指数:不宜。
紫外线指数:最弱。
晨练指数:较不宜.舒适指数:较舒适。
还好,国家⽓象局提供相关接⼝,再此表⽰感谢,虽然个⼈觉得该api设计思路有待提⾼,但是相⽐于其他部委【如交通部】来说,⽓象局这个冷衙门有开源、开放的⼼态,相⽐⽽⾔,相当了不起。
期待后期能在接⼝规范、可提供查询城市数量等⽅⾯继续提⾼。
⼆.接⼝说明据我所知,⽓象局提供三个天⽓查询接⼝,如下:1、实时天⽓接⼝地址:/data/ 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、今⽇天⽓接⼝地址:/data/cityinfo/【城市代码】.html例如:查询北京今⽇天⽓结果:{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"15","temp2":"5℃","weather":"阵⾬转阴","img1":"d3.gif","img2":"n2.gif","ptime":"08:00"}}3、今⽇及未来天⽓接⼝【内容最详细】地址:/data/【城市代码】.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;}}总结:从上⾯三个接⼝来看,调⽤的关键是获取【城市代码】,所以⽓象局⼜提供了三个查询城市代码接⼝。
开源免费天气预报接口API及全国所有地区代码(国家气象局提供)
开源免费天⽓预报接⼝API及全国所有地区代码(国家⽓象局提供)国家⽓象局提供的天⽓预报接⼝接⼝地址:对于第三个接⼝,返回信息⽐较全⾯,也是以json格式提供,格式如下{"weatherinfo": {//基本信息;"city":"北京","city_en":"beijing","date_y":"2012年2⽉16⽇","date":"", "week":"星期四","fchh":"11", "cityid":"101010100",//摄⽒温度"temp1":"2℃~-7℃","temp2":"1℃~-7℃","temp3":"4℃~-7℃","temp4":"7℃~-5℃","temp5":"5℃~-3℃","temp6":"5℃~-2℃",//华⽒温度;"tempF1":"35.6℉~19.4℉","tempF2":"33.8℉~19.4℉","tempF3":"39.2℉~19.4℉","tempF4":"44.6℉~23℉","tempF5":"41℉~26.6℉","tempF6":"41℉~28.4℉",//天⽓描述;"weather1":"晴","weather2":"晴","weather3":"晴","weather4":"晴转多云","weather5":"多云","weather6":"多云转阴",//天⽓描述图⽚序号"img1":"0","img2":"99","img3":"0","img4":"99","img5":"0","img6":"99","img7":"0","img8":"1","img9":"1","img10":"99","img11":"1","img12":"2","img_single":"0",//图⽚名称;"img_title1":"晴","img_title2":"晴","img_title3":"晴","img_title4":"晴","img_title5":"晴","img_title6":"晴","img_title7":"晴","img_title8":"多云","img_title9":"多云","img_title10":"多云","img_title11":"多云","img_title12":"阴","img_title_single":"晴",//风速描述"wind1":"北风3-4级转微风","wind2":"微风","wind3":"微风","wind4":"微风","wind5":"微风","wind6":"微风",//风速级别描述"fx1":"北风","fx2":"微风","fl1":"3-4级转⼩于3级","fl2":"⼩于3级","fl3":"⼩于3级","fl4":"⼩于3级","fl5":"⼩于3级","fl6":"⼩于3级",//今天穿⾐指数;"index":"冷","index_d":"天⽓冷,建议着棉⾐、⽪夹克加⽺⽑衫等冬季服装。
天气预报API
API:天气预报使用说明目录∙说明∙形式∙参数说明∙返回内容天气预报详细说明天气预报获取接口。
您可以方便的利用天气预报API接口开发您自己的天气预报应用程序或网站。
形式/API/Life.Weather/例如:/API/Life.Weather/?city={city}&day={day}&apiid={apiid}&alt={alt} 参数说明可传参数,如下:参数类型是否可选意义枚举备注city String 是城市默认:北京day String 是天0表示当天天气,1表示第二天的天气,2表示第三天的天气,以此类推,最大为4。
默认:0apiid String 否API标识码FOXAPI的每个应用都必须使用APIID,用来记录API操作。
请到用户中心获取APIIDalt Alt 是返回的数据格式1.xml → XML形式展示数据;2.json → json形式展示数据;默认:xml返回内容该API返回的网站信息,如下:<?xml version="1.0" encoding="utf-8"?> <Back><errormsg /><city>北京</city><status1>晴</status1><status2>晴</status2><direction1>北风</direction1><direction2>北风</direction2><power1>5-6</power1><power2>4-5</power2><temperature1>12</temperature1><temperature2>0</temperature2><ssd_l>偏冷</ssd_l><ssd_s>大部分人群外出活动要戴薄手套、薄围巾和帽子。
API免费接口大全
API免费接⼝⼤全各类⽆次数限制的免费API接⼝整理,主要是聚合数据上和API Store上的⼀些,还有⼀些其他的。
聚合数据提供30⼤类,160种以上基础数据API服务,国内最⼤的基础数据API服务,下⾯就罗列⼀些免费的各类API接⼝。
⼿机号码归属地API接⼝:历史上的今天API接⼝:股票数据API接⼝:全国WIFI接⼝:星座运势接⼝:黄⾦数据接⼝:语⾳识别接⼝:周公解梦接⼝:天⽓预报API接⼝:⾝份证查询API接⼝:笑话⼤全API接⼝:邮编查询接⼝:⽼黄历接⼝:⽹站安全检测接⼝:⼿机固话来电显⽰接⼝:基⾦财务数据接⼝:成语词典接⼝:新闻头条接⼝:IP地址接⼝:问答机器⼈接⼝:汇率API接⼝:电影票房接⼝:万年历API接⼝:NBA赛事接⼝:IP地址查询频道新闻API_易源微信热门精选:天⽓查询中国和世界天⽓预报股票查询⾝份证查询:美⼥图⽚⾳乐搜索图灵机器⼈汇率转换节假⽇pullword在线分词服务去哪⼉⽹⽕车票笑话⼤全银⾏卡查询服务语⾳合成宅⾔API-动漫台词接⼝去哪⼉景点门票查询⼿机号码归属地体育新闻⼿机归属地查询科技新闻空⽓质量指数天狗健康菜谱热门游记列表天狗药品查询汉字转拼⾳国际新闻彩票微信精选天狗健康资讯兴趣点检索⽤药参考天狗健康知识奇闻趣事花边新闻天狗医院⼤全⽣活健康⼀些其他的API接⼝:⾖瓣开放淘宝开放平台图灵语⾳马化腾的微信开放平台(对应的还有腾讯开放平台)融云IM百度开发者中⼼⼈脸识别⾼德地图:蜻蜓:。
天气预报 api
全国各城市代码如下:北京:101010100朝阳:101010300顺义:101010400怀柔:101010500通州:101010600昌平:101010700延庆:101010800丰台:101010900石景山:101011000大兴:101011100房山:101011200密云:101011300门头沟:101011400平谷:101011500八达岭:101011600佛爷顶:101011700汤河口:101011800密云上甸子:101011900斋堂:101012000霞云岭:101012100北京城区:101012200海淀:101010200天津:101030100宝坻:101030300东丽:101030400西青:101030500北辰:101030600蓟县:101031400汉沽:101030800静海:101030900津南:101031000塘沽:101031100大港:101031200武清:101030200宁河:101030700上海:101020100宝山:101020300嘉定:101020500南汇:101020600浦东:101021300青浦:101020800松江:101020900奉贤:101021000崇明:101021100徐家汇:101021200闵行:101020200金山:101020700石家庄:101090101张家口:101090301承德:101090402唐山:101090501秦皇岛:101091101沧州:101090701衡水:101090801邢台:101090901邯郸:101091001保定:101090201廊坊:101090601郑州:101180101新乡:101180301许昌:101180401平顶山:101180501信阳:101180601南阳:101180701开封:101180801
根据IP地址查询所在地7天预报接口
根据IP地址查询所在地7天预报接口7天预报接口可查询天气预报,根据IP地址查询IP地址所在地的天气预报。
接口名称:7天预报接口接口平台:聚合数据接口地址:/weather/ip支持格式:JSON/XML请求方式:HTTP GET/POST请求示例:/weather/ip?format=2&key=您申请的KEY&ip=58.215.185.154接口备注:根据IP地址查询IP地址所在地的天气预报7天预报接口JSON返回示例:{"resultcode": "200","reason": "查询成功!","result": {"sk": { /*当前实况天气*/"temp": "21", /*当前温度*/"wind_direction": "西风", /*当前风向*/"wind_strength": "2级", /*当前风力*/"humidity": "4%", /*当前湿度*/"time": "14:25" /*更新时间*/},"today": {"city": "天津","date_y": "2014年03月21日","week": "星期五","temperature": "8℃~20℃", /*今日温度*/"weather": "晴转霾", /*今日天气*/"weather_id": { /*天气唯一标识*/"fa": "00", /*天气标识00:晴*/"fb": "53"/*天气标识53:霾如果fa不等于fb,说明是组合天气*/ },"wind": "西南风微风","dressing_index": "较冷", /*穿衣指数*/"dressing_advice": "建议着大衣、呢外套加毛衣、卫衣等服装。
中央气象台API
101011100=大兴
101011200=房山
101011300=密云
101011400=门头沟
101011500=平谷
101011600=八达岭
101011700=佛爷顶
101011800=汤河口
101011900=密云上甸子
101012000=斋堂
101080203=满都拉
101080204=土默特右旗
101080205=固阳
101080206=达尔罕茂明安联合旗
101080207=石拐
101080301=乌海
101080401=集宁
101080402=卓资
101080403=化德
101080404=商都
101050404=桦川
101050405=桦南
101050406=同江
101050407=富锦
101050501=绥化
101050502=肇东
101050503=安达
101050504=海伦
101050505=明水
101050506=望奎
101080405=希拉穆仁
101080406=兴和
101080407=凉城
101080408=察哈尔右翼前旗
101080409=察哈尔右翼中旗
101070106=新民
101070107=于洪
101070108=新城子
101070201=大连
101070202=瓦房店
101070203=金州
101070204=普兰店
101070205=旅顺
101070206=长海
城市天气三小时预报 天气预报api接口大全实现
{
"weatherid": "02",
"weather": "阴",
"temp1": "23",
"temp2": "22",
"sh": "02",
"eh": "05",
"date": "20140531",
"sfdate": "20140531020000",
"efdate": "20140531050000"
},
{
"weatherid": "01",
"weather": "多云",
"temp1": "26",
"temp2": "23",
"sh": "08",
"eh": "02",
"date": "20140602",
"sfdate": "20140602200000",
"efdate": "20140603020000"
},
{
"weatherid": "07",
"weather": "小雨",
"temp1": "23",
百度天气API接口
百度天⽓API接⼝接⼝说明根据经纬度/城市名查询天⽓的结果。
接⼝参数说明参数类型参数名称是否必须具体描述String ak true开发者密钥String sn false若⽤户所⽤ak的校验⽅式为sn校验时该参数必须。
String location true 输⼊城市名或经纬度,城市名称如:北京,经纬度格式为lng,lat坐标如:location=116.305145,39.982368;城市天⽓预报中间"|"分隔,location=116.305145,39.982368| 122.305145,36.982368|….String output false输出的数据格式,默认为xml格式,当output设置为’json’时,输出的为json格式的数据;String coord_type false 请求参数坐标类型,默认为gcj02经纬度坐标。
允许的值为bd09ll、bd09mc、gcj02、wgs84。
bd09ll表⽰百度经纬度坐标,bd09mc表⽰百度墨卡托坐标,gcj02表⽰经过国测局加密的坐标。
wgs84表⽰gps获取的坐标。
返回结果参数名称含义说明currentCity当前城市返回城市名status返回结果状态信息date当前时间年-⽉-⽇results天⽓预报信息⽩天可返回近期3天的天⽓情况(今天、明天、后天)、晚上可返回近期4天的天⽓情况(今天、明天、后天、⼤后天)results.currentCity当前城市results.weather_data weather_data.date天⽓预报时间weather_data.dayPictureUrl⽩天的天⽓预报图⽚urlweather_data.nightPictureUrl晚上的天⽓预报图⽚urlweather_data.weather天⽓状况所有天⽓情况(”|”分隔符):晴|多云|阴|阵⾬|雷阵⾬|雷阵⾬伴有冰雹|⾬夹雪|⼩⾬|中⾬|⼤⾬|暴⾬|⼤暴⾬|特⼤暴⾬|阵雪|⼩雪|中雪|⼤雪|暴雪|雾|冻⾬|沙尘暴|⼩⾬转中⾬|中⾬转⼤⾬|⼤⾬转暴⾬|暴⾬转⼤暴⾬|⼤暴⾬转特⼤暴⾬|⼩雪转中雪|中雪转⼤雪|⼤雪转暴雪|浮尘|扬沙|强沙尘暴|霾weather_data.wind风⼒weather_data.temperature温度返回xml格式的数据<?xml version="1.0" encoding="utf-8" ?><CityWeatherResponse><status>success</status><date>2014-05-03</date><results><currentCity>北京</currentCity><weather_data><date>周六(今天, 实时:22℃)</date><dayPictureUrl>/images/weather/day/leizhenyu.png</dayPictureUrl> <nightPictureUrl>/images/weather/night/duoyun.png</nightPictureUrl> <weather>雷阵⾬转多云</weather><wind>北风5-6级</wind><temperature>24 ~ 11℃</temperature><date>周⽇</date><dayPictureUrl>/images/weather/day/duoyun.png</dayPictureUrl><nightPictureUrl>/images/weather/night/qing.png</nightPictureUrl> <weather>多云转晴</weather><wind>北风4-5级</wind><temperature>19 ~ 8℃</temperature><date>周⼀</date><dayPictureUrl>/images/weather/day/qing.png</dayPictureUrl><nightPictureUrl>/images/weather/night/qing.png</nightPictureUrl><weather>晴</weather><wind>微风</wind><temperature>21 ~ 9℃</temperature><date>周⼆</date><dayPictureUrl>/images/weather/day/duoyun.png</dayPictureUrl> <nightPictureUrl>/images/weather/night/qing.png</nightPictureUrl> <weather>多云转晴</weather><wind>微风</wind><temperature>21 ~ 10℃</temperature></weather_data></results></CityWeatherResponse>返回json格式的数据{"error": 0,"status": "success","date": "2014-05-03","results": [{"currentCity": "北京","weather_data": [{"date": "周六(今天, 实时:22℃)","dayPictureUrl": "/images/weather/day/leizhenyu.png","nightPictureUrl": "/images/weather/night/duoyun.png","weather": "雷阵⾬转多云","wind": "北风5-6级","temperature": "24 ~ 11℃"},{"date": "周⽇","dayPictureUrl": "/images/weather/day/duoyun.png","nightPictureUrl": "/images/weather/night/qing.png","weather": "多云转晴","wind": "北风4-5级","temperature": "19 ~ 8℃"},{"date": "周⼀","dayPictureUrl": "/images/weather/day/qing.png","nightPictureUrl": "/images/weather/night/qing.png","weather": "晴","wind": "微风","temperature": "21 ~ 9℃"},{"date": "周⼆","dayPictureUrl": "/images/weather/day/duoyun.png","nightPictureUrl": "/images/weather/night/qing.png","weather": "多云转晴","wind": "微风","temperature": "21 ~ 10℃"}]}]}。
国家气象局免费天气预报接口,城市代码(JSON格式)
{"城市代码": [{"省": "北京","市": [{"市名": "北京","编码": "101010100"},{"市名": "朝阳","编码": "101010300"},{"市名": "顺义","编码": "101010400"},{"市名": "怀柔","编码": "101010500"},{"市名": "通州","编码": "101010600"},{"市名": "昌平","编码": "101010700"},{"市名": "延庆","编码": "101010800"},{"市名": "丰台","编码": "101010900"},{"市名": "石景山","编码": "101011000"},{"市名": "大兴","编码": "101011100"{"市名": "房山","编码": "101011200" },{"市名": "密云","编码": "101011300" },{"市名": "门头沟","编码": "101011400" },{"市名": "平谷","编码": "101011500" },{"市名": "八达岭","编码": "101011600" },{"市名": "佛爷顶","编码": "101011700" },{"市名": "汤河口","编码": "101011800" },{"市名": "密云上甸子","编码": "101011900" },{"市名": "斋堂","编码": "101012000" },{"市名": "霞云岭","编码": "101012100" },{"市名": "北京城区","编码": "101012200"{"市名": "海淀","编码": "101010200"}]},{"省": "天津市","市": [{"市名": "天津","编码": "101030100"},{"市名": "宝坻","编码": "101030300"},{"市名": "东丽","编码": "101030400"},{"市名": "西青","编码": "101030500"},{"市名": "北辰","编码": "101030600"},{"市名": "蓟县","编码": "101031400"},{"市名": "汉沽","编码": "101030800"},{"市名": "静海","编码": "101030900"},{"市名": "津南","编码": "101031000"},{"市名": "塘沽","编码": "101031100"},{"市名": "大港","编码": "101031200"},{"市名": "武清","编码": "101030200"},{"市名": "宁河","编码": "101030700"}]},{"省": "上海","市": [{"市名": "上海","编码": "101020100"},{"市名": "宝山","编码": "101020300"},{"市名": "嘉定","编码": "101020500"},{"市名": "南汇","编码": "101020600"},{"市名": "浦东","编码": "101021300"},{"市名": "青浦","编码": "101020800"},{"市名": "松江","编码": "101020900"},{"市名": "奉贤","编码": "101021000"},{"市名": "崇明","编码": "101021100"},{"市名": "徐家汇","编码": "101021200"},{"市名": "闵行","编码": "101020200"},{"市名": "金山","编码": "101020700"}]},{"省": "河北","市": [{"市名": "石家庄","编码": "101090101"},{"市名": "张家口","编码": "101090301"},{"市名": "承德","编码": "101090402"},"市名": "唐山","编码": "101090501"},{"市名": "秦皇岛","编码": "101091101"},{"市名": "沧州","编码": "101090701"},{"市名": "衡水","编码": "101090801"},{"市名": "邢台","编码": "101090901"},{"市名": "邯郸","编码": "101091001"},{"市名": "保定","编码": "101090201"},{"市名": "廊坊","编码": "101090601"}]},{"省": "河南","市": [{"市名": "郑州","编码": "101180101"},{"市名": "新乡","编码": "101180301"{"市名": "许昌","编码": "101180401" },{"市名": "平顶山","编码": "101180501" },{"市名": "信阳","编码": "101180601" },{"市名": "南阳","编码": "101180701" },{"市名": "开封","编码": "101180801" },{"市名": "洛阳","编码": "101180901" },{"市名": "商丘","编码": "101181001" },{"市名": "焦作","编码": "101181101" },{"市名": "鹤壁","编码": "101181201" },{"市名": "濮阳","编码": "101181301" },{"市名": "周口","编码": "101181401"{"市名": "漯河","编码": "101181501"},{"市名": "驻马店","编码": "101181601"},{"市名": "三门峡","编码": "101181701"},{"市名": "济源","编码": "101181801"},{"市名": "安阳","编码": "101180201"}]},{"省": "安徽","市": [{"市名": "合肥","编码": "101220101"},{"市名": "芜湖","编码": "101220301"},{"市名": "淮南","编码": "101220401"},{"市名": "马鞍山","编码": "101220501"},{"市名": "安庆",},{"市名": "宿州","编码": "101220701" },{"市名": "阜阳","编码": "101220801" },{"市名": "亳州","编码": "101220901" },{"市名": "黄山","编码": "101221001" },{"市名": "滁州","编码": "101221101" },{"市名": "淮北","编码": "101221201" },{"市名": "铜陵","编码": "101221301" },{"市名": "宣城","编码": "101221401" },{"市名": "六安","编码": "101221501" },{"市名": "巢湖","编码": "101221601" },{"市名": "池州",},{"市名": "蚌埠","编码": "101220201"}]},{"省": "浙江","市": [{"市名": "杭州","编码": "101210101"},{"市名": "舟山","编码": "101211101"},{"市名": "湖州","编码": "101210201"},{"市名": "嘉兴","编码": "101210301"},{"市名": "金华","编码": "101210901"},{"市名": "绍兴","编码": "101210501"},{"市名": "台州","编码": "101210601"},{"市名": "温州","编码": "101210701"},{"市名": "丽水","编码": "101210801"},{"市名": "衢州","编码": "101211001"},{"市名": "宁波","编码": "101210401"}]},{"省": "重庆","市": [{"市名": "重庆","编码": "101040100"},{"市名": "合川","编码": "101040300"},{"市名": "南川","编码": "101040400"},{"市名": "江津","编码": "101040500"},{"市名": "万盛","编码": "101040600"},{"市名": "渝北","编码": "101040700"},{"市名": "北碚","编码": "101040800"},"市名": "巴南","编码": "101040900" },{"市名": "长寿","编码": "101041000" },{"市名": "黔江","编码": "101041100" },{"市名": "万州天城","编码": "101041200" },{"市名": "万州龙宝","编码": "101041300" },{"市名": "涪陵","编码": "101041400" },{"市名": "开县","编码": "101041500" },{"市名": "城口","编码": "101041600" },{"市名": "云阳","编码": "101041700" },{"市名": "巫溪","编码": "101041800" },{"市名": "奉节","编码": "101041900" },"市名": "巫山","编码": "101042000" },{"市名": "潼南","编码": "101042100" },{"市名": "垫江","编码": "101042200" },{"市名": "梁平","编码": "101042300" },{"市名": "忠县","编码": "101042400" },{"市名": "石柱","编码": "101042500" },{"市名": "大足","编码": "101042600" },{"市名": "荣昌","编码": "101042700" },{"市名": "铜梁","编码": "101042800" },{"市名": "璧山","编码": "101042900" },{"市名": "丰都","编码": "101043000" },"市名": "武隆","编码": "101043100"},{"市名": "彭水","编码": "101043200"},{"市名": "綦江","编码": "101043300"},{"市名": "酉阳","编码": "101043400"},{"市名": "秀山","编码": "101043600"},{"市名": "沙坪坝","编码": "101043700"},{"市名": "永川","编码": "101040200"}]},{"省": "福建","市": [{"市名": "福州","编码": "101230101"},{"市名": "泉州","编码": "101230501"},{"市名": "漳州","编码": "101230601"{"市名": "龙岩","编码": "101230701"},{"市名": "晋江","编码": "101230509"},{"市名": "南平","编码": "101230901"},{"市名": "厦门","编码": "101230201"},{"市名": "宁德","编码": "101230301"},{"市名": "莆田","编码": "101230401"},{"市名": "三明","编码": "101230801"}]},{"省": "甘肃","市": [{"市名": "兰州","编码": "101160101"},{"市名": "平凉","编码": "101160301"},{"市名": "庆阳",},{"市名": "武威","编码": "101160501" },{"市名": "金昌","编码": "101160601" },{"市名": "嘉峪关","编码": "101161401" },{"市名": "酒泉","编码": "101160801" },{"市名": "天水","编码": "101160901" },{"市名": "武都","编码": "101161001" },{"市名": "临夏","编码": "101161101" },{"市名": "合作","编码": "101161201" },{"市名": "白银","编码": "101161301" },{"市名": "定西","编码": "101160201" },{"市名": "张掖",}]},{"省": "广东","市": [{"市名": "广州","编码": "101280101"},{"市名": "惠州","编码": "101280301"},{"市名": "梅州","编码": "101280401"},{"市名": "汕头","编码": "101280501"},{"市名": "深圳","编码": "101280601"},{"市名": "珠海","编码": "101280701"},{"市名": "佛山","编码": "101280800"},{"市名": "肇庆","编码": "101280901"},{"市名": "湛江","编码": "101281001"},{"编码": "101281101" },{"市名": "河源","编码": "101281201" },{"市名": "清远","编码": "101281301" },{"市名": "云浮","编码": "101281401" },{"市名": "潮州","编码": "101281501" },{"市名": "东莞","编码": "101281601" },{"市名": "中山","编码": "101281701" },{"市名": "阳江","编码": "101281801" },{"市名": "揭阳","编码": "101281901" },{"市名": "茂名","编码": "101282001" },{"市名": "汕尾","编码": "101282101" },{"编码": "101280201"}]},{"省": "广西","市": [{"市名": "南宁","编码": "101300101"},{"市名": "柳州","编码": "101300301"},{"市名": "来宾","编码": "101300401"},{"市名": "桂林","编码": "101300501"},{"市名": "梧州","编码": "101300601"},{"市名": "防城港","编码": "101301401"},{"市名": "贵港","编码": "101300801"},{"市名": "玉林","编码": "101300901"},{"市名": "百色","编码": "101301001"},{"市名": "钦州","编码": "101301101"},{"市名": "河池","编码": "101301201"},{"市名": "北海","编码": "101301301"},{"市名": "崇左","编码": "101300201"},{"市名": "贺州","编码": "101300701"}]},{"省": "贵州","市": [{"市名": "贵阳","编码": "101260101"},{"市名": "安顺","编码": "101260301"},{"市名": "都匀","编码": "101260401"},{"市名": "兴义","编码": "101260906"},{"市名": "铜仁","编码": "101260601"},{"市名": "毕节","编码": "101260701"},{"市名": "六盘水","编码": "101260801"},{"市名": "遵义","编码": "101260201"},{"市名": "凯里","编码": "101260501"}]},{"省": "云南","市": [{"市名": "昆明","编码": "101290101"},{"市名": "红河","编码": "101290301"},{"市名": "文山","编码": "101290601"},{"市名": "玉溪","编码": "101290701"},{"市名": "楚雄","编码": "101290801"},{"市名": "普洱","编码": "101290901"},{"市名": "昭通","编码": "101291001"},{"市名": "临沧","编码": "101291101"},{"市名": "怒江","编码": "101291201"},{"市名": "香格里拉","编码": "101291301"},{"市名": "丽江","编码": "101291401"},{"市名": "德宏","编码": "101291501"},{"市名": "景洪","编码": "101291601"},{"市名": "大理","编码": "101290201"},{"市名": "曲靖","编码": "101290401"},{"市名": "保山","编码": "101290501"}]},{"省": "内蒙古","市": [{"市名": "呼和浩特","编码": "101080101"},{"市名": "乌海","编码": "101080301"},{"市名": "集宁","编码": "101080401"},{"市名": "通辽","编码": "101080501"},{"市名": "阿拉善左旗","编码": "101081201"},{"市名": "鄂尔多斯","编码": "101080701"},{"市名": "临河","编码": "101080801"},{"市名": "锡林浩特","编码": "101080901"},{"市名": "呼伦贝尔","编码": "101081000"},{"市名": "乌兰浩特","编码": "101081101"},{"市名": "包头","编码": "101080201"},{"市名": "赤峰","编码": "101080601"}]},{"省": "江西","市": [{"市名": "南昌","编码": "101240101"},{"市名": "上饶","编码": "101240301"},{"市名": "抚州","编码": "101240401"},{"市名": "宜春","编码": "101240501"},{"市名": "鹰潭","编码": "101241101"},{"市名": "赣州","编码": "101240701"},{"市名": "景德镇","编码": "101240801"},{"市名": "萍乡","编码": "101240901"},"市名": "新余","编码": "101241001"},{"市名": "九江","编码": "101240201"},{"市名": "吉安","编码": "101240601"}]},{"省": "湖北","市": [{"市名": "武汉","编码": "101200101"},{"市名": "黄冈","编码": "101200501"},{"市名": "荆州","编码": "101200801"},{"市名": "宜昌","编码": "101200901"},{"市名": "恩施","编码": "101201001"},{"市名": "十堰","编码": "101201101"},{"市名": "神农架","编码": "101201201"{"市名": "随州","编码": "101201301"},{"市名": "荆门","编码": "101201401"},{"市名": "天门","编码": "101201501"},{"市名": "仙桃","编码": "101201601"},{"市名": "潜江","编码": "101201701"},{"市名": "襄樊","编码": "101200201"},{"市名": "鄂州","编码": "101200301"},{"市名": "孝感","编码": "101200401"},{"市名": "黄石","编码": "101200601"},{"市名": "咸宁","编码": "101200701"}]},{"省": "四川","市": [{"市名": "成都","编码": "101270101"},{"市名": "自贡","编码": "101270301"},{"市名": "绵阳","编码": "101270401"},{"市名": "南充","编码": "101270501"},{"市名": "达州","编码": "101270601"},{"市名": "遂宁","编码": "101270701"},{"市名": "广安","编码": "101270801"},{"市名": "巴中","编码": "101270901"},{"市名": "泸州","编码": "101271001"},{"市名": "宜宾","编码": "101271101"},{"市名": "内江","编码": "101271201"},{"市名": "资阳","编码": "101271301"},{"市名": "乐山","编码": "101271401"},{"市名": "眉山","编码": "101271501"},{"市名": "凉山","编码": "101271601"},{"市名": "雅安","编码": "101271701"},{"市名": "甘孜","编码": "101271801"},{"市名": "阿坝","编码": "101271901"},{"市名": "德阳","编码": "101272001"},{"市名": "广元","编码": "101272101"},{"市名": "攀枝花","编码": "101270201"}]},{"省": "宁夏","市": [{"市名": "银川","编码": "101170101"},{"市名": "中卫","编码": "101170501"},{"市名": "固原","编码": "101170401"},{"市名": "石嘴山","编码": "101170201"},{"市名": "吴忠","编码": "101170301"}]},{"省": "青海省","市": [{"市名": "西宁","编码": "101150101"},{"市名": "黄南","编码": "101150301"},{"市名": "海北","编码": "101150801"},{"市名": "果洛","编码": "101150501"},{"市名": "玉树","编码": "101150601"},{"市名": "海西","编码": "101150701"},{"市名": "海东","编码": "101150201"},{"市名": "海南","编码": "101150401"}]},{"省": "山东","市": [{"市名": "济南","编码": "101120101"},{"市名": "潍坊","编码": "101120601"},{"市名": "临沂","编码": "101120901"},{"市名": "菏泽","编码": "101121001"},{"市名": "滨州","编码": "101121101"},{"市名": "东营","编码": "101121201"{"市名": "威海","编码": "101121301" },{"市名": "枣庄","编码": "101121401" },{"市名": "日照","编码": "101121501" },{"市名": "莱芜","编码": "101121601" },{"市名": "聊城","编码": "101121701" },{"市名": "青岛","编码": "101120201" },{"市名": "淄博","编码": "101120301" },{"市名": "德州","编码": "101120401" },{"市名": "烟台","编码": "101120501" },{"市名": "济宁","编码": "101120701" },{"市名": "泰安","编码": "101120801"。
PHP天气API接口
input, button, select, textarea {
outline: none;
}
textarea {
font-size: 13px;
resize: none;
}
body {
background: #F2F2F2 url(/haoqq/v101/v1img/xs-bg.png) top center no-repeat;
/**
*获取用户真实IP
*/
function getIP()
{
static $realip;
if (isset($_SERVER)){
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
lunar = data;
var month = data.month;
var day = data.day;
$("#lunarday").html("农历"+month+day);
$("#dateday").html(date.getFullYear()+"."+(date.getMonth()+1)+"."+date.getDate()+" "+getWeek(date.getDay()));
$(document).ready(function() {
$("#weekday").html(date.getDate());
百度天气预报api接口
},
{
"wid": "01",
"weather": "多云"
},
{
"wid": "02",
"weather": "阴"
},
{
"wid": "03",
"weather": "阵雨"
},
{
"wid": "04",
"weather": "雷阵雨"
},
{
"wid": "05",
"weather": "雷阵雨伴有冰雹"
},
{
"wid": "11",
"weather": "大暴雨"
},
{
"wid": "12",
"weather": "特大暴雨"
},
{
"wid": "13",
"weather": "阵雪"
},
{
"wid": "14",
"weather": "小雪"
},
{
"wid": "15",
全国天气预报接口
全国天气预报接口查询天气预报在APP中常用的一个常用功能,聚合数据全国天气预报接口可以根据根据城市名/id查询天气、根据IP查询天气、据GPS坐标查询天气、查询城市天气三小时预报,并且支持全国不同城市天气预报查询。
代码描述:基于JAVA的全国天气预报接口调用示例,根据文档中注明的需求参数,调用接口返回数据。
关联数据:全国天气预报接口接口地址:https:///docs/api/id/39step1:选择本文所示例的接口"全国天气预报接口" url:/docs/api/id/39/aid/87step2:每个接口都需要传入一个参数key,相当于用户的令牌,所以第一步你需要申请一个keystep3:看文档!!!学过java的同学们都知道,当我们对一个类或者方法不明白其意图和思想时,我们可以去查看文档,这里也不例外,而且对于英文不是特别好的同学来说很幸运的是,聚合网站上的文档都是中文版本的,比起阅读java源码里的英文文档应该轻松很多.全国天气预报接口下面有六个子接口,打开第一个接口链接,看文档发现需要传入一个城市名或者城市ID参数,这个参数我们可以通过第六个子接口获取(接口之间参数的调用类似于java中方法之间的调用),即支持城市列表获取.所以示例中我们先调用这个接口.调用接口涉及到请求网络资源的问题,这里我封装了一个工具类,包含GET和POST两种方法step4:上代码Demo1:网络访问工具类(封装get和post方法)1.package juheAPI;2.3.import java.io.BufferedReader;4.import java.io.BufferedWriter;5.import java.io.InputStream;6.import java.io.InputStreamReader;7.import java.io.OutputStream;8.import java.io.OutputStreamWriter;9.import .HttpURLConnection;10.import .URL;11.import java.util.Map;12.13.public class PureNetUtil {14.15.public static String get(String url){16.return post(url,null);17.}18.19.public static String post(String url,Map param){20.HttpURLConnection conn=null;21.try{22.URL u=new URL(url);23.conn=(HttpURLConnection) u.openConnection();24.StringBuffer sb=null;25.if(param!=null){//如果请求参数不为空26.sb=new StringBuffer();27.28.//默认为false,post方法需要写入参数,设定true29.conn.setDoOutput(true);30.//设定post方法,默认get31.conn.setRequestMethod("POST");32.//获得输出流33.OutputStream out=conn.getOutputStream();34.//对输出流封装成高级输出流35.BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(out));36.//将参数封装成键值对的形式37.for(Map.Entry s:param.entrySet()){38.sb.append(s.getKey()).append("=").append(s.getValue()).append("&");39.}40.//将参数通过输出流写入41.writer.write(sb.deleteCharAt(sb.toString().length()-1).toString());42.writer.close();//一定要关闭,不然可能出现参数不全的错误43.sb=null;44.}45.conn.connect();//建立连接46.sb=new StringBuffer();47.//获取连接状态码48.int recode=conn.getResponseCode();49.BufferedReader reader=null;50.if(recode==200){51.//Returns an input stream that reads from this open connection52.//从连接中获取输入流53.InputStream in=conn.getInputStream();54.//对输入流进行封装55.reader=new BufferedReader(new InputStreamReader(in));56.String str=null;57.sb=new StringBuffer();58.//从输入流中读取数据59.while((str=reader.readLine())!=null){60.sb.append(str).append(System.getProperty("line.separator"));61.}62.//关闭输入流63.reader.close();64.if(sb.toString().length() == 0) {65.return null;66.}67.return sb.toString().substring(0,68.sb.toString().length() - System.getProperty("line.separator").length());69.}70.} catch(Exception e) {71. e.printStackTrace();72.return null;73.}finally{74.if(conn!=null)//关闭连接75.conn.disconnect();76.}77.return null;78.}79.80.}Demo2:调用获取城市列表接口示例1.package juheAPI;2.3.import net.sf.json.JSONArray;4.import net.sf.json.JSONObject;5.6.7.8.public class GetCityList {9.10.public static String excute(){11.String url="/weather/citys?key=***a7558b2e0bedaa19673f74a6809ce";//接口URL12.//PureNetUtil是一个封装了get和post方法获取网络请求数据的工具类13.return PureNetUtil.get(url);//使用get方法14.}15.16.public static String getIDBycityName(String cityName) {17.String result=excute();//返回接口结果,得到json格式数据18.if(result!=null){19.JSONObject obj=JSONObject.fromObject(result);20.result=obj.getString("resultcode");//得到返回状态码21.if(result!=null&&result.equals("200")){//200表示成功返回数据22.result=obj.getString("result");//得到城市列表的json格式字符串数组23.JSONArray arr=JSONArray.fromObject(result);24.for(Object o:arr){//对arr进行遍历25.//将数组中的一个json个数字符串进行解析26.obj=JSONObject.fromObject(o.toString());27.28.//以city这个key为线索判断所需要寻找的这条记录29.result=obj.getString("district");30.//防止输入城市名不全,如苏州市输入为苏州,类似与模糊查询31.if(result.equals(cityName)||result.contains(cityName)){32.result=obj.getString("id");//得到ID33.return result;34.}35.}36.}37.}38.return result;39.}40.public static void main(String[] args) {41.System.out.println(getIDBycityName("香港"));42.}43.}Demo3:调用根据城市名/id查询天气1.package juheAPI;2.3.import net.sf.json.JSONObject;4.5.6.7.public class WeatherReportByCity {8.9.public static String excute(String cityName){10.String url=//此处以返回json格式数据示例,所以format=2,以根据城市名称为例,cityName传入中文11."/weather/index?cityname="+cityName+"&key=***a7558b2e0bedaa19673f74a6809ce";12.return PureNetUtil.get(url);//通过工具类获取返回数据13.}14.15.public static String GetTodayTemperatureByCity(String city) {16.String result=excute(city);17.if(result!=null){18.JSONObject obj=JSONObject.fromObject(result);19.20.result=obj.getString("resultcode");21.22.if(result!=null&&result.equals("200")){23.result=obj.getString("result");24.//此时result中数据有多个key,可以对其key进行遍历,得到对个属性25.obj=JSONObject.fromObject(result);26.//今日温度对应的key是today27.result=obj.getString("today");28.obj=JSONObject.fromObject(result);29.//今日温度对应当key是temperature30.result=obj.getString("temperature");31.return result;32.}33.}34.return result;35.}36.public static void main(String[] args) {37.System.out.println(GetTodayTemperatureByCity("苏州"));38.}39.}Demo4:调用天气种类及表示列表接口示例1.package juheAPI;2.3.import net.sf.json.JSONArray;4.import net.sf.json.JSONObject;5.6.7.8.public class GetWeatherSignAndTypeList {9.//接口地址,因为只需要传入一个固定的key为参数,所以设为常量10.private static final String URL= "/weather/uni?key=***a7558b2e0bedaa19673f74a6809ce";11.12.public static String excute(){13.return PureNetUtil.get(URL);//调用工具类获取接口数据14.}15.16.public static String getWeatherByWid(String wid) {17.String result=excute();//获取接口数据18.if(result!=null){19.JSONObject obj=JSONObject.fromObject(result);20.result=obj.getString("resultcode");21.22.if(result!=null&&result.equals("200")){23.24.result=obj.getString("result");25.JSONArray arr=JSONArray.fromObject(result);26.for(Object o:arr){//遍历数组27.obj=JSONObject.fromObject(o.toString());28.//如果遍历到需要的数据后直接返回结果,根据key(wid)得到value判断是否等于传入参数29.if(obj.getString("wid").equals(wid)){30.result=obj.getString("weather");31.return result;32.}33.}34.}35.}36.return result;37.}38.public static void main(String[] args) {39.System.out.println(getWeatherByWid("10"));40.}41.}step5:调用接口时候如果状态码不是200,仔细参考文档说明,也就是返回step3:看文档!。
基于C#的免费天气api调用代码实例
基于C#的免费天气api调用代码实例代码描述:基于C#的免费天气api调用代码实例代码平台:聚合数据using System;using System.Collections.Generic;using System.Linq;using System.Text;using ;using System.IO;using ;using System.Diagnostics;using System.Web;//----------------------------------// 全国天气预报调用示例代码-聚合数据// 在线接口文档:/docs/39// 代码中JsonObject类下载地址:/download/gcm32060 21155665/7458439//----------------------------------namespace ConsoleAPI{class Program{static void Main(string[] args){string appkey = "*******************"; //配置您申请的appkey//1.根据城市名/id查询天气string url1 = "/weather/index";var parameters1 = new Dictionary<string, string>();parameters1.Add("cityname", ""); //城市名或城市ID,如:"苏州",需要utf8 urlencodeparameters1.Add("dtype", ""); //返回数据格式:json或xml,默认jsonparameters1.Add("format", ""); //未来6天预报(future)两种返回格式,1或2,默认1parameters1.Add("key", appkey);//你申请的keystring result1 = sendPost(url1, parameters1, "get");JsonObject newObj1 = new JsonObject(result1);String errorCode1 = newObj1["error_code"].Value;if(errorCode1 == "0"){Debug.WriteLine("成功");Debug.WriteLine(newObj1);}else{//Debug.WriteLine("失败");Debug.WriteLine(newObj1["error_code"].Value+":"+newObj1 ["reason"].Value);}//2.天气种类及标识列表string url2 = "/weather/uni";var parameters2 = new Dictionary<string, string>();parameters2.Add("key", appkey);//你申请的keyparameters2.Add("dtype", ""); //返回数据的格式,xml或json,默认jsonstring result2 = sendPost(url2, parameters2, "get");JsonObject newObj2 = new JsonObject(result2);String errorCode2 = newObj2["error_code"].Value;if(errorCode2 == "0"){Debug.WriteLine("成功");Debug.WriteLine(newObj2);}else{//Debug.WriteLine("失败");Debug.WriteLine(newObj2["error_code"].Value+":"+newObj2 ["reason"].Value);}//3.根据IP查询天气string url3 = "/weather/ip";var parameters3 = new Dictionary<string, string>();parameters3.Add("ip", ""); //ip地址,如:58.215.185.154parameters3.Add("dtype", ""); //返回数据格式:json或xml,默认jsonparameters3.Add("format", ""); //未来6天预报(future)两种返回格式,1或2,默认1parameters3.Add("key", appkey);//你申请的keystring result3 = sendPost(url3, parameters3, "get");JsonObject newObj3 = new JsonObject(result3);String errorCode3 = newObj3["error_code"].Value;if(errorCode3 == "0"){Debug.WriteLine("成功");Debug.WriteLine(newObj3);}else{//Debug.WriteLine("失败");Debug.WriteLine(newObj3["error_code"].Value+":"+newObj3 ["reason"].Value);}//4.根据GPS坐标查询天气string url4 = "/weather/geo";var parameters4 = new Dictionary<string, string>();parameters4.Add("lon", ""); //经度,如:116.39277parameters4.Add("lat", ""); //纬度,如:39.933748parameters4.Add("format", ""); //未来6天预报(future)两种返回格式,1或2,默认1parameters4.Add("dtype", ""); //返回数据格式:json或xml,默认jsonparameters4.Add("key", appkey);//你申请的keystring result4 = sendPost(url4, parameters4, "get");JsonObject newObj4 = new JsonObject(result4);String errorCode4 = newObj4["error_code"].Value;if(errorCode4 == "0"){Debug.WriteLine("成功");Debug.WriteLine(newObj4);}else{//Debug.WriteLine("失败");Debug.WriteLine(newObj4["error_code"].Value+":"+newObj4 ["reason"].Value);}//5.城市天气三小时预报string url5 = "/weather/forecast3h";var parameters5 = new Dictionary<string, string>();parameters5.Add("cityname", ""); //城市名,如:"苏州&quo t;parameters5.Add("dtype", ""); //返回数据格式:json或xml,默认jsonparameters5.Add("key", appkey);//你申请的keystring result5 = sendPost(url5, parameters5, "get");JsonObject newObj5 = new JsonObject(result5);String errorCode5 = newObj5["error_code"].Value;if(errorCode5 == "0"){Debug.WriteLine("成功");Debug.WriteLine(newObj5);}else{//Debug.WriteLine("失败");Debug.WriteLine(newObj5["error_code"].Value+":"+newObj5 ["reason"].Value);}//6.支持城市列表string url6 = "/weather/citys";var parameters6 = new Dictionary<string, string>();parameters6.Add("dtype", ""); //返回数据格式:json或xml,默认jsonparameters6.Add("key", appkey);//你申请的keystring result6 = sendPost(url6, parameters6, "get");JsonObject newObj6 = new JsonObject(result6);String errorCode6 = newObj6["error_code"].Value;if(errorCode6 == "0"){Debug.WriteLine("成功");Debug.WriteLine(newObj6);}else{//Debug.WriteLine("失败");Debug.WriteLine(newObj6["error_code"].Value+":"+newObj6 ["reason"].Value);}}/// <summary>/// Http (GET/POST)/// </summary>/// <param name="url">请求URL</param>/// <param name="parameters">请求参数</param>/// <param name="method">请求方法</param>/// <returns>响应内容</returns>static string sendPost(string url, IDictionary<string, string> p arameters, string method){if(method.ToLower() == "post"){HttpWebRequest req = null;HttpWebResponse rsp = null;System.IO.Stream reqStream = null;try{req = (HttpWebRequest)WebRequest.Create(url);req.Method = method;req.KeepAlive = false;req.ProtocolVersion = HttpVersion.Version10;req.Timeout = 5000;req.ContentType = "application/x-www-form-urlencode d;charset=utf-8";byte[] postData = Encoding.UTF8.GetBytes(BuildQuery (parameters, "utf8"));reqStream = req.GetRequestStream();reqStream.Write(postData, 0, postData.Length);rsp = (HttpWebResponse)req.GetResponse();Encoding encoding = Encoding.GetEncoding(rsp.Charac terSet);return GetResponseAsString(rsp, encoding);}catch(Exception ex){return ex.Message;}finally{if(reqStream != null) reqStream.Close();if(rsp != null) rsp.Close();}}else{//创建请求HttpWebRequest request = (HttpWebRequest)WebRequest.Cre ate(url + "?"+ BuildQuery(parameters, "utf8"));//GET请求request.Method = "GET";request.ReadWriteTimeout = 5000;request.ContentType = "text/html;charset=UTF-8";HttpWebResponse response = (HttpWebResponse)request.Get Response();Stream myResponseStream = response.GetResponseStream();StreamReader myStreamReader = new StreamReader(myRespons eStream, Encoding.GetEncoding("utf-8"));//返回内容string retString = myStreamReader.ReadToEnd();return retString;}}/// <summary>/// 组装普通文本请求参数。
windapi手册
windapi手册【原创版】目录1.Windapi 手册概述2.Windapi 的功能3.Windapi 的使用方法4.Windapi 的优点与不足5.总结正文1.Windapi 手册概述Windapi 是一套提供各种气象数据查询的 API 接口,可以帮助开发者轻松获取全球范围内的气象信息。
Windapi 手册则是详细说明如何使用这些 API 接口的指南,旨在帮助开发者快速上手并高效利用这些接口。
2.Windapi 的功能Windapi 主要提供以下功能:- 查询实时气象数据,包括温度、湿度、风速、风向等;- 查询历史气象数据,支持自定义时间范围;- 查询未来气象预报,支持多天预报查询;- 查询气象站点信息,包括经纬度、海拔等。
3.Windapi 的使用方法使用 Windapi 非常简单,只需遵循以下步骤:- 注册并登录 Windapi 官网,获取 API 密钥;- 在代码中引入 Windapi 的 SDK 库;- 调用相应的 API 接口,传入参数,获取返回的气象数据。
例如,以下代码展示了如何使用 Windapi 查询北京实时气温和湿度:```pythonimport windapi# 获取 API 密钥key = "your_api_key"# 初始化 Windapi 实例w = windapi.Windapi(key)# 查询实时气象数据result = w.weather("city", "101010100") # 北京的行政区划代码为 101010100temperature = result["data"]["wendu"] # 获取实时气温humidity = result["data"]["wensh"] # 获取实时湿度print("实时气温:", temperature)print("实时湿度:", humidity)```4.Windapi 的优点与不足Windapi 的优点主要表现在数据准确性高、覆盖范围广、接口易用等方面。
开源免费天气预报接口API以及全国所有地区代码
开源免费天气预报接口API以及全国所有地区代码国家气象局提供的天气预报接口接口地址:对于第三个接口,返回信息比较全面,也是以json格式提供,格式如下{"weatherinfo": {//基本信息;"city":"北京","city_en":"beijing","date_y":"2012年2月16日","date":"","week":"星期四","fchh":"11","cityid":"101010100",//摄氏温度"temp1":"2℃~-7℃","temp2":"1℃~-7℃","temp3":"4℃~-7℃","temp4":"7℃~-5℃","temp5":"5℃~-3℃","temp6":"5℃~-2℃",//华氏温度;"tempF1":"35.6℉~19.4℉","tempF2":"33.8℉~19.4℉","tempF3":"39.2℉~19.4℉","tempF4":"44.6℉~23℉","tempF5":"41℉~26.6℉","tempF6":"41℉~28.4℉",//天气描述;"weather1":"晴","weather2":"晴","weather3":"晴","weather4":"晴转多云","weather5":"多云","weather6":"多云转阴",//天气描述图片序号"img1":"0","img2":"99","img3":"0","img4":"99","img5":"0","img6":"99","img7":"0","img8":"1","img9":"1","img10":"99","img11":"1","img12":"2","img_single":"0",//图片名称;"img_title1":"晴","img_title2":"晴","img_title3":"晴","img_title4":"晴","img_title5":"晴","img_title6":"晴","img_title7":"晴","img_title8":"多云","img_title9":"多云","img_title10":"多云","img_title11":"多云","img_title12":"阴","img_title_single":"晴",//风速描述"wind1":"北风3-4级转微风","wind2":"微风","wind3":"微风","wind4":"微风","wind5":"微风","wind6":"微风",//风速级别描述"fx1":"北风","fx2":"微风","fl1":"3-4级转小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级",//今天穿衣指数;"index":"冷","index_d":"天气冷,建议着棉衣、皮夹克加羊毛衫等冬季服装。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
全国和国际天气预报API免费接口全国2567个市县地区和国际5万个城市的7-15天天气预报、实况天气、每小时天气、灾害预警、AQI空气质量、生活指数等数据。
有免费版和收费版,区别主要在于访问次数和一些高级数据,一般开发使用免费版足够了。
百度apistore上有现成的,不需要注册:/apiworks/servicedetail/478.html官网也有免费版本,可以管理自己的key和申请优质开发者:接口文档说明:"HeWeather data service 3.0": { "status": "ok", //接口状态,参考/documents/api"basic": { //基本信息"city": "北京", //城市名称"cnty": "中国", //国家"id": "CN101010100", //城市ID,参见/documents/cn-city-list"lat": "39.904000", //城市维度"lon": "116.391000", //城市经度"update": { //更新时间"loc": "2015-07-02 14:44", //当地时间"utc": "2015-07-02 06:46:11" //UTC时间}}, "now": { //实况天气"cond": { //天气状况"code": "100", //天气状况代码"txt": "晴" //天气状况描述},"fl": "30", //体感温度"hum": "20%", //相对湿度(%)"pcpn": "0.0", //降水量(mm)"pres": "1001", //气压"tmp": "32", //温度"vis": "10", //能见度(km)"wind": { //风力风向"deg": "10", //风向(360度)"dir": "北风", //风向"sc": "3级", //风力"spd": "15" //风速(kmph)}},"aqi": { //空气质量"city": {"aqi": "30", //空气质量指数"co": "0", //一氧化碳1小时平均值(ug/m3)"no2": "10", //二氧化氮1小时平均值(ug/m3)"o3": "94", //臭氧1小时平均值(ug/m3)"pm10": "10", //PM10 1小时平均值(ug/m3)"pm25": "7", //PM2.5 1小时平均值(ug/m3)"qlty": "优", //空气质量类别"so2": "3" //二氧化硫1小时平均值(ug/m3) }}, "daily_forecast": [ //天气预报,国内7天,国际10-15天{"date": "2015-07-02", //预报日期"astro": { //天文数值"sr": "04:50", //日出时间"ss": "19:47" //日落时间},"cond": { //天气状况"code_d": "100", //白天天气状况代码,参考/documents/condition-code"code_n": "100", //夜间天气状况代码"txt_d": "晴", //白天天气状况描述"txt_n": "晴" //夜间天气状况描述},"hum": "14", //相对湿度(%)"pcpn": "0.0", //降水量(mm)"pop": "0", //降水概率"pres": "1003", //气压"tmp": { //温度"max": "34℃", //最高温度"min": "18℃" //最低温度},"vis": "10", //能见度(km)"wind": { //风力风向"deg": "339", //风向(360度)"dir": "东南风", //风向"sc": "3-4", //风力"spd": "15" //风速(kmph)}},...... //略],"hourly_forecast": [ //每小时天气预报,免费接口为每三小时预报{"date": "2015-07-02 01:00", //时间"hum": "43", //相对湿度(%)"pop": "0", //降水概率"pres": "1003", //气压"tmp": "25", //温度"wind": { //风力风向"deg": "320", //风向(360度)"dir": "西北风", //风向"sc": "微风", //风力"spd": "12" //风速(kmph)}},...... //略], "suggestion": { //生活指数"comf": { //舒适度指数"brf": "较不舒适", //简介"txt": "白天天气多云,同时会感到有些热,不很舒适。
" //详细描述},"cw": { //洗车指数"brf": "较适宜","txt": "较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。
"},"drsg": { //穿衣指数"brf": "炎热","txt": "天气炎热,建议着短衫、短裙、短裤、薄型T恤衫等清凉夏季服装。
"},"flu": { //感冒指数"brf": "少发","txt": "各项气象条件适宜,发生感冒机率较低。
但请避免长期处于空调房间中,以防感冒。
"},"sport": { //运动指数"brf": "较适宜","txt": "天气较好,户外运动请注意防晒。
推荐您进行室内运动。
"},"trav": { //旅游指数"brf": "较适宜","txt": "天气较好,温度较高,天气较热,但有微风相伴,还是比较适宜旅游的,不过外出时要注意防暑防晒哦!"},"uv": { //紫外线指数"brf": "中等","txt": "属中等强度紫外线辐射天气,外出时建议涂擦SPF高于15、PA+的防晒护肤品,戴帽子、太阳镜。
"}}}。