When a user sends a message to Service Account (or when an event is pushed due to some specific user action),A POST request is generated, and the developer can return a specific XML structure in the response package (Get) to respond to the message (now supporting reply text, pictures, text, voice, video, music).Strictly speaking, sending a passive response message is not an interface, but a reply to a message sent by the WeChat server.
WeChat server is sending user messages to the Service Account developer server address (configuration path: [WeChat developer platform]]](https://developers.weixin.qq.com/platform) - My business- Service number - Development information) After the WeChat server does not receive a response within five seconds, it will break the connection and re-launch the request, a total of three retries. If during debugging, it is found that the user cannot receive a responding message, it can check whether the message processing is overtime. With regard to the message weight of retry, msgid messages recommend using msgid weight. FromUserName + CreateTime is recommended for event type messages.
If a developer wishes to enhance security, they can turn on message encryption at the Developer Center so that,User messages to Service Account and service numbers passively respond to user messages continue to be encrypted, for more information see message decryption instructions .
If the server cannot guarantee to process and reply within five seconds, the following response must be made:This way the WeChat server doesn't do anything about this and doesn 't initiate a retry (in which case an asynchronous response can be made using the customer service message interface), otherwise a serious error message will be presented.See the following instructions for more details:
1, directly reply success (recommended way) 2, directly reply empty string (refers to the length of byte zero empty character string, rather than XML structure in the content field is empty)
Once the following situation is encountered, WeChat will send a system prompt to the user in the Service Account session, "This service number is temporarily unable to provide service, please try again later":
1, the developer did not reply to any content within 5 seconds 2, the developer replied to abnormal data, such as JSON data, etc.
Also, please note that replying to multimedia messages such as pictures (not supporting GIFs) requires a pre-upload of temporary material through the Material Management Interface to the WeChat server. You can use temporary or permanent material in the Material Management.
The required XML digital packet structure for each message type is as follows:
catalog
# Reply to text message
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[你好]]></Content>
</xml>
parameter | Do I have to? | describe |
---|---|---|
ToUserName | yes | Recipient account number (OpenID received) |
FromUserName | yes | Developer No. WeChat |
CreateTime | yes | Message Creation Time (integer) |
MsgType | yes | Message type, text is text |
Content | yes | Reply message content (newline: in the content can newline, WeChat guest supports newline display) |
# Response to Photo Message
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[image]]></MsgType>
<Image>
<MediaId><![CDATA[media_id]]></MediaId>
</Image>
</xml>
parameter | Do I have to? | Introductions |
---|---|---|
ToUserName | yes | Recipient account number (OpenID received) |
FromUserName | yes | Developer No. WeChat |
CreateTime | yes | Message Creation Time (integer) |
MsgType | yes | Message type, image |
MediaId | yes | Upload multimedia files through the interface of material management, get the id. |
# Reply to voice messages
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[voice]]></MsgType>
<Voice>
<MediaId><![CDATA[media_id]]></MediaId>
</Voice>
</xml>
parameter | Do I have to? | Introductions |
---|---|---|
ToUserName | yes | Recipient account number (OpenID received) |
FromUserName | yes | Developer No. WeChat |
CreateTime | yes | Message Create a timestamp (integer) |
MsgType | yes | Message type, voice is voice |
MediaId | yes | Upload multimedia files through the interface of material management, and get the id |
# Reply to video message
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[video]]></MsgType>
<Video>
<MediaId><![CDATA[media_id]]></MediaId>
<Title><![CDATA[title]]></Title>
<Description><![CDATA[description]]></Description>
</Video>
</xml>
parameter | Do I have to? | Introductions |
---|---|---|
ToUserName | yes | Recipient account number (OpenID received) |
FromUserName | yes | Developer No. WeChat |
CreateTime | yes | Message Creation Time (integer) |
MsgType | yes | Message type, video is video |
MediaId | yes | Upload multimedia files through the interface of material management, and get the id |
Title | no | Title of the video message |
Description | no | Description of a video message |
# Reply to a music message
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[music]]></MsgType>
<Music>
<Title><![CDATA[TITLE]]></Title>
<Description><![CDATA[DESCRIPTION]]></Description>
<MusicUrl><![CDATA[MUSIC_Url]]></MusicUrl>
<HQMusicUrl><![CDATA[HQ_MUSIC_Url]]></HQMusicUrl>
<ThumbMediaId><![CDATA[media_id]]></ThumbMediaId>
</Music>
</xml>
parameter | Do I have to? | Introductions |
---|---|---|
ToUserName | yes | Recipient account number (OpenID received) |
FromUserName | yes | Developer No. WeChat |
CreateTime | yes | Message Creation Time (integer) |
MsgType | yes | Message type, music for music |
Title | no | Music title |
Description | no | Music Description |
MusicURL | no | Music links |
HQMusicUrl | no | High quality music link, WIFI environment priority to use the link to play music |
ThumbMediaId | yes | Thumbnail media id, upload multimedia files through the interface of material management, get id |
# Reply to Graphic Message
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>1</ArticleCount>
<Articles>
<item>
<Title><![CDATA[title1]]></Title>
<Description><![CDATA[description1]]></Description>
<PicUrl><![CDATA[picurl]]></PicUrl>
<Url><![CDATA[url]]></Url>
</item>
</Articles>
</xml>
parameter | Do I have to? | Introductions |
---|---|---|
ToUserName | yes | Recipient account number (OpenID received) |
FromUserName | yes | Developer No. WeChat |
CreateTime | yes | Message Creation Time (integer) |
MsgType | yes | The message type is news. |
ArticleCount | yes | Number of graphic messages; When a user sends six kinds of messages - text, pictures, voice, video, text, geo-location - the developer can only reply to one text message. The remaining scenarios can reply to up to 8 graphic messages |
Articles | yes | Graphic message information. Note that if the number of graphs exceeds the limit, only the number of items within the limit will be issued |
Title | yes | Graphic message title |
Description | yes | Graphic message description |
PicUrl | yes | Image link, support JPG, PNG format, the better effect is the big picture 360*200, small picture 200*200 |
Url | yes | Click on the text message to jump link |