The ASP WeChat public platform interface implementation code seen by bluedidea, friends in need can refer to it.
Copy the code code as follows:
<%@Language="VBScript" CodePage="65001"%>
<%
'**********************************************
'Notes
'ASP files need to be saved in UTF-8 format, otherwise they will be garbled.
'The following two lines of code are for verification through the WeChat interface.
'response.write request("echostr")
'response.end
'**********************************************
dim signature 'WeChat encrypted signature
dim timestamp 'timestamp
dim nonce 'random number
'dim echostr 'random string
dimToken
dimsignaturetmp
token="ldwz"'the token you added in the background
signature = Request("signature")
nonce = Request("nonce")
timestamp = Request("timestamp")
'**********************************************
dim ToUserName 'Developer WeChat account
dim FromUserName'sender account (an OpenID)
dim CreateTime 'Message creation time (integer)
dim MsgType 'text
dim Content 'Text message content
set xml_dom = Server.CreateObject("MSXML2.DOMDocument")'This is rewritten according to your actual server situation
xml_dom.load request
FromUserName=xml_dom.getelementsbytagname("FromUserName").item(0).text 'Sender's WeChat account
ToUserName=xml_dom.getelementsbytagname("ToUserName").item(0).text 'Receiver's WeChat account. That is our public platform account.
MsgType=xml_dom.getelementsbytagname("MsgType").item(0).text
if MsgType="text" then
Content=xml_dom.getelementsbytagname("Content").item(0).text
end if
'dim mingling
'mingling=replace(content,chr(13),"")
'mingling=trim(replace(mingling,chr(10),""))
if (MsgType="event") then
strEventType=xml_dom.getelementsbytagname("Event").item(0).text 'WeChat event
if strEventType="subscribe" then 'Indicates subscribing to WeChat public platform
strsend=gz(FromUserName,ToUserName)
ElseIf strEventType="unsubscribe" Then'Cancel close
strsend=gz(FromUserName,ToUserName)
end if
Else
'strsend=text(fromusername,tousername,Content)
strsend=""
end if
response.write strsend
set xml_dom=Nothing
'******************The following code is for debugging only**********
'filepath=server.mappath(".")&"/wx.txt"
'Set fso = Server.CreateObject("Scripting.FileSystemObject")
'set fopen=fso.OpenTextFile(filepath, 8,true)
'fopen.writeline(strsend)
'set fso=nothing
'set fopen=Nothing
'******************Debugging End************************
function gz(fromusername,tousername)
gz="<xml>" &_
"<ToUserName><![CDATA["&fromusername&"]]></ToUserName>" &_
"<FromUserName><![CDATA["&tousername&"]]></FromUserName>" &_
"<CreateTime>"&now&"</CreateTime>" &_
"<MsgType>news</MsgType>" &_
"<ArticleCount>5</ArticleCount>" &_
"<Articles>" &_
"<item>" &_
"<Title>A second-hand car trading market without profit margin</Title>" &_
"<Description>Liaocheng second-hand car is a second-hand car market that combines online and physical second-hand cars. It mainly provides second-hand car transaction information in Liaocheng and surrounding cities with Liaocheng second-hand car information. You can view and publish second-hand car information for free, and handle Used car related business.
"</Description>" &_
"<PicUrl><![CDATA[]]></PicUrl>" &_
"<Url><![CDATA[]]></Url>" &_
"</item>" &_
"<item>" &_
"<Title><![CDATA[View used car information]]></Title>" &_
"<Discription><![CDATA[All used car information]]></Discription>" &_
"<PicUrl><![CDATA[]]></PicUrl>" &_
"<Url><![CDATA[]]></Url>" &_
"</item>" &_
"<item>" &_
"<Title><![CDATA[Second-hand car transfer procedures]]></Title>" &_
"<Discription><![CDATA[Second-hand car transfer procedures]]></Discription>" &_
"<PicUrl><![CDATA[]]></PicUrl>" &_
"<Url><![CDATA[]]></Url>" &_
"</item>" &_
"<item>" &_
"<Title><![CDATA[What is not earning the difference]]></Title>" &_
"<Discription><![CDATA[e-commerce]]></Discription>" &_
"<PicUrl><![CDATA[]]></PicUrl>" &_
"<Url><![CDATA[]]></Url>" &_
"</item>" &_
"<item>" &_
"<Title><![CDATA[Contact Us]]></Title>" &_
"<Discription><![CDATA[Contact Us]]></Discription>" &_
"<PicUrl><![CDATA[]]></PicUrl>" &_
"<Url><![CDATA[]]></Url>" &_
"</item>" &_
"</Articles>" &_
"<FuncFlag>1</FuncFlag>" &_
"</xml> "
end function
function text(fromusername,tousername,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
%>