根据微信http://mp.weixin.qq.com/wiki/index.php 接收消息提供的接口,微信提供多种消息回复接口,本人开发调试过程一一封装,下边是封装好的方法,希望对大家有帮助。
这里做个广告,为了更快了解微信本来新建了一个QQ群,群名称是【微信开发技术交流:389075177】,专门用于微信开发和交流,欢迎正在研究微信的童鞋一起加入,一起学习,一起进步!
‘回复文本消息
function text(fromusername,tousername,returnstr)
text="<xml>" &_
"<ToUserName><![CDATA["&fromusername&"]]></ToUserName>" &_
"<FromUserName><![CDATA["&tousername&"]]></FromUserName>" &_
"<CreateTime>"&now&"</CreateTime>" &_
"<MsgType><![CDATA[text]]></MsgType>" &_
"<Content><![CDATA[" & Replace(returnstr,"<br>",VBCRLF) & "]]></Content>" &_
"<FuncFlag>0<FuncFlag>" &_
"</xml>"
end Function
‘回复图片消息
function image(fromusername,tousername,media_id)
image="<xml>" &_
"<ToUserName><![CDATA["&fromusername&"]]></ToUserName>" &_
"<FromUserName><![CDATA["&tousername&"]]></FromUserName>" &_
"<CreateTime>"&now&"</CreateTime>" &_
"<MsgType><![CDATA[image]]></MsgType>" &_
"<Image>" &_
"<MediaId><![CDATA["&media_id&"]]></MediaId>>" &_
"</Image>" &_
"</xml>"
end Function
‘回复语音消息
function voice(fromusername,tousername,media_id)
voice="<xml>" &_
"<ToUserName><![CDATA["&fromusername&"]]></ToUserName>" &_
"<FromUserName><![CDATA["&tousername&"]]></FromUserName>" &_
"<CreateTime>"&now&"</CreateTime>" &_
"<MsgType><![CDATA[voice]]></MsgType>" &_
"<Voice>" &_
"<MediaId><![CDATA["&media_id&"]]></MediaId>>" &_
"</Voice>" &_
"</xml>"
end Function
‘回复视频消息
function video(fromusername,tousername,media_id,title,description)
video="<xml>" &_
"<ToUserName><![CDATA["&fromusername&"]]></ToUserName>" &_
"<FromUserName><![CDATA["&tousername&"]]></FromUserName>" &_
"<CreateTime>"&now&"</CreateTime>" &_
"<MsgType><![CDATA[video]]></MsgType>" &_
"<Video>" &_
"<MediaId><![CDATA["&media_id&"]]></MediaId>" &_
"<Title><![CDATA["&title&"]]></Title>" &_
"<Description><![CDATA["&description&"]]></Description>" &_
"</Video>" &_
"</xml>"
end Function
‘回复音乐消息
function music(fromusername,tousername,title,description,musicurl,hqmusicurl,media_id)
music="<xml>" &_
"<ToUserName><![CDATA["&fromusername&"]]></ToUserName>" &_
"<FromUserName><![CDATA["&tousername&"]]></FromUserName>" &_
"<CreateTime>"&now&"</CreateTime>" &_
"<MsgType><![CDATA[music]]></MsgType>" &_
"<Music>" &_
"<Title><![CDATA["&title&"]]></Title>" &_
"<Description><![CDATA["&description&"]]></Description>" &_
"<MusicUrl><![CDATA["&musicurl&"]]></MusicUrl>" &_
"<HQMusicUrl><![CDATA["&hqmusicurl&"]]></HQMusicUrl>" &_
"<MediaId><![CDATA["&media_id&"]]></MediaId>>" &_
"</Music>" &_
"</xml>"
end Function
‘回复图文消息
function news(fromusername,tousername,Articles)
news="<xml>" &_
"<ToUserName><![CDATA["&fromusername&"]]></ToUserName>" &_
"<FromUserName><![CDATA["&tousername&"]]></FromUserName>" &_
"<CreateTime>"&now&"</CreateTime>" &_
"<MsgType><![CDATA[news]]></MsgType>"
Dim rs,sql
set rs=server.CreateObject("adodb.recordset")
sql="select * from WeiXin_NewsItem where Articles="&Articles
rs.open sql,conn,1,3
news=news&"<ArticleCount>"&rs.recordcount&"</ArticleCount>"
news=news&"<Articles>"
Do While Not rs.eof
news=news&"<item>"
news=news&"<Title><![CDATA["&rs("Title")&"]]></Title>"
news=news&"<PicUrl><![CDATA["&rs("PicUrl")&"]]></PicUrl>"
news=news&"<Url><![CDATA["&rs("Url")&"]]></Url>"
news=news&"</item>"
rs.movenext
Loop
rs.close
Set rs=nothing
news=news&"</Articles>"
news=news&"</xml>"
End function