- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) > ASP >
- ASP 微信公共平臺接口實(shí)現代碼
代碼如下:
<%@Language="VBScript" CodePage="65001"%>
<%
'**********************************************
'注意事項
'ASP文件需要以UTF-8的格式保存,否則亂碼.
'以下兩行代碼是為了通過(guò)微信接口驗證的。
'response.write request("echostr")
'response.end
'**********************************************
dim signature '微信加密簽名
dim timestamp '時(shí)間戳
dim nonce '隨機數
'dim echostr '隨機字符串
dim Token
dim signaturetmp
token="ldwz"'您在后臺添寫(xiě)的 token
signature = Request("signature")
nonce = Request("nonce")
timestamp = Request("timestamp")
'**********************************************
dim ToUserName '開(kāi)發(fā)者微信號
dim FromUserName'發(fā)送方帳號(一個(gè)OpenID)
dim CreateTime '消息創(chuàng )建時(shí)間(整型)
dim MsgType 'text
dim Content '文本消息內容
set xml_dom = Server.CreateObject("MSXML2.DOMDocument")'此處根據您的實(shí)際服務(wù)器情況改寫(xiě)
xml_dom.load request
FromUserName=xml_dom.getelementsbytagname("FromUserName").item(0).text '發(fā)送者微信賬號
ToUserName=xml_dom.getelementsbytagname("ToUserName").item(0).text '接收者微信賬號。即我們的公眾平臺賬號。
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 '微信事件
if strEventType="subscribe" then '表示訂閱微信公眾平臺
strsend=gz(FromUserName,ToUserName)
ElseIf strEventType="unsubscribe" Then'取消關(guān)
strsend=gz(FromUserName,ToUserName)
end if
Else
'strsend=text(fromusername,tousername,Content)
strsend=""
end if
response.write strsend
set xml_dom=Nothing
'*************以下代碼只是為了調試作用***********
'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
'****************調試結束************************
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>不賺差價(jià)的二手車(chē)交易市場(chǎng)</Title>" &_
"<Description>聊城二手車(chē)是二手車(chē)網(wǎng)上與實(shí)體相結合的二手車(chē)市場(chǎng),以聊城二手車(chē)信息為主提供聊城及周邊地市的二手車(chē)交易信息,您可免費查看和發(fā)布二手車(chē)信息,辦理二手車(chē)相關(guān)業(yè)務(wù)。" &_
"</Description>" &_
"<PicUrl><![CDATA[http://www.0635che.com/images/wxlogo.jpg]]></PicUrl>" &_
"<Url><![CDATA[http://www.0635che.com/]]></Url>" &_
"</item>" &_
"<item>" &_
"<Title><![CDATA[查看二手車(chē)信息]]></Title>" &_
"<Discription><![CDATA[全部二手車(chē)信息]]></Discription>" &_
"<PicUrl><![CDATA[http://www.0635che.com/images/wxche.jpg]]></PicUrl>" &_
"<Url><![CDATA[http://www.0635che.com/ershouche]]></Url>" &_
"</item>" &_
"<item>" &_
"<Title><![CDATA[二手車(chē)過(guò)戶(hù)手續]]></Title>" &_
"<Discription><![CDATA[二手車(chē)過(guò)戶(hù)過(guò)戶(hù)手續]]></Discription>" &_
"<PicUrl><![CDATA[http://www.0635che.com/images/wxgh.jpg]]></PicUrl>" &_
"<Url><![CDATA[http://www.0635che.com/guohu]]></Url>" &_
"</item>" &_
"<item>" &_
"<Title><![CDATA[什么是不賺差價(jià)]]></Title>" &_
"<Discription><![CDATA[電子商務(wù)]]></Discription>" &_
"<PicUrl><![CDATA[http://www.0635che.com/images/wxxw.jpg]]></PicUrl>" &_
"<Url><![CDATA[http://www.0635che.com/service]]></Url>" &_
"</item>" &_
"<item>" &_
"<Title><![CDATA[聯(lián)系我們]]></Title>" &_
"<Discription><![CDATA[聯(lián)系我們]]></Discription>" &_
"<PicUrl><![CDATA[http://www.0635che.com/images/wxlx.jpg]]></PicUrl>" &_
"<Url><![CDATA[http://www.0635che.com/]]></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
%>
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站