![]() 2.7℃ 晴 |
|
风向风速:东北风2级 |
|
相对湿度:43% |
|
空气质量:66良 |
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>