WeChat Official Account Admin Platform Message API Guide

简介: Keyword: WeChat Message API Text Image Location Link Event Music RichMedia Author: PondBay Studio[WeChat Developer EXPERT] Address:  http://www.

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]

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:

Parameter Description
signature signature for communication encryption
timestamp time stamp
nonce a random number
echostr a random string

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>
Parameter Description
ToUserName WeChat ID of your app
FromUserName a unique ID for the sender
CreateTime create time of the message
MsgType message type ("text" for text messages)
Content message contents
MsgId a unique ID for the message (64 bit integer)

 

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>
Parameter Description
ToUserName WeChat ID of your app
FromUserName a unique ID for the sender
CreateTime create time of the message
MsgType message type ("image" for image messages)
PicUrl URL for the image
MsgId a unique ID for the message (64 bit integer)

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> 
Parameter Description
ToUserName WeChat ID of your app
FromUserName a unique ID for the sender
CreateTime create time of the message
MsgType message type ("location" for location messages)
Location_X latitude of the location
Location_Y longitude of the location
Scale scale of the map
Label location description
MsgId a unique ID for the message (64 bit integer)

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> 
Parameter Description
ToUserName WeChat ID of your app
FromUserName a unique ID for the sender
CreateTime create time of the message
MsgType message type ("link" for link messages)
Title title of the message
Description description of the message
Url url which is sent to users
MsgId a unique ID for the message (64 bit integer)

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>
Parameter Description
ToUserName WeChat ID of your app
FromUserName a unique ID for the sender
CreateTime create time of the message
MsgType message type ("event" for event messages)
Event event type, currently we have 3 types: subscribe, unsubscribe, CLICK(coming soon)
EventKey for future usage

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>
Parameter Description
ToUserName a unique ID for the receiver, you can get it from the request
FromUserName WeChat ID of your app
CreateTime create time of the message, the type is integer
MsgType message type ("text" for text messages)
Content reply message contents
FuncFlag add a star for the message if the bit (0x0001) is set

 

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>
Parameter Description
ToUserName a unique ID for the receiver, you can get it from the request
FromUserName WeChat ID of your app
CreateTime create time of the message, the type is integer
MsgType message type("music" for music messages)
MusicUrl URL for the music
HQMusicUrl URL for high quality, WeChat will access it when using WiFi
ThumbMediaId OPTIONAL. You will get this ID after you upload the thumb (80*80) by using the API
FuncFlag add a star for the message if the bit (0x0001) is set

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> 
Parameter Description
ToUserName a unique ID for the receiver, you can get it from the request
FromUserName WeChat ID of your app
CreateTime create time of the message, the type is integer
MsgType message type ("news" for rich media messages)
ArticleCount quantity of rich media messages (no larger than 10)
Articles contents of rich media messages. The first item will be displayed in large image by default.
Title title of the rich media message
Description description of the rich media message
PicUrl URL of images in the rich media message. Domain name of this URL should be the same as the one of URL provided in basic info. Recommended image size: 640*320 (large image); 80*80 (small image)
Url redirection link of the rich media message

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  

 

 

 

相关文章
|
9月前
|
安全 关系型数据库 API
docker方式安装konga图形化admin api UI
docker方式安装konga图形化admin api UI
102 0
WeChat Official Account Admin Platform API Introduction
Keyword: WeChat API Introduction Message and GeneralAuthor: PondBay Studio[WeChat Developer EXPERT] Address: http://www.
1213 0
|
21小时前
|
SQL API Python
Python DB API下规范下cursor对象常用接口
Python DB API下规范下cursor对象常用接口。
21 4
|
20小时前
|
安全 API 开发者
智能体-Agent能力升级!新增Assistant API & Tools API服务接口
ModelScope-Agent是一个交互式创作空间,它支持LLM(Language Model)的扩展能力,例如工具调用(function calling)和知识检索(knowledge retrieval)。它已经对相关接口进行了开源,以提供更原子化的应用LLM能力。用户可以通过Modelscope-Agent上的不同代理(agent),结合自定义的LLM配置和消息,调用这些能力。
|
21小时前
|
JSON 搜索推荐 数据挖掘
电商数据分析的利器:电商关键词搜索API接口(标题丨图片丨价格丨链接)
淘宝关键词搜索接口为电商领域的数据分析提供了丰富的数据源。通过有效利用这一接口,企业和研究人员可以更深入地洞察市场动态,优化营销策略,并提升用户体验。随着电商平台技术的不断进步,未来的API将更加智能和个性化,为电商行业带来更多的可能性。
|
21小时前
|
存储 缓存 运维
DataWorks操作报错合集之DataWorks根据api,调用查询文件列表接口报错如何解决
DataWorks是阿里云提供的一站式大数据开发与治理平台,支持数据集成、数据开发、数据服务、数据质量管理、数据安全管理等全流程数据处理。在使用DataWorks过程中,可能会遇到各种操作报错。以下是一些常见的报错情况及其可能的原因和解决方法。
23 1
|
21小时前
|
SQL 数据管理 API
数据管理DMS产品使用合集之阿里云DMS提供API接口来进行数据导出功能吗
阿里云数据管理DMS提供了全面的数据管理、数据库运维、数据安全、数据迁移与同步等功能,助力企业高效、安全地进行数据库管理和运维工作。以下是DMS产品使用合集的详细介绍。
|
21小时前
|
运维 Serverless API
Serverless 应用引擎产品使用之在阿里函数计算中开启函数计算 API 接口如何解决
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
122 6
|
21小时前
|
前端开发 Java 测试技术
IDEA 版 API 接口神器来了,一键生成文档,贼香!
IDEA 版 API 接口神器来了,一键生成文档,贼香!
69 0
|
21小时前
|
API 开发者
邮件API接口使用的方法和步骤
AOKSEND指南:了解和使用邮件API接口,包括选择适合的接口(如AOKSEND、Mailgun、SMTP),获取访问权限,配置发件人、收件人及邮件内容,调用接口发送邮件,并处理返回结果,以高效集成邮件功能。

热门文章

最新文章