微信公众号消息与事件处理机制

一:授权事件接收URL

1:微信服务器每隔10分钟定时推送component_verify_ticket。

第三方平台方在收到ticket推送后也需进行解密

{ComponentVerifyTicket=ticket@@@fxUU8P4_ip5B-S1sBL2SHmfA24haZRIUR8QIs0jLRXNfg1iBm4Lmv_h3T6Pb3KoXhNm-MspBFXr1cpN7nMzWDA,
CreateTime=1453311619, 
AppId=wx630d7795f554888e, 
InfoType=component_verify_ticket}

将ticket存储到redis缓存中备用。(获取component_access_token的时候会用到)

2:取消授权:
{CreateTime=1456983869,
 AppId=wx630d7795f554888e,
 AuthorizerAppid=wx136a04a96a5a4315,
 InfoType=unauthorized}

update公众号的授权状态status = 0(微信公众号一件授权绑定的时候,设置状态status = 1)

二:公众号消息与事件接收URL

1:全网发布测试程序
2:粉丝留言

(1)文本消息MsgType=text

<xml><ToUserName><![CDATA[gh_55a07f02b729]]></ToUserName>
<FromUserName><![CDATA[oPL3EwABb3O9FlyYqrEq8s60XQHM]]></FromUserName>
<CreateTime>1453324217</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[ 80507050055]]></Content>
<MsgId>6241979982901678088</MsgId>
</xml>

解密后:

{"ToUserName":"gh_55a07f02b729",
"FromUserName":"oPL3EwABb3O9FlyYqrEq8s60XQHM",
"CreateTime":"1453324217",
"MsgType":"text",
"MsgId":"6241979982901678088",
"Content":" 80507050055"}

(2)图片消息MsgType=image

<xml><ToUserName><![CDATA[gh_75bd42c76810]]></ToUserName>
<FromUserName><![CDATA[oL2tEsy80dteCTC3s2N-oJ29FzvQ]]></FromUserName>
<CreateTime>1458022782</CreateTime>
<MsgType><![CDATA[image]]></MsgType>
<PicUrl><![CDATA[http://mmbiz.qpic.cn/mmbiz/RFKb8DPbIRaHLYwvIP42gmxCn9BibXIibAWurGWNxhVNIv9QPiaTgSjoURLvEhEmibyUmpn3Iejd2iarqFxNEibiazicjA/0]]></PicUrl>
<MsgId>6262160165914921281</MsgId>
<MediaId><![CDATA[N140xMpjGKediJdR3YnDl18lkhrGms3nMjw2_5N3IL_bgssG-EHwLVLK3_YrrjY-]]></MediaId>
</xml>

解密后:

{"ToUserName":"gh_75bd42c76810",
"FromUserName":"oL2tEsy80dteCTC3s2N-oJ29FzvQ",
"CreateTime":"1458022782",
"MsgType":"image",
"MsgId":"6262160165914921281",
"PicUrl":"http://mmbiz.qpic.cn/mmbiz/RFKb8DPbIRaHLYwvIP42gmxCn9BibXIibAWurGWNxhVNIv9QPiaTgSjoURLvEhEmibyUmpn3Iejd2iarqFxNEibiazicjA/0",
"MediaId":"N140xMpjGKediJdR3YnDl18lkhrGms3nMjw2_5N3IL_bgssG-EHwLVLK3_YrrjY-"}

(3)语音MsgType=voice

(4)视频MsgType=shortvideo

3:微信菜单点击事件Event=CLICK
<xml><ToUserName><![CDATA[gh_8564206f6175]]></ToUserName>
<FromUserName><![CDATA[oll5DuPVHrhwgXiL6O8_UjxWx9EQ]]></FromUserName>
<CreateTime>1453312109</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[CLICK]]></Event>
<EventKey><![CDATA[63_82cceb50702b4ebba1ce7d823f7ec6c5]]></EventKey>
</xml>

解密后:

{"ToUserName":"gh_8564206f6175",
"FromUserName":"oll5DuPVHrhwgXiL6O8_UjxWx9EQ",
"CreateTime":"1453312109",
"MsgType":"event",
"Event":"CLICK",
"EventKey":"63_82cceb50702b4ebba1ce7d823f7ec6c5"}
4:微信菜单点击事件Event=VIEW
<xml><ToUserName><![CDATA[gh_1b519a1f5ff0]]></ToUserName>
<FromUserName><![CDATA[oHRogs1ZP_VfEkRK3wbzC0d4hJ1A]]></FromUserName>
<CreateTime>1453313107</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[VIEW]]></Event>
<EventKey><![CDATA[http://www.zhilangedu.cn:80/questionnaire/view/wxlistVote.shtml?accountid=68]]></EventKey>
<MenuId>403098247</MenuId>
</xml>

解密后:

{"ToUserName":"gh_1b519a1f5ff0",
"FromUserName":"oHRogs1ZP_VfEkRK3wbzC0d4hJ1A",
"CreateTime":"1453313107",
"MsgType":"event","Event":"VIEW",
"EventKey":"http://www.zhilangedu.cn:80/questionnaire/view/wxlistVote.shtml?accountid\u003d68"}
5:粉丝关注 eventType=subscribe
<xml><ToUserName><![CDATA[gh_8564206f6175]]></ToUserName>
<FromUserName><![CDATA[oll5DuOb01gBsgoAFoPAevsnxcCg]]></FromUserName>
<CreateTime>1453312687</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[subscribe]]></Event>
<EventKey><![CDATA[]]></EventKey>
</xml>

解密后:

{"ToUserName":"gh_8564206f6175",
"FromUserName":"oll5DuOb01gBsgoAFoPAevsnxcCg",
"CreateTime":"1453312687",
"MsgType":"event",
"Event":"subscribe",
"EventKey":""}

获取FromUserName = oll5DuOb01gBsgoAFoPAevsnxcCg(即openId,根据openId调用微信接口就可以获取粉丝的详细信息,然后将粉丝信息持久化到本地数据库)

6:粉丝取消关注 eventType=unsubscribe
<xml><ToUserName><![CDATA[gh_8713b6f91735]]></ToUserName>
<FromUserName><![CDATA[oL0_ut6qys6lr2HNoow_yirdIc_A]]></FromUserName>
<CreateTime>1453336420</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[unsubscribe]]></Event>
<EventKey><![CDATA[]]></EventKey>
</xml>

解密后:

{"ToUserName":"gh_8713b6f91735",
"FromUserName":"oL0_ut6qys6lr2HNoow_yirdIc_A",
"CreateTime":"1453336420",
"MsgType":"event",
"Event":"unsubscribe","EventKey":""}

获取FromUserName = oL0_ut6qys6lr2HNoow_yirdIc_A(即openId,根据openId可以将粉丝从本地数据库删除)

7:微信认证成功:
<xml><ToUserName><![CDATA[gh_75bd42c76810]]></ToUserName>
<FromUserName><![CDATA[oL2tEs-jwoo3QAq7Tkbm5wAgqY3s]]></FromUserName>
<CreateTime>1457841364</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[qualification_verify_success]]></Event>
<ExpiredTime>1489377364</ExpiredTime>
</xml>

解密后:

{"ToUserName":"gh_75bd42c76810",
"FromUserName":"oL2tEs-jwoo3QAq7Tkbm5wAgqY3s",
"CreateTime":"1457841364",
"MsgType":"event","Event":"qualification_verify_success"}

eventType=qualification_verify_success
update公众号的认证状态verifytypeinfo = 0(如果公众号没有微信认证的话,verifytypeinfo = -1)

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

十五楼亮哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值