zoukankan      html  css  js  c++  java
  • 微信公众号消息与事件处理机制

    一:授权事件接收URL

    1:微信server每隔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?accountidu003d68"}
    

    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)

  • 相关阅读:
    Java POI Word 写文档
    安装SQL Server Management Studio遇到的29506错误
    DataSet中的relation
    如何在Eclipse中配置Tomcat
    button与submit
    redis应用场景
    机器学习实战-KNN(K-近邻算法)详解
    python中的random扩展
    php函数实现文章列表显示的几秒前,几分钟前,几天前等方法
    HTML5的Video标签的属性,方法和事件汇总
  • 原文地址:https://www.cnblogs.com/mfmdaoyou/p/7265075.html
Copyright © 2011-2022 走看看