Receive event push
Receive event push
In the process of interaction between WeChat users and official accounts, certain user operations will cause the WeChat server to notify developers in the developer center through event push Set the server address so that developers can obtain this information. Among them, some push events allow developers to reply to users after they occur, while others do not. For detailed instructions, please see the WeChat push message and event description at the end of this page.
Follow/Unfollow Event
When a user follows or unfollows a public account, WeChat will push this event to the URL filled in by the developer. It is convenient for developers to send welcome messages to users or unbind accounts.
If the WeChat server does not receive a response within five seconds, it will disconnect and re-initiate the request, retrying three times in total.
Regarding retry message duplication, it is recommended to use FromUserName CreateTime to deduplicate messages.
If the server cannot guarantee to process and reply within five seconds, you can directly reply with an empty string. The WeChat server will not do anything with this and will not initiate a retry.
Push XML packet example:
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[subscribe]]></Event> </xml> |
Parameter description:
Parameter | Description |
---|---|
ToUserName | Developer WeChat ID |
FromUserName | Sender account (an OpenID) |
CreateTime | Message creation time (Integer type) |
MsgType | Message type, event |
Event | Event type, subscribe (subscribe), unsubscribe (cancel subscription) |
Use web debugging tools to debug this interface
Scan QR code event with parameters
User scans QR code with scene value , the following two events may be pushed:
If the user has not followed the official account, the user can follow the official account. After following the official account, WeChat will push the following events with scene values to the developer .
If the user has followed the official account, WeChat will push the scanning event with scene value to the developer.
1. When the user has not followed, push the event after following the user
Example of pushing XML data packet:
<xml><ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[subscribe]]></Event> <EventKey><![CDATA[qrscene_123123]]></EventKey> <Ticket><![CDATA[TICKET]]></Ticket> </xml> |
Parameter description:
Parameter | Description |
---|---|
ToUserName | Developer WeChat ID |
FromUserName | Sender account (an OpenID) |
CreateTime | Message creation time (Integer type) |
MsgType | Message type, event |
Event | Event type, subscribe |
EventKey | Event KEY value, qrscene_ is the prefix, followed by the parameter value of the QR code |
Ticket | Tickets with QR codes can be used to exchange for QR code pictures |
2. Event push when the user has followed
Example of push XML packet:
<ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> < CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[SCAN]]>< /Event> <EventKey><![CDATA[SCENE_VALUE]]></EventKey> <Ticket><![CDATA[TICKET]]></Ticket> </xml> |
Parameter | Description |
---|---|
ToUserName | Developer WeChat ID |
FromUserName | Sender account (an OpenID) |
CreateTime | Message creation time (Integer type) |
MsgType | Message type, event |
Event | Event type, SCAN |
EventKey | The event KEY value is a 32-bit unsigned integer, which is the QR code scene_id |
The QR code ticket can be used to exchange for the QR code picture |
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[LOCATION]]></Event> <Latitude>23.137466</Latitude> <Longitude>113.352425</Longitude> <Precision>119.385040</Precision> </xml> |
Parameter description:
Parameter | Description |
---|---|
ToUserName | Developer WeChat ID |
FromUserName | Sender account (an OpenID) |
CreateTime | Message creation time (Integer type) |
MsgType | Message type, event |
Event | Event type, LOCATION |
Latitude | Geographical location latitude |
Longitude | Geographical location longitude |
Precision | Geolocation accuracy |
Use web debugging tools to debug this interface
Custom menu event
After the user clicks the custom menu, WeChat will send the click event Push to developers, please note that clicking on the menu will pop up a submenu and will not generate a report.
Event push when clicking the menu to pull the message
Example of pushing XML data package:
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[CLICK]]></Event> <EventKey><![CDATA[EVENTKEY]]></EventKey> </xml> |
Parameter description:
Parameter | Description |
---|---|
ToUserName | Developer WeChat ID |
FromUserName | Sender account (an OpenID) |
CreateTime | Message creation time (Integer type) |
MsgType | Message type, event |
Event | Event type, CLICK |
EventKey | The event KEY value corresponds to the KEY value in the custom menu interface |
Event push when clicking the menu jump link
Push XML data packet example:
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[VIEW]]></Event> <EventKey><![CDATA[www.qq.com]]></EventKey> </xml> |
Parameter description:
Parameter | Description |
---|---|
ToUserName | Developer WeChat ID |
FromUserName | Sender account (an OpenID) |
CreateTime | Message creation time (Integer type) |
MsgType | Message type, event |
Event | Event type, VIEW |
EventKey | Event KEY value, set jump URL |