<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../conn/conn2.asp" -->
<!--#include file="sha1.asp"-->
<%
D_domain=split(split("http://"&Request.ServerVariables("HTTP_HOST")&Request.ServerVariables("URL"),"http://")(1),"/weixin")(0)
sql="Select * from config"
		set rs=Server.CreateObject("ADODB.RecordSet")
		rs.open sql,conn,1,1
		if not rs.eof then
		C_title=rs("C_title")
		C_wtoken=rs("C_wtoken")
		end if
		rs.close
		set rs=nothing

	signature = Request("signature")
	nonce = Request("nonce")
	timestamp = Request("timestamp")
	echostr=request("echostr")

If echostr<>"" then
		
		Myarray=Sort(Array(C_wtoken,timestamp,nonce))
		For M=0 To Ubound(Myarray)
			str=str&Myarray(M)
		Next
		if signature=Lcase(sha1(str)) then
			response.Write echostr
			response.End()
		end if
End if

if signature<>"" and echostr="" then

set xml_dom = Server.CreateObject("MSXML2.DOMDocument")'此处根据您的实际服务器情况改写
 
xml_dom.load request
 
FromUserName=xml_dom.getelementsbytagname("FromUserName").item(0).text '发送者微信账号
ToUserName=xml_dom.getelementsbytagname("ToUserName").item(0).text '接收者微信账号。即我们的公众平台账号。
MsgType=xml_dom.getelementsbytagname("MsgType").item(0).text
 
 
if MsgType="event" then
 
        strEventType=xml_dom.getelementsbytagname("Event").item(0).text '微信事件
        if strEventType="subscribe" then '表示订阅微信公众平台
        strsend=gz(FromUserName,ToUserName)
        end if
else
 
if MsgType="text" then
Content=xml_dom.getelementsbytagname("Content").item(0).text
strsend=text(fromusername,tousername,Content)
end if
end if

response.write strsend
set xml_dom=Nothing
end if
 

function gz(fromusername,tousername)

sql="Select * from slide order by S_id desc"
		set rs=Server.CreateObject("ADODB.RecordSet")
		rs.open sql,conn,1,1
		if not rs.eof then
		S_pic=rs("S_pic")
		end if
		rs.close
		set rs=nothing
sql="select count(*) as U_count from menu1 where U_sub=0"
set rs=Server.CreateObject("ADODB.RecordSet")
		rs.open sql,conn,1,1
		U_count=rs("U_count")
		rs.close
set rs=nothing
if U_count>8 then
U_count=8
end if
gz="<xml><ToUserName><![CDATA["&fromusername&"]]></ToUserName><FromUserName><![CDATA["&tousername&"]]></FromUserName><CreateTime>"&now&"</CreateTime><MsgType>news</MsgType><ArticleCount>"&U_count&"</ArticleCount><Articles>"

gz=gz&"<item><Title>"&C_title&"</Title><Description>"&C_title&"</Description><PicUrl><![CDATA[http://"&D_domain&"/"&S_pic&"]]></PicUrl><Url><![CDATA[http://"&D_domain&"]]></Url></item>"

Set rs= Server.CreateObject("ADODB.RecordSet")
sql="select top "&U_count-1&" * from menu1 where U_sub=0 and not U_type='slideshow' order by U_order"
rs.open sql,conn,1,1
if not rs.eof then
Do while Not rs.eof
if rs("U_type")<>"sub" and rs("U_type")<>"link" then
link=rs("U_type")&".asp?id="&rs("U_typeid")
else
link=rs("U_type")&".asp?id="&rs("U_id")
end if
gz=gz&"<item><Title>"&rs("U_title")&"</Title><Description>"&rs("U_title")&"</Description><PicUrl><![CDATA[http://"&D_domain&"/media/"&rs("U_icon")&"]]></PicUrl><Url><![CDATA[http://"&D_domain&"/wap/"&link&"]]></Url></item>"
rs.movenext
		loop
gz=gz&"</Articles><FuncFlag>1</FuncFlag></xml>"
	end if
set rs=nothing
 
end function
 

function text(fromusername,tousername,fromstr)

returnstr="感谢您的留言，等待人工客户为您回复。"

text="<xml>" &_
 
"<ToUserName><![CDATA["&fromusername&"]]></ToUserName>" &_
 
"<FromUserName><![CDATA["&tousername&"]]></FromUserName>" &_
 
"<CreateTime>"&now&"</CreateTime>" &_
 
"<MsgType><![CDATA[text]]></MsgType>" &_
 
"<Content><![CDATA[" & returnstr & "]]></Content>" &_
 
"<FuncFlag>0<FuncFlag>" &_
 
"</xml>"
 
end function
Function Sort(ary)
		Dim KeepChecking,I,FirstValue,SecondValue
		KeepChecking = TRUE 
		Do Until KeepChecking = FALSE 
		KeepChecking = FALSE 
		For I = 0 to UBound(ary) 
		If I = UBound(ary) Then Exit For 
		If ary(I) > ary(I+1) Then 
		FirstValue = ary(I) 
		SecondValue = ary(I+1) 
		ary(I) = SecondValue 
		ary(I+1) = FirstValue 
		KeepChecking = TRUE 
		End If 
		Next 
		Loop 
		Sort = ary 
	End Function
	
%>
