WeChat interface message Interface Guide

Source: Internet
Author: User

The message interface of the public platform provides developers with a new message processing method.

Message application interface

Click Apply and enter the url and token. You can enter the token as needed to generate a signature.


Website access

After a public platform user submits information, the server sends a GET request to the URL filled in with four parameters:

Parameters Description
Signature Encrypted Signature
Timestamp Timestamp
Nonce Random Number
Echostr Random string

The developer verifies the request by verifying signature (The following is a verification method ). If you confirm that the GET request is from the server, the echostr parameter is returned as is, and the access takes effect. Otherwise, the access fails.

Signature combines the token parameter entered by the developer with the timestamp parameter and nonce parameter in the request.

Encryption/verification process: 1. sort the tokens, timestamp, and nonce in Lexicographic Order. splice the three parameter strings into one string for sha1 encryption. the encrypted string obtained by the developer can be compared with signature to identify that the request comes from

 

Message push

When a common user sends a message to a public account, the server will POST the message to the entered URL. The structure 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> </xml>
Parameters Description
ToUserName Developer ID
FromUserName Sender account (one OpenID)
CreateTime Message creation time (integer)
MsgType Text
Content Text message content
MsgId Message id, 64-bit integer
Image message
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1348831860</CreateTime> <MsgType><![CDATA[image]]></MsgType> <PicUrl><![CDATA[this is a url]]></PicUrl> <MsgId>1234567890123456</MsgId> </xml>
Parameters Description
ToUserName Developer ID
FromUserName Sender account (one OpenID)
CreateTime Message creation time (integer)
MsgType Image
PicUrl Image Link
MsgId Message id, 64-bit integer
Geographic location message
<Xml> <ToUserName> <! [CDATA [toUser]> </ToUserName> <FromUserName> <! [CDATA [fromUser]> </FromUserName> <CreateTime> 1351776360 </CreateTime> <MsgType> <! </MsgType> <Location_X> 23.134521 </Location_X> <Location_Y> 113.358803 </Location_Y> <Scale> 20 </Scale> <Label> <! [CDATA [location information]> </Label> <MsgId> 1234567890123456 </MsgId> </xml>
Parameters Description
ToUserName Developer ID
FromUserName Sender account (one OpenID)
CreateTime Message creation time (integer)
MsgType Location
Location_X Geographic location and latitude
Location_Y Geographic longitude
Scale Map zoom
Label Geographic location information
MsgId Message id, 64-bit integer
Link message
<Xml> <ToUserName> <! [CDATA [toUser]> </ToUserName> <FromUserName> <! [CDATA [fromUser]> </FromUserName> <CreateTime> 1351776360 </CreateTime> <MsgType> <! [CDATA [link]> </MsgType> <Title> <! [CDATA [official website of the public platform]> </Title> <Description> <! [CDATA [official website of the public platform]> </Description> <Url> <! </Url> <MsgId> 1234567890123456 </MsgId> </xml>
Parameters Description
ToUserName Recipient number
FromUserName Sender id. If it is a common user, it is an OpenID.
CreateTime Message Creation Time
MsgType Message Type, link
Title Message Title
Description Message description
Url Message Link
MsgId Message id, 64-bit integer
Event push

Event push only supports version 4.5. Currently, you can enable event push, follow, and cancel follow event push for custom menu interfaces. Other functions will be available soon.

<xml><ToUserName><![CDATA[toUser]]></ToUserName><FromUserName><![CDATA[FromUser]]></FromUserName><CreateTime>123456789</CreateTime><MsgType><![CDATA[event]]></MsgType><Event><![CDATA[EVENT]]></Event><EventKey><![CDATA[EVENTKEY]]></EventKey></xml>
Parameters Description
ToUserName Recipient number
FromUserName Sender id. If it is a common user, it is an OpenID.
CreateTime Message Creation Time
MsgType Message Type, event
Event Event Type: subscribe, unsubscribe, and CLICK)
EventKey Event KEY value, which corresponds to the KEY value in the custom menu interface
Message reply

For each POST request, the developer returns a specific xml structure in the response packet to respond to the message (now supports text, text, voice, video, music ).

If the server fails to receive the response within five seconds, the connection will be disconnected.

The xml structure of the reply is as follows:

Reply text message
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>12345678</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[content]]></Content> </xml>
Parameters Description
ToUserName Recipient account (received OpenID)
FromUserName Developer ID
CreateTime Message Creation Time
MsgType Text
Content The content of the reply message. The length cannot exceed 2048 bytes.
Reply 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> </Music> </xml>
Parameters Description
ToUserName Recipient account (received OpenID)
FromUserName Developer ID
CreateTime Message Creation Time
MsgType Music
MusicUrl Music Link
HQMusicUrl High-quality music link, which is preferred for playing music in WIFI Environments
Reply to text message
<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> 
Parameters Description
ToUserName Recipient account (received OpenID)
FromUserName Developer ID
CreateTime Message Creation Time
MsgType News
ArticleCount Number of text and text messages, up to 10
Articles Multiple text messages. The first item is a large image by default.
Title Text message title
Description Text Message description
PicUrl Image links. JPG and PNG formats are supported. The larger image size is 640*320, and the smaller image size is 80*80.
Url Click the text message jump Link
Notes

1. the user's OpenID is a fixed and unique string for a public number.

2. Use port 80

Sample Code

PHP: Download


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.