联系客服: iP138.com客服 iP138客服 |

天气预报接口
北京市天气实况

3℃ 晴

风向风速:西北风2级

相对湿度:27%

空气质量:27优

  • API接口QQ交流群:177096428   iP138 api接口
  • 数据修正QQ处理群:94181690    iP138数据修正

天气预报查询接口支持HTTPS(赠送1000次)

简介:获取全国今天天气及最近7天的天气预报情况

已连接应用数:1680

C#(.net)调用天气查询接口示例:

方法一

                                    using System;
                                    using System.Collections.Generic;
                                    using System.Web;
                                    using System.Net;

                                    public class IP138
                                    {
                                        public static string GetWeatherData(string token, string code, string type = "1")
                                        {
                                            string url = string.Format("https://api.ip138.com/weather/?code={0}&type={1}&token={2}", code, type, token);
                                            using (WebClient client = new WebClient())
                                            {
                                                return client.DownloadString(url);
                                            }
                                        }
                                    }

                                    string data = IP138.GetWeatherData("00d5cb1fac5dc5cbfe2ff218222a2dfd33", 110111);
                                    Console.WriteLine(data);
                                    Response.Write(data);
                                    

方法二

                                    <% 
                                    string code = 110111;
                                    string strMid = "777";    //用户中心查看您的mid
                                    string oid = "777";   //用户中心查看您的oid
                                    string token = "00d5cb1fac5dc5cbfe2ff218222a2dfd33";    //用户中心查看您的token
                                    string url = "https://api.ip138.com/weather/?";
                                    string str = "code=" + code + "&token=" + token;
                                    string sign = FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
                                    %>
                                    <script type="text/javascript">
                                    function find(str){alert(str.data);}
                                    </script>
                                    <script type="text/javascript" src="<%= url+"code="+code+"&callback=find&mid="+strMid+"&oid="+oid+"&sign="+sign %>"></script>