When an ordinary WeChat user sends a message to a public account, the WeChat server packages the XML number of the POST message to the developer's URL.
Please note:
- For message retry, msgid is recommended.
- WeChat If the server does not receive a response within five seconds, it disconnects the connection and reinitiates the request for a total of three retries.If the server cannot guarantee to process and reply within five seconds, you can directly reply to the empty string, and the WeChat server will not do any processing on this, and will not initiate a retry. See Send a message - Reject a message for more details.
- If a developer needs to respond immediately to a user message within 5 seconds, i.e. when using the Send Message-Reject Message interface to passively reply to a message to the user, they can
Set up message encryption at the developer center on the public platform's official website. When encryption is turned on, messages sent by users and messages returned by developers will be encrypted (but developers send messages to users through API calls such as customer service interfaces are not affected). For detailed instructions on message decryption, see "Sending a Message - Passive Reply Message Decryption Instructions." The structure of the push XML digital packet for each message type is as follows:
# Text Message
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1348831860</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[this is a test]]></Content>
<MsgId>1234567890123456</MsgId>
<MsgDataId>xxxx</MsgDataId>
<Idx>xxxx</Idx>
</xml>
parameter | describe |
---|---|
ToUserName | Developer No. WeChat |
FromUserName | Sender account (an OpenID) |
CreateTime | Message Creation Time (integer) |
MsgType | Message type, text is text |
Content | Text message content |
MsgId | Message id, 64-bit integer |
MsgDataId | The data ID of the message (only if the message is from an article) |
Idx | The first article in a multi-text article starts with 1 (the message only exists when it comes from the article) |
Deploy this interface using a web debugging tool
# Photo message
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1348831860</CreateTime>
<MsgType><![CDATA[image]]></MsgType>
<PicUrl><![CDATA[this is a url]]></PicUrl>
<MediaId><![CDATA[media_id]]></MediaId>
<MsgId>1234567890123456</MsgId>
<MsgDataId>xxxx</MsgDataId>
<Idx>xxxx</Idx>
</xml>
parameter | describe |
---|---|
ToUserName | Developer No. WeChat |
FromUserName | Sender account (an OpenID) |
CreateTime | Message Creation Time (integer) |
MsgType | Message type, image |
PicUrl | Image Link (generated by the system) |
MediaId | Picture message media id, you can call to get temporary material interface pull data. |
MsgId | Message id, 64-bit integer |
MsgDataId | The data ID of the message (only if the message is from an article) |
Idx | The first article in a multi-text article starts with 1 (the message only exists when it comes from the article) |
Deploy this interface using a web debugging tool
# Voice Messages
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1357290913</CreateTime>
<MsgType><![CDATA[voice]]></MsgType>
<MediaId><![CDATA[media_id]]></MediaId>
<Format><![CDATA[Format]]></Format>
<MsgId>1234567890123456</MsgId>
<MsgDataId>xxxx</MsgDataId>
<Idx>xxxx</Idx>
<MediaId16K><![CDATA[media_id_16k]]></MediaId16K>
</xml>
parameter | describe |
---|---|
ToUserName | Developer No. WeChat |
FromUserName | Sender account (an OpenID) |
CreateTime | Message Creation Time (integer) |
MsgType | Voice for voice |
MediaId | Voice media id, you can call to get temporary material interface pull data, Format for amr return 8K sampling rate amr voice. |
Format | Voice formats such as amr, speex, etc. |
MsgId | Message id, 64-bit integer |
MsgDataId | The data ID of the message (only if the message is from an article) |
Idx | The first article in a multi-text article starts with 1 (the message only exists when it comes from the article) |
MediaId16K | 16K sampling rate voice message media id, you can call to get temporary material interface pull data, return 16K sampling rate amr / speex voice. |
Deploy this interface using a web debugging tool
# Video Messages
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1357290913</CreateTime>
<MsgType><![CDATA[video]]></MsgType>
<MediaId><![CDATA[media_id]]></MediaId>
<ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId>
<MsgId>1234567890123456</MsgId>
<MsgDataId>xxxx</MsgDataId>
<Idx>xxxx</Idx>
</xml>
parameter | describe |
---|---|
ToUserName | Developer No. WeChat |
FromUserName | Sender account (an OpenID) |
CreateTime | Message Creation Time (integer) |
MsgType | Video for video |
MediaId | Video message media id, you can call to get temporary material interface pull data. |
ThumbMediaId | Video message thumbnail media ID, you can call the multimedia document download interface pull data. |
MsgId | Message id, 64-bit integer |
MsgDataId | The data ID of the message (only if the message is from an article) |
Idx | The first article in a multi-text article starts with 1 (the message only exists when it comes from the article) |
Deploy this interface using a web debugging tool
# Small Video Message
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1357290913</CreateTime>
<MsgType><![CDATA[shortvideo]]></MsgType>
<MediaId><![CDATA[media_id]]></MediaId>
<ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId>
<MsgId>1234567890123456</MsgId>
<MsgDataId>xxxx</MsgDataId>
<Idx>xxxx</Idx>
</xml>
parameter | describe |
---|---|
ToUserName | Developer No. WeChat |
FromUserName | Sender account (an OpenID) |
CreateTime | Message Creation Time (integer) |
MsgType | Short video |
MediaId | Video message media id, you can call to get temporary material interface pull data. |
ThumbMediaId | Video message thumbnail media id, you can call to get temporary material interface pull data. |
MsgId | Message id, 64-bit integer |
MsgDataId | The data ID of the message (only if the message is from an article) |
Idx | The first article in a multi-text article starts with 1 (the message only exists when it comes from the article) |
Deploy this interface using a web debugging tool
# Geolocation Message
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1351776360</CreateTime>
<MsgType><![CDATA[location]]></MsgType>
<Location_X>23.134521</Location_X>
<Location_Y>113.358803</Location_Y>
<Scale>20</Scale>
<Label><![CDATA[位置信息]]></Label>
<MsgId>1234567890123456</MsgId>
<MsgDataId>xxxx</MsgDataId>
<Idx>xxxx</Idx>
</xml>
parameter | describe |
---|---|
ToUserName | Developer No. WeChat |
FromUserName | Sender account (an OpenID) |
CreateTime | Message Creation Time (integer) |
MsgType | Message type, location is location |
Location_X | Geographic location latitude |
Location_Y | Geolocation Longitude |
Scale | Map zoom size |
Label | Geographic location information |
MsgId | Message id, 64-bit integer |
MsgDataId | The data ID of the message (only if the message is from an article) |
Idx | The first article in a multi-text article starts with 1 (the message only exists when it comes from the article) |
Deploy this interface using a web debugging tool
# Link message
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1351776360</CreateTime>
<MsgType><![CDATA[link]]></MsgType>
<Title><![CDATA[公众平台官网链接]]></Title>
<Description><![CDATA[公众平台官网链接]]></Description>
<Url><![CDATA[url]]></Url>
<MsgId>1234567890123456</MsgId>
<MsgDataId>xxxx</MsgDataId>
<Idx>xxxx</Idx>
</xml>
parameter | describe |
---|---|
ToUserName | Receiver No. WeChat |
FromUserName | The sender WeChat number, or an OpenID for a normal user |
CreateTime | Message creation time |
MsgType | Message type, link is link |
Title | Message header |
Description | Message Description |
Url | Message Link |
MsgId | Message id, 64-bit integer |
MsgDataId | The data ID of the message (only if the message is from an article) |
Idx | The first article in a multi-text article starts with 1 (the message only exists when it comes from the article) |