ASP 微信公用平台介面實現代碼_應用技巧

來源:互聯網
上載者:User

複製代碼 代碼如下:

<%@Language="VBScript" CodePage="65001"%>
<%
'**********************************************
'注意事項
'ASP檔案需要以UTF-8的格式儲存,否則亂碼.
'以下兩行代碼是為了通過微信介面驗證的。
'response.write request("echostr")
'response.end
'**********************************************
dim signature        '微信加密簽名
dim timestamp        '時間戳記
dim nonce                '隨機數
'dim echostr                '隨機字串
dim Token
dim signaturetmp
token="ldwz"'您在後台添寫的 token

signature = Request("signature")
nonce = Request("nonce")
timestamp = Request("timestamp")
'**********************************************
dim ToUserName        '開發人員微訊號
dim FromUserName'發送方帳號(一個OpenID)
dim CreateTime        '訊息建立時間(整型)
dim MsgType                'text
dim Content                '簡訊內容

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="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'取消關
                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>不賺價差的二手車交易市場</Title>" &_
"<Description>聊城二手車是二手車網上與實體相結合的二手車市場,以聊城二手車資訊為主提供聊城及周邊地市的二手車交易資訊,您可免費查看和發布二手車資訊,辦理二手車相關業務。" &_
"</Description>" &_
"<PicUrl><![CDATA[yun_qi_img/wxlogo.jpg]]></PicUrl>" &_
"<Url><![CDATA[http://www.0635che.com/]]></Url>" &_
"</item>" &_
"<item>" &_
"<Title><![CDATA[查看二手車資訊]]></Title>" &_
"<Discription><![CDATA[全部二手車資訊]]></Discription>" &_
"<PicUrl><![CDATA[yun_qi_img/wxche.jpg]]></PicUrl>" &_
"<Url><![CDATA[http://www.0635che.com/ershouche]]></Url>" &_
"</item>" &_
"<item>" &_
"<Title><![CDATA[二手車過戶手續]]></Title>" &_
"<Discription><![CDATA[二手車過戶過戶手續]]></Discription>" &_
"<PicUrl><![CDATA[yun_qi_img/wxgh.jpg]]></PicUrl>" &_
"<Url><![CDATA[http://www.0635che.com/guohu]]></Url>" &_
"</item>" &_
"<item>" &_
"<Title><![CDATA[什麼是不賺價差]]></Title>" &_
"<Discription><![CDATA[電子商務]]></Discription>" &_
"<PicUrl><![CDATA[yun_qi_img/wxxw.jpg]]></PicUrl>" &_
"<Url><![CDATA[http://www.0635che.com/service]]></Url>" &_
"</item>" &_
"<item>" &_
"<Title><![CDATA[聯絡我們]]></Title>" &_
"<Discription><![CDATA[聯絡我們]]></Discription>" &_
"<PicUrl><![CDATA[yun_qi_img/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
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.