天气信息来源:中国天气网【weather.com.cn】
根据QQ[http://fw.qq.com:80/ipaddress]得到ip地址和所在城市信息,
然后调用weather.com.cn网站的xml得到城市代码,就可以得到JSON格式的天气信息
setWeather函数可以自行修改生成您想要的天气信息格式
效果如下:
Weather.asp
<%codepage=936%>
<%
'***********************************************************
' 文件名: 免费天气插件asp版本,仅适用于中国用户
' 版本: mmWeather1.0
' 作者: 走过四季
' 电子邮件: maomaoysq@sohu.com
' 日期: 2010年01月14日
' 功能: 根据用户的ip地址自动获取所在城市的天气信息
' 声明:
' 本代码可以自由使用,但请保留此版权声明信息
' 如果您对本代码进行修改增强,
' 请发送一份给俺。
'**********************************************************
dim cityid,city1,city2,tmpHtml,tmpArr,tLevel,weaXML,weaHTML
tLevel = 0
weaXML = "http://service.weather.com.cn/plugin/"
weaHTML = "http://m.weather.com.cn/data/"
cityid = Trim(Request.Cookies("wea_cityid"))
if cityid = "" then
tmpHtml = GetUrlBody("http://fw.qq.com:80/ipaddress","gb2312")
tmpHtml = BytesToBstr(tmpHtml,"gb2312")
if tmpHtml = "" then
Response.Write("Error:Can't get ip address from qq.com.")
end if
tmpArr = Split(tmpHtml,",")
Response.Cookies("wea_cityip") = tmpArr(0)
city1 = tmpArr(2)
city2 = tmpArr(3)
city1 = Replace(city1,"省","")
city1 = Replace(city1,"市","")
city1 = Replace(city1,"""","")
city2 = Replace(city2,");","")
if Trim(city2) = "" then
city2 = city1
else
city2 = Replace(city2,"市","")
city2 = Replace(city2,"自治区","")
end if
city2 = Replace(city2,"""","")
'call getCityCode(city2)
if cityid = "" then
call getLocalCity("data/city.xml",0)
end if
else
call getWeather(cityid)
end if
function getLocalCity(ByVal tUrl,ByVal tLevel)
dim iPos,iPos1,cid,cArr
tmpHtml = GetUrlBody(weaXML & tUrl,"")
iPos = InStr(tmpHtml,city1)
iPos1 = InStr(tmpHtml,city2)
if tLevel<3 then
if iPos>0 then
tmpHtml = Left(tmpHtml,iPos-1)
iPos = InStrRev(tmpHtml,",")
tmpHtml = Right(tmpHtml,len(tmpHtml)-iPos)
cid = Replace(tmpHtml,"|",""):
elseif iPos1>0 then
tmpHtml = Left(tmpHtml,iPos1-1)
iPos = InStrRev(tmpHtml,",")
tmpHtml = Right(tmpHtml,len(tmpHtml)-iPos)
cid = Replace(tmpHtml,"|",""):
end if
call getLocalCity("data/city" & cid & ".xml",tLevel+1)
else
cid = Split(tmpHtml,"|")(1)
call getWeather(cid)
end if
end function
function getWeather(ByVal cid)
Response.Cookies("wea_cityid") = cid
tmpHtml = GetUrlBody(weaHTML & cid & ".html","")
if tmpHtml="" then
Response.Write("Error:Nothing is from "&weaHTML & cid & ".html")
else
Response.Write("<script language=javascript>"& vbCrLf &"function window.onload(){var oJson = "& tmpHtml & vbCrLf)
Response.Write("setWeather(oJson);}"& vbCrLf &"</script>")
end if
end function
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
Public Function GetUrlBody(ByVal URL,ByVal CharSet)
On Error Resume Next
Set Http = Server.CreateObject("MICROSOFT.XMLHTTP")
Http.Open "GET", URL, False
Http.Send
If Http.Readystate = 4 Then
If Http.Status = 200 Then
if CharSet="gb2312" then
GetUrlBody = Http.responseBody
else
GetUrlBody = Http.responseText
end if
End If
End If
End Function
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>中国天气网-天气预报</title>
</head>
<body>
<div class="Weather">
<span id="city"></span> <span id="temp1"></span> <span id="wd1"></span>
</div>
</body>
</html>
<script language=javascript>
function setWeather(objJson)
{
var imgHtml = "";
var cityname = objJson.weatherinfo.city; //上海
var id = objJson.weatherinfo.cityid; //101020100
var cityinfo1 = objJson.weatherinfo.weather1; //晴转多云
var wd1 = objJson.weatherinfo.wind1; //北风3-4级
var fl1 = objJson.weatherinfo.fl1; //3-4级
var temp1 = objJson.weatherinfo.temp1; //4℃~-1℃
//注释里面为更详细的信息,您可以根据自己需要使用
/*var cityinfo2=objJson.weatherinfo.weather2;
var wd2=objJson.weatherinfo.wind2;
var fl2=objJson.weatherinfo.fl2;
var temp2=objJson.weatherinfo.temp2;
var img1=objJson.weatherinfo.img1;
var img2=objJson.weatherinfo.img2;
var img3=objJson.weatherinfo.img3;
var img4=objJson.weatherinfo.img4;
var index=objJson.weatherinfo.index;
var index_d=objJson.weatherinfo.index_d;
var index_xc=objJson.weatherinfo.index_xc;
var index_uv=objJson.weatherinfo.index_uv;
var date=objJson.weatherinfo.date;
var date_y=objJson.weatherinfo.date_y;
var imgtitle1=objJson.weatherinfo.img_title1;
var imgtitle2=objJson.weatherinfo.img_title2;
var imgsingle=objJson.weatherinfo.img_single;
var imgtitlesingle=objJson.weatherinfo.img_title_single;
*/
document.all.city.innerHTML = cityname
document.all.temp1.innerHTML = cityinfo1
document.all.wd1.innerHTML = wd1 + fl1
}
</script>
- 大小: 9.9 KB
分享到:
- 2010-01-14 22:57
- 浏览 1643
- 评论(0)
- 论坛回复 / 浏览 (0 / 4650)
- 查看更多
相关推荐
在这个场景中,"asp.net通用天气预报插件"是一款专为ASP.NET开发者设计的组件,它使得在网站中集成实时天气预报功能变得简单而便捷。 该插件的核心功能可能包括以下几点: 1. **数据获取**:插件可能通过与各大...
描述中提到的“很完整的天气插件源码”,暗示我们这个代码包包含了一个自定义的ASP.NET控件,可能是通过集成外部天气API来获取和展示天气数据。这样的插件对于网站设计者来说非常有用,因为它们能够为用户提供实时的...
ASP源码,压缩包解压密码:www.cqlsoft.com
此天气预报代码使用嵌入式框架为最佳显示方式。 直接获取 天气网 数据,本人提供的代码仅供学习研究,如...修改tianqi.asp 第17行:call getWeather(101340101) 括号中的城市代码即可使用。 文件中有具体说明。
2.每次打开调用页面的时候并不获取天气信息,所以天气插件不会影响到您网站的速度。 3.每10--30分钟在net后台自动获取天气信息一次,不存在手动更新,很方便。 4.没有任何外连接。完全展示大站风采。 5.样式有...
ASP版天气预报查询插件 1、将下载下来的天气接口接程序文件:weather.asp上传至你的空间,随便放在哪个目录,就可以了。 2、在您需要使用的地方直接调用你上传的:weather.asp文件即可,调用内容为:...
【天气预报插件for 7.0 sp2 Tianqi7.0】是一款专为7.0 sp2版本设计的插件,主要用于在论坛环境中提供实时天气预报服务,增强用户互动体验,让论坛用户能够轻松获取所在地的天气信息,提高用户粘性。 这款插件的核心...
ASP天气预报插件源码 v1.0是一个用于在网站上集成实时天气预报功能的ASP(Active Server Pages)开发实例。这个插件可以帮助网站开发者轻松地在网页上展示全球各地的天气信息,提升用户体验,同时也增加了网站的实用...
总的来说,"基于ASP的天气预报插件源码 v1.0.zip"是一个利用ASP技术实现的动态插件,它展示了如何在服务器端集成天气API,获取并显示实时天气信息。这个源码对于学习ASP编程和理解Web服务集成是一个宝贵的实例。
此天气预报代码使用嵌入式框架为最佳显示方式。 直接获取 天气网 数据,本人提供的代码仅供学习研究,如...修改tianqi.asp 第17行:call getWeather(101340101) 括号中的城市代码即可使用。 文件中有具体说明。
【标题】"最新天气预报插件for leadbbs3.14" 描述了这是一个针对Leadbbs3.14版本的更新版天气预报插件。Leadbbs是一款流行的开源论坛软件,它允许用户们在论坛上进行互动讨论。这款插件的更新可能包括了性能优化、新...
ASP源码—天气预报插件源码 v1.0.zip
"源代码-天气预报插件源码 v1.0.zip" 这个标题表明我们处理的是一个关于天气预报插件的源代码文件包,版本为v1.0。通常,源代码是程序员用编程语言编写的原始指令集合,用于创建软件、应用或插件。"天气预报插件"是...
"tianqi2.asp"和"tianqi.asp"这两个文件是插件的主要执行程序,它们负责从天气数据接口获取实时的气象信息,并在论坛页面上展示。这些信息可能包括温度、湿度、风向、风力、空气质量等,帮助用户了解各地的天气状况...
'' 特点: '' 1.可查看全国100个城市地区24、48、72小时天气 '' 2.调用方便:<script src=getTianQi.asp></script><br>'' 3.当天气服务器当机时,不会影响页面其它部分运行
《jQuery 浮云天气插件 (jQuery Clouds Weather Plus) v1.0——打造互动式天气预报体验》 在Web开发领域,jQuery以其简洁、易用的API深受开发者喜爱,而jQuery Clouds Weather Plus v1.0正是这样一个利用jQuery功能...
插入插件位置 MN("Plug-ins/xingzuo/index.asp","星座运程"); MN2(4,"Boards.asp","休闲娱乐") 中添加: MN("Plug-ins/game-016/index.asp&...
跨域得到天气预报信息,然后利用 mui+echart+天气预报
2. index.ASP:这是论坛的主页面,可能包含天气插件的入口或者调用代码。 3. fjtq.ASP:根据命名习惯,这可能对应福建地区的天气查询页面。 4. 说明.htm:这是一个HTML格式的帮助文档,详细解释了插件的安装、使用...
ASP.NET MVC框架下的Webpart/Portlet插件开发是一种构建动态、可定制Web界面的方法。Webparts(或Portlets)是独立的、可重用的组件,它们可以被用户根据个人喜好在页面上自由排列和配置。在ASP.NET MVC中实现这一...