接收普通消息

跳转到: 导航, 搜索
第9行: 第9行:
  
  
==纯文本消息==
+
==纯文本类型私信消息==
  
 
+
纯文本类型私信消息JSON格式如下:
 
+
<h3>纯文本类型私信和留言消息:text</h3>
+
 
<pre>
 
<pre>
 
{
 
{
第59行: 第57行:
  
  
<h3>位置类型私信消息:position</h3>
+
 
 +
==位置类型私信消息==
 +
 
 +
位置类型私信消息JSON格式如下:
 
<pre>
 
<pre>
 
{
 
{
第115行: 第116行:
 
|}
 
|}
  
 +
==语音类型私信消息==
  
<h3>语音类型私信和留言消息:voice</h3>
+
语音类型私信消息JSON格式如下:
 
<pre>
 
<pre>
 
{
 
{
第187行: 第189行:
  
  
<h3>图片类型私信和留言消息:image</h3>
+
==图片类型私信消息==
 +
 
 +
图片类型私信消息JSON格式如下:
 
<pre>
 
<pre>
 
{
 
{
第249行: 第253行:
 
2,"TOVFID":返回结果data字段中的tovfid。
 
2,"TOVFID":返回结果data字段中的tovfid。
 
</pre>
 
</pre>
 
==接收事件推送==
 
 
建立首次连接后,当认证用户有新消息时,微博消息推送服务会POST消息数据包到开发者填写的URL上,当前支持的事件类型:
 
 
<h3>事件消息:event</h3>
 
<pre>
 
{
 
    "type": "event",
 
    "receiver_id": 1902538057,
 
    "sender_id": 2489518277,
 
    "created_at": "Mon Jul 16 18:09:20 +0800 2012",
 
    "text": "事件消息",
 
    "data": {
 
        "subtype": "EVENT",
 
        "key": "EVENT_KEY",
 
        "ticket": "TICKET",
 
    }
 
}
 
</pre>
 
<div class="wiki_kit">
 
 
{|width="100%" border="0" cellspacing="0" cellpadding="0" class="wiki_table"
 
<html><colgroup><col class="tbF1"/><col class="tbF2" /><col /></colgroup></html>
 
!colspan="3" scope="col" |<span id="返回值说明">返回值说明</span>
 
|-
 
|style="text-align:center; width: 12%"|属性
 
|style="text-align:center;width: 12%"|值的类型
 
|style="text-align:center;"|说明描述
 
|-
 
|type
 
|string
 
|event
 
|-
 
|receiver_id
 
|int64
 
|消息的接收者
 
|-
 
|sender_id
 
|int64
 
|消息的发送者
 
|-
 
|created_at
 
|string
 
|消息创建时间
 
|-
 
|text
 
|string
 
|默认文案。subtype为follow或unfollow时分别为“关注事件消息”、“取消关注事件消息”;为subscribe或unsubscribe时为触发订阅的私信关键词(如“dy”),非私信触发时(点击订阅按钮)为“订阅事件消息”、“取消订阅事件消息”;subtype为scan或scan_follow时为“扫描二维码”;
 
|-
 
|data
 
|string
 
|消息内容
 
|-
 
|data:subtype
 
|string
 
|follow:关注事件,unfollow取消关注事件,subscribe订阅事件,unsubscribe订阅事件。scan和scan_follow为二维码扫描事件。
 
|-
 
|data:key
 
|string
 
|subtype为follow、unfollow、subscribe或unsubscribe时不返回
 
|-
 
|data:ticket
 
|string
 
|subtype为scan和scan_follow时才返回
 
|}
 
 
<h3>被@消息:mention</h3>
 
说明:指定的认证用户需被授予接收“被@消息”权限,此接口才返回“被@消息”,申请可邮件 [mailto:open_api@sina.com open_api@sina.com] 。
 
<pre>
 
{
 
    "type": "mention",
 
    "receiver_id": 1902538057,
 
    "sender_id": 2489518277,
 
    "created_at": "Mon Jul 16 18:09:20 +0800 2012",
 
    "text": "被@的微博或评论文本信息",
 
    "data": {
 
        "subtype": "MENTION_TYPE,
 
        "key": "MENTION_KEY"
 
    }
 
}
 
 
// 默认仅返回可信用户的@,如需返回所有用户@,认证用户可访问此链接设置:http://account.weibo.com/set/message
 
</pre>
 
<div class="wiki_kit">
 
{|width="100%" border="0" cellspacing="0" cellpadding="0" class="wiki_table"
 
<html><colgroup><col class="tbF1"/><col class="tbF2" /><col /></colgroup></html>
 
!colspan="3" scope="col" |<span id="返回值说明">返回值说明</span>
 
|-
 
|style="text-align:center; width: 12%"|属性
 
|style="text-align:center;width: 12%"|值的类型
 
|style="text-align:center;"|说明描述
 
|-
 
|type
 
|string
 
|mention
 
|-
 
|receiver_id
 
|int64
 
|消息的接收者
 
|-
 
|sender_id
 
|int64
 
|消息的发送者
 
|-
 
|created_at
 
|string
 
|消息创建时间
 
|-
 
|text
 
|string
 
|被@的微博或评论文本信息
 
|-
 
|data
 
|string
 
|消息内容
 
|-
 
|data:subtype
 
|string
 
|status:@的微博,comment:@的评论
 
|-
 
|data:key
 
|string
 
|当subtype为status时为微博ID,为comment时为评论ID
 
|}
 
 
==发送被动响应==
 
 
对于每一个POST请求,开发者在响应包(Get)中返回特定JSON包,对该消息进行响应。微博服务器在五秒内收不到响应会断掉连接,并且重新发起请求,总共重试三次; 关于重试的消息排重,推荐使用消息ID排重。
 
 
假如开发者无法保证在五秒内处理并回复,可以直接回复空串,微博服务器不会对此作任何处理,并且不会发起重试。
 
 
如果发送被动响应消息,则返回JSON格式如下:
 
注意:JSON格式中的data字段内容必须进行UTF8格式的URLEncode
 
<pre class="brush:js">
 
{
 
    "result": true,
 
    "receiver_id":123456,
 
    "sender_id":123123,
 
    "tpye": "text",
 
    "data":"{}"
 
}
 
</pre>
 
 
 
 
当前支持回复的私信类型(type)中,data参数支持的参数:
 
 
<h3> 纯文本类型私信消息:text</h3>
 
<pre>
 
{
 
    "text": "纯文本回复"
 
}
 
</pre>
 
 
<div class="wiki_kit">
 
 
{|width="100%" border="0" cellspacing="0" cellpadding="0" class="wiki_table"
 
<html><colgroup><col class="tbF1"/><col class="tbF2" /><col /></colgroup></html>
 
!colspan="4" scope="col" |<span id="data参数支持的参数">data参数支持的参数</span>
 
|-
 
|style="text-align:center; width: 12%"|参数名称
 
|style="text-align:center;width: 12%"|值的类型
 
|style="text-align:center;width: 11%"|是否必填
 
|style="text-align:center;"|说明描述
 
|-
 
|text
 
|string
 
|true
 
|要回复的私信文本内容。文本大小必须小于300个汉字。
 
|}
 
举例:
 
当data对应json为{"text": "纯文本响应"} 时,则进行URLEncode后对应data参数值为:"%7B%22text%22%3A%20%22%E7%BA%AF%E6%96%87%E6%9C%AC%E5%93%8D%E5%BA%94%22%7D%20"。
 
 
<h3>图文类型私信消息:articles</h3>
 
<pre>
 
{
 
    "articles": [
 
        {
 
            "display_name": "两个故事",
 
            "summary": "今天讲两个故事,分享给你。谁是公司?谁又是中国人?​",
 
            "image": "http://storage.mcp.weibo.cn/0JlIv.jpg",
 
            "url": "http://e.weibo.com/mediaprofile/article/detail?uid=1722052204&aid=983319"
 
        },
 
        ... //最多支持8个图文,建议为1或3个
 
    ]
 
}
 
</pre>
 
 
 
<div class="wiki_kit">
 
{|width="100%" border="0" cellspacing="0" cellpadding="0" class="wiki_table"
 
<html><colgroup><col class="tbF1"/><col class="tbF2" /><col /></colgroup></html>
 
!colspan="4" scope="col" |<span id="data参数支持的参数">data参数支持的参数</span>
 
|-
 
|style="text-align:center; width: 12%"|参数名称
 
|style="text-align:center;width: 12%"|值的类型
 
|style="text-align:center;width: 11%"|是否必填
 
|style="text-align:center;"|说明描述
 
|-
 
|articles:display_name
 
|string
 
|true
 
|图文的显示名称标题
 
|-
 
|articles:summary
 
|string
 
|true
 
|图文的文字描述,大于等于2个图文时,仅显示第一个图文的描述
 
|-
 
|articles:image
 
|string
 
|true
 
|图文的缩略显示图片,需为JPG、PNG格式,单图及多图第一张推荐使用280*155,多图非第一张推荐使用64*64
 
|-
 
|articles:url
 
|string
 
|true
 
|图文的URL地址,点击后跳转
 
|}
 
 
 
<h3>位置类型私信消息:position </h3>
 
<pre>
 
{
 
    "longitude": "116.308586",
 
    "latitude": "39.982525"
 
}
 
</pre>
 
 
 
<div class="wiki_kit">
 
{|width="100%" border="0" cellspacing="0" cellpadding="0" class="wiki_table"
 
<html><colgroup><col class="tbF1"/><col class="tbF2" /><col /></colgroup></html>
 
!colspan="4" scope="col" |<span id="data参数支持的参数">data参数支持的参数</span>
 
|-
 
|style="text-align:center; width: 12%"|参数名称
 
|style="text-align:center;width: 12%"|值的类型
 
|style="text-align:center;width: 11%"|是否必填
 
|style="text-align:center;"|说明描述
 
|-
 
|longitude
 
|string
 
|true
 
|经度
 
|-
 
|latitude
 
|string
 
|true
 
|纬度
 
|}
 

2014年4月20日 (日) 14:57的版本

建立首次连接后,当认证用户有新消息时,微博消息推送服务会POST消息数据包到开发者填写的URL上,当前支持的普通消息类型包括: (注意:需要对接收到的消息体type或subtype做兼容,当出现未知类型时可忽略此消息。)

对于每一个POST请求,开发者在响应包(Get)中返回特定JSON包,对该消息进行响应。微博服务器在五秒内收不到响应会断掉连接,并且重新发起请求,总共重试三次;

关于重试的消息排重,目前微博消息排重推荐使用消息ID排重。

假如开发者无法保证在五秒内处理并回复,可以直接回复空串,微博服务器不会对此作任何处理,并且不会发起重试。


目录

纯文本类型私信消息

纯文本类型私信消息JSON格式如下:

{
    "type": "text",
    "receiver_id": 1902538057,
    "sender_id": 2489518277,
    "created_at": "Mon Jul 16 18:09:20 +0800 2012",
    "text": "私信或留言内容",
    "data": {}
}
返回值说明
属性 值的类型 说明描述
type string text
receiver_id int64 消息的接收者
sender_id int64 消息的发送者
created_at string 消息创建时间
text string 私信内容
data string 消息内容,纯文本私信或留言为空


位置类型私信消息

位置类型私信消息JSON格式如下:

{
    "type": "position",
    "receiver_id": 1902538057,
    "sender_id": 2489518277,
    "created_at": "Mon Jul 16 18:09:20 +0800 2012",
    "text": "我在这里: http://t.cn/zQgLLYO",
    "data": {
        "longitude": "116.308586",
        "latitude": "39.982525"
      }
}
返回值说明
属性 值的类型 说明描述
type string mention
receiver_id int64 消息的接收者
sender_id int64 消息的发送者
created_at string 消息创建时间
text string 原位置私信文本,没有时用默认文案“发送了一个位置”
data string 消息内容
data:longitude string 经度
data:latitude string 纬度

语音类型私信消息

语音类型私信消息JSON格式如下:

{
    "id": 1211260020031347,
    "type": "voice",
    "receiver_id": 1902538057,
    "sender_id": 2489518277,
    "created_at": "Mon Jul 16 18:09:20 +0800 2012",
    "text": "发了一个语音消息",
    "data": {
        "vfid": 821804459,    // 发送者用此ID查看语音
        "tovfid": 821804469  // 接收者用此ID查看语音
    }
}
返回值说明
属性 值的类型 说明描述
type string voice
receiver_id int64 消息的接收者
sender_id int64 消息的发送者
created_at string 消息创建时间
text string 私信内容
data string 消息内容,纯文本私信或留言为空
data:vfid string 语音文件ID,发送者通过此ID读取语音
data:tovfid string 语音文件ID,接收者通过此ID读取语音
查看(下载)认证用户接收到的语音方法一
curl "https://upload.api.weibo.com/2/mss/msget?access_token=RECIPIENT_ACCESS_TOKEN&fid=TOVFID"

1,"RECIPIENT_ACCESS_TOKEN":返回结果中接收者(recipient_id)通过OAuth2授权返回的access_token;
2,"TOVFID":返回结果data字段中的tovfid。

查看(下载)认证用户接收到的语音方法二
curl -u "USERNAME:PASSWORD" "https://upload.api.weibo.com/2/mss/msget?source=APPKEY&fid=TOVFID"

1,"USERNAME:PASSWORD"为"recipient_id"(认证用户)的微博登录用户名和密码,此时方法二中的APPKEY应用所有者为"recipient_id";
2,"TOVFID":返回结果data字段中的tovfid。


图片类型私信消息

图片类型私信消息JSON格式如下:

{
    "type": "image",
    "receiver_id": 1902538057,
    "sender_id": 2489518277,
    "created_at": "Mon Jul 16 18:09:20 +0800 2012",
    "text": "发了一张图片",
    "data": {
        "vfid": 821804459,     // 发送者用此ID查看图片
        "tovfid": 821804469    // 接收者用此ID查看图片
    }
}
返回值说明
属性 值的类型 说明描述
type string image
receiver_id int64 消息的接收者
sender_id int64 消息的发送者
created_at string 消息创建时间
text string 私信内容
data string 消息内容,纯文本私信或留言为空
data:vfid string 图片ID,发送者通过此ID读取图片
data:tovfid string 图片ID,接收者通过此ID读取图片
查看(下载)图片
curl "https://upload.api.weibo.com/2/mss/msget?access_token=RECIPIENT_ACCESS_TOKEN&fid=TOVFID"

1,"RECIPIENT_ACCESS_TOKEN":返回结果中接收者(receiver_id)通过OAuth2授权返回的access_token;
2,"TOVFID":返回结果data字段中的tovfid。