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:

ParameterDescription
ToUserNameDeveloper WeChat ID
FromUserNameSender account (an OpenID)
CreateTimeMessage creation time (Integer type)
MsgTypeMessage type, event
EventEvent 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:

  1. 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 .

  2. 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:

ParameterDescription
ToUserNameDeveloper WeChat ID
FromUserNameSender account (an OpenID)
CreateTimeMessage creation time (Integer type)
MsgTypeMessage type, event
EventEvent type, subscribe
EventKeyEvent KEY value, qrscene_ is the prefix, followed by the parameter value of the QR code
TicketTickets 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:

##<xml>

Parameter description:

<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>
## when creating the QR code. #TicketThe QR code ticket can be used to exchange for the QR code picture

Use web debugging tools to debug this interface

#Report geographical location events

After the user agrees to report the geographical location, each time he enters the official account During a session, the geographical location will be reported when entering, or the geographical location will be reported every 5 seconds after entering the session. Official accounts can modify the above settings on the official platform website. When reporting a geographical location, WeChat will push the reported geographical location event to the URL filled in by the developer.

Push XML packet example:

ParameterDescription
ToUserNameDeveloper WeChat ID
FromUserNameSender account (an OpenID)
CreateTimeMessage creation time (Integer type)
MsgTypeMessage type, event
EventEvent type, SCAN
EventKeyThe event KEY value is a 32-bit unsigned integer, which is the QR code scene_id
<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:

ParameterDescription
ToUserNameDeveloper WeChat ID
FromUserNameSender account (an OpenID)
CreateTimeMessage creation time (Integer type)
MsgTypeMessage type, event
EventEvent type, LOCATION
LatitudeGeographical location latitude
LongitudeGeographical location longitude
PrecisionGeolocation 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:

ParameterDescription
ToUserNameDeveloper WeChat ID
FromUserNameSender account (an OpenID)
CreateTimeMessage creation time (Integer type)
MsgTypeMessage type, event
EventEvent type, CLICK
EventKeyThe 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:

ParameterDescription
ToUserNameDeveloper WeChat ID
FromUserNameSender account (an OpenID)
CreateTimeMessage creation time (Integer type)
MsgTypeMessage type, event
EventEvent type, VIEW
EventKeyEvent KEY value, set jump URL

Use web debugging tools Debugging this interface

1474853764453255.jpg