WeChat Official Account Admin Platform Message API Guide
来源:互联网 发布:战网网络初始化失败 编辑:程序博客网 时间:2024/04/26 16:35
Keyword: WeChat Message API Text Image Location Link Event Music RichMedia
Author: PondBay Studio[WeChat Developer EXPERT]
Address: http://www.cnblogs.com/txw1958/p/WeChat-Message-API.html
Guide for Message API
Contents
[hide]- 1 Introduction
- 2 Apply for Message API
- 3 URL Access
- 4 Pushing Messages
- 4.1 Text messages
- 4.2 Image messages
- 4.3 Location data messages
- 4.4 Link messages
- 4.5 Event messages
- 5 Messages Replies
- 5.1 Text messages
- 5.2 Music message
- 5.3 Rich media messages
- 6 Notes
- 7 Sample code
Introduction
The WeChat Official Account Admin Platform provides developers with a Message API to manage incoming messages and reply logic.
Apply for Message API
Click Apply and fill in a name, phone and email for a contact person, as well as a URL pointing to your server and a token. The token is used to generate a signature for communication between your app and WeChat.
URL Access
When the application is submitted, a GET request will be sent to the URL provided above with the 4 parameters below:
You should check whether the HTTP request is from WeChat by verifying the signature. If the signature is correct, you should return the echostr.
The signature will be generated in the following way using the token (that you provided), timestamp and nonce.
1. Sort the 3 values of token, timestamp and nonce alphabetically.2. Combine the 3 parameters into one string, encrypt it using SHA-1.3. Compare the SHA-1 digest string with the signature from the request. If they are the same, the access request is from WeChat.
Pushing Messages
When a WeChat user sends a message to an Official Account, WeChat Official Account Admin Platform will POST it to you via the URL you provided.
Text messages
<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>
Image messages
<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>
Location data messages
<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[location]]></Label><MsgId>1234567890123456</MsgId></xml>
Link messages
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1357290913</CreateTime> <MsgType><![CDATA[link]]></MsgType> <Title><![CDATA[WeChat Official Account Platform portal]]></Title> <Description><![CDATA[The URL of the portal]]></Description> <Url><![CDATA[url]]></Url> <MsgId>1234567890123456</MsgId> </xml>
Event messages
<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>
Messages Replies
You can reply to incoming messages. Now the platform supports different kinds of messages, including text, image, voice, video and music. You can also do the operation 'add to my favorites'.
If you fail to perform your response within 5 seconds, we will close the connection.
The data structure for a reply message:
Text messages
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>12345678</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[content]]></Content> <FuncFlag>0</FuncFlag> </xml>
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> <FuncFlag>0</FuncFlag> </xml>
Rich media messages
<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> <FuncFlag>1</FuncFlag> </xml>
Notes
1. One user's unique ID is different for different Official Accounts.
2. Recommend you use port 80 for your app server.
Sample code
PHP:Download
PondBay Studio is the Expert of WeChat Development, and has a lots of cases in China, Japan, Europe and US. The Founder has served the top companies such as China HuaWei and Israel Company. You can Contact US via email
- WeChat Official Account Admin Platform Message API Guide
- WeChat Official Account Admin Platform Message API Guide
- WeChat Official Account Admin Platform API Introduction
- WeChat Official Account Admin Platform API Introduction
- CorelDRAW: The Official Guide
- Android official compile guide
- magento add admin account
- JBoss 4.0 - The Official Guide
- Crystal Reports XI Official Guide
- CCDA Official Exam Certification Guide
- Quicken 2009 The Official Guide
- RSA Security's Official Guide to Cryptography
- DB2 for Solaris: The Official Guide
- DB2 Version 8: The Official Guide
- Official Butterfly.net Game Developer's Guide
- RSA Security's Official Guide to Cryptography
- CCNP ISCW Official Exam Certification Guide
- CCNP ONT Official Exam Certification Guide
- 微信公众平台开发(59)相册
- 接口100
- 微信公众平台开发(60)每日英语
- PHP获取Cookie模拟登录
- 微信公众平台开发(61)预约挂号
- WeChat Official Account Admin Platform Message API Guide
- axlsx报表工具(一)——安装及入门
- WeChat Official Account Admin Platform API Introduction
- 微信支付可能改变的六大行业
- 易信公众平台的微创新:活动消息
- 微信公众平台开发(62)股票行情及分析
- C++编程规范之32:弄清楚要编写的是哪种类
- 七牛云存储官方接口PHP版本
- 微信5.0绑定银行卡教程