When a user sends a message to the official account (or when events are pushed due to certain specific user operations), a POST request will be generated. Developers can respond to the message by returning a specific XML structure in the response package (Get) (reply text, pictures, graphics, voice, video, and music are now supported). Strictly speaking, sending a passive response message is not actually an interface, but a reply to a message sent by the WeChat server.
After the WeChat server sends the user's message to the official account's developer server address (configured in the developer center), if the WeChat server does not receive a response within five seconds, it will disconnect and re-initiate the request. , retry three times in total. If during debugging, you find that the user cannot receive the response message, you can check whether the message processing times out. Regarding retry message deduplication, it is recommended to use msgid to deduplicate messages with msgid. It is recommended to use FromUserName CreateTime to deduplicate event type messages.
If developers want to enhance security, they can turn on message encryption in the developer center. In this way, messages sent by users to official accounts and passive replies to user messages from official accounts will continue to be encrypted (but). For details, see Passive Reply Message encryption and decryption instructions.
If the server cannot guarantee to process and reply within five seconds, the following reply must be made, so that the WeChat server will not do anything with it and will not initiate a retry (in this case, you can Use the customer service message interface for asynchronous reply), otherwise, a serious error message will appear. See the instructions below for details:
1. Directly reply to success (recommended method) 2. Directly reply to an empty string (referring to an empty string with a byte length of 0, rather than The content of the content field in the XML structure is empty) |
Once the following situations are encountered, WeChat will issue the message to the user in the public account session The system prompts "This official account is temporarily unable to provide services, please try again later":
1. The developer did not reply with any content within 5 seconds 2. The developer responded with abnormal data, such as JSON data, etc. |
In addition, please note that when replying to multimedia messages such as pictures, you need to upload temporary materials to the WeChat server through the material management interface in advance. You can use temporary materials in material management or permanent materials.
Reply to text message
##<xml><ToUserName><! [CDATA[toUser]]></ToUserName><FromUserName><![CDATA[fromUser]]></FromUserName><CreateTime>12345678< ;/CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[Hello]] ></Content></xml> |
Parameter | Is it required | Description |
---|
ToUserName | is the | receiver account (received OpenID) |
FromUserName | is the | developer WeChat ID |
CreateTime | is the | message creation time (integer) |
MsgType | is | text |
Content | is the message content of | (line break: line breaks can be made in content , WeChat client supports line wrap display) |
Reply to picture 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 | Is it required | Description |
---|
ToUserName | is the | receiver account (received OpenID) |
FromUserName | is the | developer WeChat ID |
CreateTime | is the | message creation time (integer) |
MsgType | is | image |
MediaId | is | Upload multimedia files through the interface in material management , the obtained id. |
Reply to voice message
<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 | Is it required | Description |
---|
ToUserName | is the | receiver account (received OpenID) |
FromUserName | is the | developer Wechat ID |
CreateTime | is the | message creation timestamp (integer) |
MsgType | is | voice, voice |
MediaId | is | Upload multimedia files through the interface in material management , the obtained 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 | Is it required | Description |
---|
ToUserName | Yes | Receiver account (received OpenID) |
FromUserName | is | Developer WeChat ID |
CreateTime | is | Message creation time (integer) |
MsgType | is | video |
##MediaId | is the id | ## obtained by uploading multimedia files through the interface in material management. #Title |
NoTitle of video message | | Description |
NoVideo message description of | | Reply to 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 | Is it required | Description |
---|
ToUserName | Yes | Receiver account (received OpenID) | FromUserName | is | Developer WeChat ID | CreateTime | is | Message creation time (integer) | MsgType | is | music | Title | No | Music Title | Description | No | Music Description | MusicURL | No | Music Link | HQMusicUrl | No | High-quality music link, WIFI environment preferentially uses this link to play music | ThumbMediaId | is the media ID of the | thumbnail. Upload multimedia files through the interface in material management, and the obtained ID |
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>12345678</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>2</ArticleCount>
<Articles>
<item>
<Title><![CDATA[title1]]></Title>
<Description><![CDATA[description1]]></Description>
<PicUrl><![CDATA[picurl]]></PicUrl>
<Url><![CDATA[url]]></Url>
</item>
<item>
<Title><![CDATA[title]]></Title>
<Description><![CDATA[description]]></Description>
<PicUrl><![CDATA[picurl]]></PicUrl>
<Url><![CDATA[url]]></Url>
</item>
</Articles>
</xml> | Parameter | Is it required | Description |
---|
ToUserName | Yes | Receiver account (received OpenID) | FromUserName | is | Developer WeChat ID | CreateTime | is | Message creation time (integer) | MsgType | is | news | ##ArticleCount | is the number of | graphic messages, limited to 10 messages | Articles | is | multiple graphic and text messages. By default, the first item is a large image. Note that if the number of graphic and text exceeds 10, there will be no response | Title | No | Graphic message title | Description | No | Graphic message description | PicUrl | No | Picture link, supports JPG and PNG formats, the best effect is a large image 360*200, Small picture 200*200 | Url | No | Click on the graphic message to jump to the link |
|