微信XML格式兼容

跳转到: 导航, 搜索

微博消息推送服务完全兼容“微信XML格式”,以方便基于微信公众平台做了开发的第三方能够更为顺畅得迁移; 第三方可以通过http://open.weibo.com/wiki/Eps/push/set_format 接口来选择自己需要的格式是XML还是JSON;

目录

接收消息

text消息的XML格式

<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>
返回值说明
XML参数 在JSON格式中对应的参数 说明描述
ToUserName receiver_id 消息的接收者
FromUserName sender_id 消息的发送者
CreateTime created_at 消息创建时间
MsgType type text
Content text 私信内容
MsgId 暂无对应字段 该字段内容为空

image消息的XML格式

<xml>
 <ToUserName><![CDATA[toUser]]></ToUserName>
 <FromUserName><![CDATA[fromUser]]></FromUserName>
 <CreateTime>1348831860</CreateTime>
 <MsgType><![CDATA[image]]></MsgType>
 <PicUrl><![CDATA[this is a url]]></PicUrl>
 <MediaId><![CDATA[media_id]]></MediaId>
 <MsgId>1234567890123456</MsgId>
 </xml>
返回值说明
XML参数 在JSON格式中对应的参数 说明描述
ToUserName receiver_id 消息的接收者
FromUserName sender_id 消息的发送者
CreateTime created_at 消息创建时间
MsgType type image
PicUrl 无对应字段 该字段内容为空
MediaID data:tovfid 私信内容
MsgId 暂无对应字段 该字段为空

voice消息的XML格式

<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1357290913</CreateTime>
<MsgType><![CDATA[voice]]></MsgType>
<MediaId><![CDATA[media_id]]></MediaId>
<Format><![CDATA[Format]]></Format>
<MsgId>1234567890123456</MsgId>
</xml>
返回值说明
XML参数 在JSON格式中对应的参数 说明描述
ToUserName receiver_id 消息的接收者
FromUserName sender_id 消息的发送者
CreateTime created_at 消息创建时间
MsgType type voice
PicUrl 无对应字段 该字段内容为空
MediaID data:tovfid 私信内容
Format 暂无对应字段 该字段为空
MsgId 暂无对应字段 该字段为空

position消息的XML格式

<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[位置信息]]></Label>
<MsgId>1234567890123456</MsgId>
</xml>
返回值说明
XML参数 在JSON格式中对应的参数 说明描述
ToUserName receiver_id 消息的接收者
FromUserName sender_id 消息的发送者
CreateTime created_at 消息创建时间
MsgType type position
Location_X data:latitude 纬度
Location_Y data:longitude 经度
Scale 暂无对应字段 该字段为空
Label 暂无对应字段 该字段为空
MsgId 暂无对应字段 该字段为空

关注/取消关注,订阅/取消订阅消息的XML格式

<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[FromUser]]></FromUserName>
<CreateTime>123456789</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[subscribe]]></Event>
</xml>
返回值说明
XML参数 在JSON格式中对应的参数 说明描述
ToUserName receiver_id 消息的接收者
FromUserName sender_id 消息的发送者
CreateTime created_at 消息创建时间
MsgType type event
Event data:subtype follow:关注事件,unfollow取消关注事件,subscribe订阅事件,unsubscribe订阅事件。

扫描带参数二维码事件的XML格式

用户扫描带场景值二维码时,可能推送以下两种事件: 如果用户还未关注二维码生成方的官方账号,则扫描后进入关注列表;如果用户点击关注,则微博会给第三方推送scan_follow事件;

<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[FromUser]]></FromUserName>
<CreateTime>123456789</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[subscribe]]></Event>
<EventKey><![CDATA[qrscene_123123]]></EventKey>
<Ticket><![CDATA[TICKET]]></Ticket>
</xml>
返回值说明
XML参数 在JSON格式中对应的参数 说明描述
ToUserName receiver_id 消息的接收者
FromUserName sender_id 消息的发送者
CreateTime created_at 消息创建时间
MsgType type event
Event data:subtype scan_follow
EventKey data:key 事件Key值,action_name为前缀,后面为二维码的scene_id值
Ticket data:ticket 二维码的ticket,可用来换取二维码图片

如果用户已经关注二维码生成方的官方账号,则扫描后进入和该官方账号的私信对话界面中,并且微博会给第三方推送scan事件;

<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[FromUser]]></FromUserName>
<CreateTime>123456789</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[SCAN]]></Event>
<EventKey><![CDATA[SCENE_VALUE]]></EventKey>
<Ticket><![CDATA[TICKET]]></Ticket>
</xml>
返回值说明
XML参数 在JSON格式中对应的参数 说明描述
ToUserName receiver_id 消息的接收者
FromUserName sender_id 消息的发送者
CreateTime created_at 消息创建时间
MsgType type event
Event data:subtype scan
EventKey data:key 事件Key值,action_name为前缀,后面为二维码的scene_id值
Ticket data:ticket 二维码的ticket,可用来换取二维码图片


自定义菜单事件推送的XML格式

<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[FromUser]]></FromUserName>
<CreateTime>123456789</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[CLICK]]></Event>
<EventKey><![CDATA[EVENTKEY]]></EventKey>
</xml>
返回值说明
XML参数 在JSON格式中对应的参数 说明描述
ToUserName receiver_id 消息的接收者
FromUserName sender_id 消息的发送者
CreateTime created_at 消息创建时间
MsgType type event
Event data:subtype click为自定义菜单点击事件,view为自定义菜单跳转链接事件。
EventKey data:key click事件时为被点击的自定义菜单的key值,view事件时为该按钮设置的url。


发送被动响应

回复text消息的XML格式

<xml>
 <ToUserName><![CDATA[toUser]]></ToUserName>
 <FromUserName><![CDATA[fromUser]]></FromUserName> 
 <CreateTime>1348831860</CreateTime>
 <MsgType><![CDATA[text]]></MsgType>
 <Content><![CDATA[this is a test]]></Content>
</xml>
参数说明
XML参数 在JSON格式中对应的参数 说明描述
ToUserName receiver_id 消息的接收者
FromUserName sender_id 消息的发送者
CreateTime created_at 消息创建时间
MsgType type text
Content data:text 私信内容;微博对于要回复的私信文本内容,要求文本大小必须小于300个汉字;如果超过300个汉字,则微博会自动截断超过部分

回复图文消息的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参数 在JSON格式中对应的参数 说明描述
ToUserName receiver_id 消息的接收者
FromUserName sender_id 消息的发送者
CreateTime created_at 消息创建时间
MsgType type articles
ArticleCount 无对应字段 该字段内容会自动忽略掉;另外微博最多支持8个图文,如果超过8个图文,则微博会自动截断超过部分;
Title articles:display_name 图文的显示名称标题,文本大小必须小于60个汉字。
Description articles:summary 图文的文字描述,文本大小必须小于300个汉字,支持空格与换行,三个或三个以上的空格、换行缩减为两个。
PicUrl articles:image 图文的图片链接,仅支持PNG、JPG类型。
Url articles:url 图文的URL地址,点击后跳转。
文档更新时间: 2014-06-03