ASP 微信公共平台接口实现代码
<%@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
%>
上一篇: ASP中巧用Split()函数生成SQL查询语句的实例
下一篇: C#和Java有什么区别和联系
推荐阅读
-
.NET实现微信公共平台上传下载多媒体文件
-
微信公众平台 客服接口发消息的实现代码(Java接口开发)
-
微信抢红包ASP.NET代码轻松实现
-
微信公共服务平台开发(.Net 的实现)4-------语音识别
-
详解基于Node.js的微信JS-SDK后端接口实现代码
-
微信公共服务平台开发(.Net 的实现)2-------获得ACCESSTOKEN
-
微信公共服务平台开发(.Net 的实现)3-------发送文本消息
-
微信公共服务平台开发(.Net 的实现)7-------发送图文消息
-
微信公共服务平台开发(.Net 的实现)6-------自定义菜单
-
微信公共服务平台开发(.Net 的实现)1-------认证“成为开发者”