Event-based Messages
Back

From WeChat Official Account Admin Platform
Jump to: navigation, search

Contents

Following/Unfollowing Event

When a user follows or unfollows an official account event, WeChat system pushes the event to the URL entered by the developer so that the developer can deliver a welcome message or unlink the account.

If a response from the developer's backend system is not received within five seconds, the WeChat Official Account System will close the connection and initiate a new request up to three times.

To avoid duplicate retry messages, it is recommended to use FromUserName + CreateTime.

If the developer’s backend system cannot guarantee a reply back to the WeChat Official Account System within 5 seconds, a reply with an empty string should be returned to the WeChat Official Account System instead. In this case, the WeChat Official Account System will not attempt to resend the event-based message.

An example of pushing XML data package is as follows:

<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[FromUser]]></FromUserName>
<CreateTime>123456789</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[subscribe]]></Event>
</xml>
Parameter Description
ToUserName Developer's WeChat ID
FromUserName Unique sender ID (an OpenID)
CreateTime Message creation time (Integer)
MsgType Event
Event An event type: either subscribe or unsubscribe

Scanning Parametric QR Code Event

When a user scans a QR code with the scene value, the following events may be pushed: The user can follow the official account if he/she is not yet a follower. WeChat system then pushes the followed event and scene value to the developer. If the user is already a follower, WeChat system pushes the scanning event and the scene value to the developer.

1. The user is not a follower.

An example of pushing an XML data package is as follows:

<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
ToUserName Developer's WeChat ID
FromUserName Unique sender ID (an OpenID)
CreateTime Message creation time (Integer)
MsgType Event
Event Event type: subscribe
EventKey Event KEY value, "qrscene_" is a prefix followed by the parameter value ​​for the QR Code
Ticket A QR Code ticket that can be exchanged for a QR Code image

2. The user is a follower.

An example of pushing an XML data package is as follows:

<xml>
<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's WeChat ID
FromUserName Unique sender ID (an OpenID)
CreateTime Message creation time (Integer)
MsgType Event
Event Event type: scan
EventKey Event KEY value (a 32-bit unsigned integer)
Ticket A QR Code ticket that can be exchanged a QR Code image


Reporting Location Event

Developers can set on the Admin Platform whether a user's location is reported each time he/she enters an official account chat or every 5 seconds after he/she enters a chat. The WeChat system pushes the reporting location event to the URL entered by the developer. An example of pushing an XML data package is as follows:

<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
ToUserName Developer's WeChat ID
FromUserName Unique sender ID (an OpenID)
CreateTime Message creation time (Integer)
MsgType Event
Event Event
Event Event type: location
Latitude Latitude
Longitude Longitude
Precision Location accuracy


Custom-defined Menu Event

Pulling Message Event

For a clickable custom-defined menu, the WeChat system pushes the click event to the developer after the menu is clicked. Note that it doesn't push anything for a view-only menu (redirecting to URL). An example of pushing an XML data package is as follows:

<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's WeChat ID
FromUserName Unique sender ID (an OpenID)
CreateTime Message creation time (Integer)
MsgType Event
Event Event type: click
EventKey An event KEY value that corresponds to the KEY value in the user-defined menu API

URL Redirection Event

An example of pushing an XML data package is as follows:

<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's WeChat ID
FromUserName Unique sender ID (an OpenID)
CreateTime Message creation time (Integer)
MsgType Event
Event Event type: view
EventKey An event KEY value that corresponds to the URL to be redirected to
Developer Guide
Custom-defined Menu
WeChat JS-SDK