欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP 微信公共平台接口实现代码

程序员文章站 2022-05-03 16:34:05
复制代码 代码如下:<%@language="vbscript" codepage="65001"%><%'***********************...

复制代码 代码如下:

<%@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[http://www.0635che.com/images/wxlogo.jpg]]></picurl>" &_
"<url><![cdata[http://www.0635che.com/]]></url>" &_
"</item>" &_
"<item>" &_
"<title><![cdata[查看二手车信息]]></title>" &_
"<discription><![cdata[全部二手车信息]]></discription>" &_
"<picurl><![cdata[http://www.0635che.com/images/wxche.jpg]]></picurl>" &_
"<url><![cdata[http://www.0635che.com/ershouche]]></url>" &_
"</item>" &_
"<item>" &_
"<title><![cdata[二手车过户手续]]></title>" &_
"<discription><![cdata[二手车过户过户手续]]></discription>" &_
"<picurl><![cdata[http://www.0635che.com/images/wxgh.jpg]]></picurl>" &_
"<url><![cdata[http://www.0635che.com/guohu]]></url>" &_
"</item>" &_
"<item>" &_
"<title><![cdata[什么是不赚差价]]></title>" &_
"<discription><![cdata[电子商务]]></discription>" &_
"<picurl><![cdata[http://www.0635che.com/images/wxxw.jpg]]></picurl>" &_
"<url><![cdata[http://www.0635che.com/service]]></url>" &_
"</item>" &_
"<item>" &_
"<title><![cdata[联系我们]]></title>" &_
"<discription><![cdata[联系我们]]></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
%>