Live/im/api/en

跳转到: 导航, 搜索
第1行: 第1行:
  
== Overview ==
+
== 概述 ==
  
  
One of the cooperation mode between weibo and the third-party that access to weibo is server-side synchronization.This mode means doing message synchronization between live interactive system of weibo and interactive system of the third-party to implement message sharing. Send message interface and pull message interface(active pull and callback pull)can synchronize third-party messages to weibo.
+
微博与接入微博的第三方合作的一种模式是“服务端同步”,即微博直播互动系统和第三方互动系统之间做消息同步,从而实现消息共享的效果。发送消息接口和拉取消息接口(主动拉取和回调拉取)提供第三方的消息同步到微博的功能。
  
== Post Comments ==
+
== 互动上行 ==
  
'''Description'''
+
'''说明'''
  
Post comment of the users to weibo live-im system.
+
直播用户上行评论接口
  
  
第17行: 第17行:
  
  
'''Support Formats'''
+
'''支持格式'''
  
 
JSON
 
JSON
第23行: 第23行:
  
  
'''Authorization'''
+
'''是否需要登录'''
  
Required. More details of login authorization, Please refer to this WIKI[http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E How to login to authorization]
+
true 登录授权方式,请参见本WIKI内的 [http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E 如何登录授权]
  
  
'''Request parameter'''
+
'''请求参数'''
  
 
{| border="1" cellspacing="0" cellpadding="0" width="100%" class="parameters" style="border-color:#CCCCCC;"
 
{| border="1" cellspacing="0" cellpadding="0" width="100%" class="parameters" style="border-color:#CCCCCC;"
 
|-
 
|-
!width="15%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Parameter field
+
!width="15%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|参数字段
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field must be selected
+
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段必选
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"| Field Type
+
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段类型
!width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field description
+
!width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段说明
{{api_args| access_token|true|string|Required parameters when using OAuth authorization mode,obtained after OAuth authorization}}
+
{{api_args| access_token|true|string|采用OAuth授权方式为必填参数,OAuth授权后获得}}
{{api_args|room_id|true|string|room id}}
+
{{api_args|room_id|true|string|房间id}}
{{api_args|ts|true|long|Timestamp(The number of milliseconds from 1970-01-01 00:00:00),cannot delay more than 2min}}
+
{{api_args|ts|true|long|时间戳(1970-01-01 00:00:00 起毫秒数),要求不得延迟2min以上}}
{{api_args|msg_type|true|int|message types, see [http://open.weibo.com/wiki/Live/im/api/en#.E6.B6.88.E6.81.AF.E7.B1.BB.E5.9E.8B message types]}}
+
{{api_args|msg_type|true|int|消息类型,参见 [http://open.weibo.com/wiki/Live/im/api#.E6.B6.88.E6.81.AF.E7.B1.BB.E5.9E.8B 消息类型]}}
{{api_args|content|true|string|Message content}}
+
{{api_args|content|true|string|消息内容}}
{{api_args|uid|true|long|sender ID}}
+
{{api_args|uid|true|long|发送者ID}}
{{api_args|nickname|true|string|Sender nickname}}
+
{{api_args|nickname|true|string|发送者昵称}}
{{api_args|avatar|true|string|sender avatar url}}
+
{{api_args|avatar|true|string|发送者头像url}}
{{api_args|sign|true|string|The result of signing all the parameters other than sign ,See [http://open.weibo.com/wiki/Live/im/api/en#.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95 signature algorithm]}}
+
{{api_args|sign|true|string|对sign之外的其他所有参数进行签名的结果 见[http://open.weibo.com/wiki/Live/im/api#.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95 签名算法]}}
{{api_args|extension|false|string|message extension field [http://open.weibo.com/wiki/Live/im/api/en#.E6.95.B0.E6.8D.AE.E7.BB.93.E6.9E.84 see] (json object format, the default is empty json object) }}
+
{{api_args|extension|false|string|消息扩展字段 [http://open.weibo.com/wiki/Live/im/api#.E6.95.B0.E6.8D.AE.E7.BB.93.E6.9E.84 参见](json object格式,默认为空json object)}}
{{api_args|offset|false|long|the time offset between sending message and the start of the live,unit:ms.If not pass, or pass the negative, do 0 process,indicating that the current message is not displayed when playing back.}}
+
{{api_args|offset|false|long|发消息的时间距离直播开始的偏移,单位ms。如果不传,或者传的是负数,做0处理,表示当前消息回放时不展示。}}
 
|}
 
|}
  
  
  
'''Return result'''
+
'''返回结果'''
  
//Successful return
+
//成功返回
 
<pre class="brush:js">
 
<pre class="brush:js">
 
{
 
{
     "error_code":0,    //0 indicates success,while others mean failed. Need to see the error message
+
     "error_code":0,    // 0表示成功 其他表示失败。需要看错误消息
 
     "error_msg":""
 
     "error_msg":""
 
}
 
}
第62行: 第62行:
  
  
//Failed to return
+
//失败返回
 
<pre class="brush:js">
 
<pre class="brush:js">
 
{
 
{
第70行: 第70行:
 
</pre>
 
</pre>
  
== Receive Comments-Pull Mode ==
+
== 互动下行—Pull方式 ==
'''Description'''
+
'''说明'''
  
This interface allows the third-party pull room messages from weibo live interactive system.After the third-party initiates the request,the interface will push the latest message in the room continuously as long as the connection is not broken.If the connection is disconnected accidentally,the message will continue to be pushed from the last disconnected position as long as the cumulative number of messages before the reconnection does not exceed the agreed threshold.
+
该接口提供第三方从微博直播互动系统拉取房间消息的功能。
 +
第三方发起该请求之后,只要不断开连接,该接口会源源不断的推回房间中最新的消息。如果连接意外断开,只要重连之前累计消息数量不超过商定的阈值,消息都会从上次断开的地方继续推送。
  
  
第81行: 第82行:
  
  
'''Support Formats'''
+
'''支持格式'''
  
 
JSON
 
JSON
  
  
'''Authorization'''
+
'''是否需要登录'''
  
Required. More details of login authorization, Please refer to this WIKI [http://open.weibo.com/wiki/OAuth/en How to log in to authorization]
+
true 登录授权方式,请参见本WIKI内的[http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E 如何登录授权]
  
  
'''Request parameter'''
+
'''请求参数'''
 
{| border="1" cellspacing="0" cellpadding="0" width="100%" class="parameters" style="border-color:#CCCCCC;"
 
{| border="1" cellspacing="0" cellpadding="0" width="100%" class="parameters" style="border-color:#CCCCCC;"
 
|-
 
|-
!width="15%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Parameter field
+
!width="15%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|参数字段
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field must be selected
+
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段必选
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field Type
+
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段类型
!width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field description
+
!width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段说明
{{api_args| access_token|true|string|Required parameters when using OAuth authorization mode,obtained after OAuth authorization}}
+
{{api_args| access_token|true|string|采用OAuth授权方式为必填参数,OAuth授权后获得}}
{{api_args|room_id|true|string|room id}}
+
{{api_args|room_id|true|string|房间id}}
 
|}
 
|}
  
'''Return Result'''
+
'''返回结果'''
 +
返回的消息以JSON的方式推送,推送的数据结构如下,每条消息是一个单独的JSON-OBJECT。
  
The return message is pushed in JSON mode, and the data structure is pushed as follows. Each message is a separate JSON-OBJECT.
+
//成功返回
 
+
//Successful return
+
 
<pre class="brush:js">
 
<pre class="brush:js">
 
{
 
{
     "error_code":0,    //0 indicates success,while others mean failed. Need to see the error message
+
     "error_code":0,    // 0表示成功 其他表示失败。需要看错误消息
 
     "error_msg":"",
 
     "error_msg":"",
 
}
 
}
 
{
 
{
     // message body. See Annex [Data structure / message body]
+
     // 消息体。见附件[数据结构/消息体]
 
}
 
}
 
{
 
{
     // message body.
+
     // 消息体
 
}
 
}
 
...
 
...
第122行: 第122行:
  
  
//Failed to return
+
//失败返回
 
<pre class="brush:js">
 
<pre class="brush:js">
 
{
 
{
第130行: 第130行:
 
</pre>
 
</pre>
  
about error return values and error codes, see[http://open.weibo.com/wiki/Live/im/api/en#.E9.94.99.E8.AF.AF.E7.A0.81.E5.AE.9A.E4.B9.89 Error Code Definitions]
+
关于错误返回值与错误代码,参见 [http://open.weibo.com/wiki/Live/im/api#.E9.94.99.E8.AF.AF.E7.A0.81.E5.AE.9A.E4.B9.89 错误码定义]
  
== Receive Comments-Callback Mode ==
+
== 互动下行—Callback方式 ==
'''Description'''
+
'''说明'''
  
If the third-party uses HTTP Callback mode to accept weibo messages,the third-party needs to provide an interface similar to [send message interface]. Requires the same parameters and return values as that interface.
+
如果第三方使用的是HTTP Callback的方式接受微博消息,那么第三方也需要提供一个类似[发送消息接口]的接口。要求与那个接口使用相同的参数和返回值。
  
  
 
'''URL'''
 
'''URL'''
  
customize by the third-party
+
第三方自定义
  
  
'''Support format'''
+
'''支持格式'''
  
 
JSON
 
JSON
  
  
'''HTTP request mode'''
+
'''HTTP请求方式'''
  
 
POST
 
POST
  
  
'''Authorization'''
+
'''是否需要登录'''
  
Required. More details of login authorization, Please refer to this WIKI[http://open.weibo.com/wiki/OAuth/en How to log in to authorization]
+
true 登录授权方式,请参见本WIKI内的 [http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E 如何登录授权]
  
  
'''Request parameter'''
+
'''请求参数'''
 
{| border="1" cellspacing="0" cellpadding="0" width="100%" class="parameters" style="border-color:#CCCCCC;"
 
{| border="1" cellspacing="0" cellpadding="0" width="100%" class="parameters" style="border-color:#CCCCCC;"
 
|-
 
|-
!width="15%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Parameter field
+
!width="15%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|参数字段
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field must be selected
+
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段必选
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field Type
+
!width="10%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段类型
!width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|Field description
+
!width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段说明
{{api_args| source |true|string|AppKey applied when applying for application,When calling an interface, it represents the unique identity of the application(This parameter is not required when using OAuth authorization mode)}}
+
{{api_args| source |true|string|申请应用时分配的AppKey,调用接口时候代表应用的唯一身份(采用OAuth授权方式不需要此参数)}}
{{api_args|room_id|true|string|room id}}
+
{{api_args|room_id|true|string|房间id}}
{{api_args|ts|true|long|Timestamp(The number of milliseconds from 1970-01-01 00:00:00)}}
+
{{api_args|ts|true|long|时间戳(1970-01-01 00:00:00 起毫秒数)}}
{{api_args|msg_type|true|int|Message Type 1 - Comment Message 2 - Praise message}}
+
{{api_args|msg_type|true|int|消息类型 1 - 评论消息 2 - 点赞消息}}
{{api_args|content|true|string|Message content}}
+
{{api_args|content|true|string|消息内容}}
{{api_args|uid|true|long|sender ID}}
+
{{api_args|uid|true|long|发送者ID}}
{{api_args|nickname|true|string|sender nickname}}
+
{{api_args|nickname|true|string|发送者昵称}}
{{api_args|avatar|true|string|sender avatar url}}
+
{{api_args|avatar|true|string|发送者头像url}}
{{api_args|sign|true|string|The result of signing all the parameters other than sign ,See[http://open.weibo.com/wiki/Live/im/api#.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95 signature algorithm]}}
+
{{api_args|sign|true|string|对sign之外的其他所有参数进行签名的结果 见[http://open.weibo.com/wiki/Live/im/api#.E7.AD.BE.E5.90.8D.E7.AE.97.E6.B3.95 签名算法]}}
{{api_args|extension|false|string|message extension field[http://open.weibo.com/wiki/Live/im/api/en#.E6.95.B0.E6.8D.AE.E7.BB.93.E6.9E.84 see](json object format, the default is empty json object)}}
+
{{api_args|extension|false|string|消息扩展字段 [http://open.weibo.com/wiki/Live/im/api#.E6.95.B0.E6.8D.AE.E7.BB.93.E6.9E.84 参见](json object格式,默认为空json object)}}
{{api_args|offset|false|long|the time offset between sending message and the start of the live,unit:ms.If not pass, or pass the negative, do 0 process,indicating that the current message is not displayed when playing back.}}
+
{{api_args|offset|false|long|发消息的时间距离直播开始的偏移,单位ms。如果不传,或者传的是负数,做0处理,表示当前消息回放时不展示。}}
 
|}
 
|}
  
  
Return result
+
返回结果
  
//Successful return
+
//成功返回
 
<pre class="brush:js">
 
<pre class="brush:js">
 
{
 
{
     "error_code":0,    //0 indicates success,while others mean failed. Need to see the error message
+
     "error_code":0,    // 0表示成功 其他表示失败。需要看错误消息
 
     "error_msg":""
 
     "error_msg":""
 
}
 
}
第190行: 第190行:
  
  
//Failed to return
+
//失败返回
 
<pre class="brush:js">
 
<pre class="brush:js">
 
{
 
{
第198行: 第198行:
 
</pre>
 
</pre>
  
== Signature Algorithm==
+
== 签名算法==
'''Input:'''
+
'''输入:'''
  
- the list of key-value pairs
+
- 键值对列表
  
- appsecret used to signature
+
- 签名时用的appsecret
  
  
'''Output:'''
+
'''输出:'''
  
Signature Result String
+
签名结果字符串
  
  
'''Algorithm:'''
+
'''算法:'''
  
- Each of the key-value pair composes a string follows key=value format,each string is sorted by the dictionary order of the key(key is not the same),then a semiangle sign "&" is used to form a string.
+
- 键值对列表的每一项按照key=value的方式组成该项的字符串,各项的字符串按照对应key的字典序排序(key不相同),然后用半角"&"符号连接形成一个字符串。
  
- The string is encoded in UTF-8 to get a byte sequence input,the secret string is encoded by UTF-8 to generate a byte sequence as the key,the byte sequence of the hash value is calculated in the form of hmac-md5,the hash-value byte sequence uses URL-safe-Base64 encoding,then take the 6th to 16th characters as the result output.
+
- 字符串按照UTF-8编码得到一个字节序列input, secret的字符串按UTF-8编码生成一个字节序列作为key,用hmac-md5的方式计算哈希值的字节序列,哈希值字节序列使用URL-safe-Base64编码,取第6到16个字符作为结果输出。
  
  
'''Algorithm Example:'''  
+
'''算法示例:'''  
  
  Assume that the input is:
+
  假设输入是:
 
  kv-pair: {"a":"1", "c":"jerry", "b":"tom"}
 
  kv-pair: {"a":"1", "c":"jerry", "b":"tom"}
 
  appsecret:  123456
 
  appsecret:  123456
  
  the concatenated string is:
+
  连接成的字符串就是:
 
  a=1&b=tom&c=jerry
 
  a=1&b=tom&c=jerry
  
 
  hmac-md5("a=1&b=tom&c=jerry",123456)
 
  hmac-md5("a=1&b=tom&c=jerry",123456)
  byte array output:[-117, -27, -78, -5, 73, 68, -64, -50, 4, 21, 16, -55, -55, -39, -31, -15]
+
  输出得到字节数组:[-117, -27, -78, -5, 73, 68, -64, -50, 4, 21, 16, -55, -55, -39, -31, -15]
  
  converted to URL-safe base64 string:i-Wy-0lEwM4EFRDJydnh8Q==
+
  转成URL-safe的base64字符串:i-Wy-0lEwM4EFRDJydnh8Q==
  take the 6th to 16th characters(initial bit is 0), contains the 6th, does not contain the 16th, a total of 10 bits:lEwM4EFRDJ
+
  取6到16位(初始位为0)子串,包含第6位,不包含第16位,共10位:lEwM4EFRDJ
  
  
'''Signature results:'''
+
'''签名结果:'''
  
 
lEwM4EFRDJ
 
lEwM4EFRDJ
  
== Data Structure ==
+
== 数据结构 ==
  
'''Message Body'''
+
'''消息体'''
 
<pre class="brush:js">
 
<pre class="brush:js">
 
{
 
{
     "room_id":string,      // room id
+
     "room_id":string,      // 房间号
     "room_sys_id": uint64, // room id (internal)
+
     "room_sys_id": uint64, // 房间ID (内部)
     "msg_type":int,        // Message type, see "Message Type Description"
+
     "msg_type":int,        // 消息类型,见“消息类型说明”
 
     "mid":long,
 
     "mid":long,
 
     "sender_info":{
 
     "sender_info":{
         // user information of the sender, see "User Information"
+
         // 发送者的用户信息,见“用户信息”
 
     },
 
     },
     "content":string,      // message content
+
     "content":string,      // 消息内容
     "extension":string,    // The extended field of the message
+
     "extension":string,    // 消息的扩展字段
     "offset": long,        // the offset of message time from the video start time,unit:ms
+
     "offset": long,        // 消息距离视频开始时间间隔,单位ms
     "created_at":long   // Timestamp,the number of milliseconds from 1970-01-01 0:00:00 GMT
+
     "created_at":long     // 时间戳,距离1970-01-01 0:00:00 GMT的毫秒数
      //If there are other fields, these fields continue here,related fields See "Additional fields for each message type"
+
    // 如果还有其他字段,这些字段在此处继续,相关字段见“各消息类型的额外字段”
 
}
 
}
  
第261行: 第261行:
 
'''extension'''
 
'''extension'''
  
For the message types 1 to 14, each kind of message will have some unique fields used to represent the business, these fields will appear in the sys field inside of the extension, the structure is as follows:
+
消息类型1~14时,各类消息会有一些该类型特有的字段用于表示一些业务,这些字段会出现在extension中的sys字段里面,结构如下:
 
<pre class="brush:js">
 
<pre class="brush:js">
 
extension = {
 
extension = {
 
     "sys": {
 
     "sys": {
         // The fields that appear here are listed in "unique additional fields to each type".If the extra field list is empty, the "sys" field may not exist
+
         // 此处出现的字段,见”各类型特有的额外字段“。如果额外字段列表为空,那么"sys"字段可以不存在。
 
     },
 
     },
     // "Other transparent fields"
+
     // "其它透传的字段"
 
}
 
}
 
</pre>
 
</pre>
  
unique additional fields to each type
+
各类型特有的额外字段
  
 
<pre class="brush:js">
 
<pre class="brush:js">
chat message,msg_type=1
+
聊天消息,msg_type=1
"msg_behavior":uint32  //the display behavior of message 0: Default 1. Barrage
+
"msg_behavior":uint32  //消息的显示行为 0:默认 1.弹幕
 
+
praise message,msg_type=2
+
点赞消息,msg_type=2
"praises_count":int    // Current total number of praise
+
"praises_count":int    // 当前总赞数
"inc_praises":long    // the number of times that users point like
+
"inc_praises":long    // 用户点赞次数
 
+
banned,msg_type=4
+
禁言,msg_type=4
"shut_info":{          // the users be banned
+
"shut_info":{          // 被禁言的用户信息
     "shutted_until":uint32  //the remaining time of the end of prohibition,unit:s
+
     "shutted_until":uint32  //禁言结束的剩余时间,单位s
     "members":[              //User list that be banned
+
     "members":[              //被禁言用户列表
 
     {
 
     {
       "uid":uint64          //the UID of the user that be banned
+
       "uid":uint64          //被禁言用户的UID
       "user_system":string  //the system that the banned user belongs to
+
       "user_system":string  //被禁言用户所属系统
 
     }
 
     }
 
   ]
 
   ]
 
}
 
}
 
+
room change,msg_type=11
+
房间变更,msg_type=11
"live_status":int      // Indicates the status of the live broadcast
+
"live_status":int      // 表示直播的状态
 
"room_info": {
 
"room_info": {
     // Room information body, see "room information"
+
     // 房间信息体,见“房间信息”
 
}
 
}
 
+
join room and exit room,msg_type=12
+
加退房间,msg_type=12
"exit_or_enter_room":int  // 0:exit 1:join
+
"exit_or_enter_room":int  // 0:退出 1:进入
 
"room_info": {
 
"room_info": {
     // Room information body, see "room information"
+
     // 房间信息体,见“房间信息”
 
}
 
}
 
+
add and delete administrator,msg_type=14
+
增加删除管理员,msg_type=14
"admin_info":{            // information of users that be added or deleted
+
"admin_info":{            // 被增加或删除的用户信息
     "uid":uint64              //UID of the administrator
+
     "uid":uint64              //管理员的UID
     "user_system":string      //the system that the administrator belongs to
+
     "user_system":string      //管理员所属系统
     "type":int              //Operation Type 1:Add 2:Delete
+
     "type":int              //操作类型 1 增加 2 删除
 
}
 
}
 
</pre>
 
</pre>
  
== Live Interface ==
+
== 直播接口 ==
Please refer to[http://open.weibo.com/wiki/Live/api live interface documentation]
+
请参考[http://open.weibo.com/wiki/Live/api 直播接口文档]
  
== Message Type ==
+
== 消息类型 ==
  
     1 - chat message
+
     1 - 聊天消息
     2 - praise message
+
     2 - 赞消息
     3 - light the anchor message
+
     3 - 点亮主播消息
     4 - banned message
+
     4 - 禁言消息
     6 - announcement message
+
     6 - 公告消息
     7 - share live messages
+
     7 - 分享直播消息
     8 - focus on the anchor message
+
     8 - 关注主播消息
     11 -live change message (any change in room status will be pushed)
+
     11 - 直播变更消息(房间的任何状态变更都会进行push)
     12 - join / exit room message
+
     12 - 加入/退出房间消息
     13 - reward message
+
     13 - 打赏消息
     14 - administrator change message
+
     14 - 管理员变更消息
     100 - customize message type
+
     100 - 自定义消息类型
  
== Error code definition ==
+
== 错误码定义 ==
 
<table class="wiki_table">
 
<table class="wiki_table">
 
<tr>
 
<tr>
<th style="width: 10%">error code</th>
+
<th style="width: 10%">错误码</th>
<th>error description</th>
+
<th>错误说明</th>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9101</td>
 
<td>9101</td>
<td>authentication failed</td>
+
<td>认证失败</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9102</td>
 
<td>9102</td>
<td>internal error</td>
+
<td>内部错误</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9103</td>
 
<td>9103</td>
<td>data format error</td>
+
<td>数据格式错误</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9104</td>
 
<td>9104</td>
<td>the message contains spam</td>
+
<td>消息内容包含垃圾信息</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9105</td>
 
<td>9105</td>
<td>already exists</td>
+
<td>已经存在</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9106</td>
 
<td>9106</td>
<td>data is not legal.the point that unlike 9103 : 9103 is the data format error, such as a int parameter should be passed but passed a string can not be resolved into int. And the current error code indicates that the data format itself is not a problem, but is an illegal data, such as ID corresponding entity does not exist.</td>
+
<td>数据不合法。与9103不同的地方在于:9103是数据格式错误, 比如int型的参数传了一个无法解析成int的字符串。而当前错误码表示数据格式本身没有问题, 但是是一个不合法的数据, 比如ID对应的实体不存在</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9107</td>
 
<td>9107</td>
<td>room is not allowed to speak</td>
+
<td>房间不允许发言</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9108</td>
 
<td>9108</td>
<td>user does not exist</td>
+
<td>用户不存在</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9109</td>
 
<td>9109</td>
<td>room does not exist</td>
+
<td>房间不存在</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9110</td>
 
<td>9110</td>
<td>token parse error</td>
+
<td>token解析错误</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9111</td>
 
<td>9111</td>
<td>room status is not correct</td>
+
<td>房间状态不正确</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9112</td>
 
<td>9112</td>
<td>the user is banned</td>
+
<td>用户被禁言</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>9113</td>
 
<td>9113</td>
<td>the current operation is not allowed</td>
+
<td>当前操作不允许</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
<td>1019</td>
 
<td>1019</td>
<td>the current operation is not supported</td>
+
<td>当前操作不支持</td>
 
</tr>
 
</tr>
 
</table>
 
</table>

2017年2月24日 (五) 16:17的版本

目录

概述

微博与接入微博的第三方合作的一种模式是“服务端同步”,即微博直播互动系统和第三方互动系统之间做消息同步,从而实现消息共享的效果。发送消息接口和拉取消息接口(主动拉取和回调拉取)提供第三方的消息同步到微博的功能。

互动上行

说明

直播用户上行评论接口


URL

https://api.weibo.com/2/liveim/message/sync.json [POST]


支持格式

JSON


是否需要登录

true 登录授权方式,请参见本WIKI内的 如何登录授权


请求参数

参数字段 字段必选 字段类型 字段说明
access_token true string 采用OAuth授权方式为必填参数,OAuth授权后获得
room_id true string 房间id
ts true long 时间戳(1970-01-01 00:00:00 起毫秒数),要求不得延迟2min以上
msg_type true int 消息类型,参见 消息类型
content true string 消息内容
uid true long 发送者ID
nickname true string 发送者昵称
avatar true string 发送者头像url
sign true string 对sign之外的其他所有参数进行签名的结果 见签名算法
extension false string 消息扩展字段 参见(json object格式,默认为空json object)
offset false long 发消息的时间距离直播开始的偏移,单位ms。如果不传,或者传的是负数,做0处理,表示当前消息回放时不展示。


返回结果

//成功返回

{
    "error_code":0,    // 0表示成功 其他表示失败。需要看错误消息
    "error_msg":""
}


//失败返回

{
    "error_code": 91XX,
    "error_msg": "xxxxxxxxx"
}

互动下行—Pull方式

说明

该接口提供第三方从微博直播互动系统拉取房间消息的功能。 第三方发起该请求之后,只要不断开连接,该接口会源源不断的推回房间中最新的消息。如果连接意外断开,只要重连之前累计消息数量不超过商定的阈值,消息都会从上次断开的地方继续推送。


URL

https://api.weibo.com/2/liveim/message/pull.stream [GET]


支持格式

JSON


是否需要登录

true 登录授权方式,请参见本WIKI内的如何登录授权


请求参数

参数字段 字段必选 字段类型 字段说明
access_token true string 采用OAuth授权方式为必填参数,OAuth授权后获得
room_id true string 房间id

返回结果 返回的消息以JSON的方式推送,推送的数据结构如下,每条消息是一个单独的JSON-OBJECT。

//成功返回

{
    "error_code":0,    // 0表示成功 其他表示失败。需要看错误消息
    "error_msg":"",
}
{
    // 消息体。见附件[数据结构/消息体]
}
{
    // 消息体
}
...


//失败返回

{
    "error_code": 91XX,
    "error_msg": "xxxxxxxxx"
}

关于错误返回值与错误代码,参见 错误码定义

互动下行—Callback方式

说明

如果第三方使用的是HTTP Callback的方式接受微博消息,那么第三方也需要提供一个类似[发送消息接口]的接口。要求与那个接口使用相同的参数和返回值。


URL

第三方自定义


支持格式

JSON


HTTP请求方式

POST


是否需要登录

true 登录授权方式,请参见本WIKI内的 如何登录授权


请求参数

参数字段 字段必选 字段类型 字段说明
source true string 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份(采用OAuth授权方式不需要此参数)
room_id true string 房间id
ts true long 时间戳(1970-01-01 00:00:00 起毫秒数)
msg_type true int 消息类型 1 - 评论消息 2 - 点赞消息
content true string 消息内容
uid true long 发送者ID
nickname true string 发送者昵称
avatar true string 发送者头像url
sign true string 对sign之外的其他所有参数进行签名的结果 见签名算法
extension false string 消息扩展字段 参见(json object格式,默认为空json object)
offset false long 发消息的时间距离直播开始的偏移,单位ms。如果不传,或者传的是负数,做0处理,表示当前消息回放时不展示。


返回结果

//成功返回

{
    "error_code":0,    // 0表示成功 其他表示失败。需要看错误消息
    "error_msg":""
}


//失败返回

{
    "error_code": 91XX,
    "error_msg": "xxxxxxxxx"
}

签名算法

输入:

- 键值对列表

- 签名时用的appsecret


输出:

签名结果字符串


算法:

- 键值对列表的每一项按照key=value的方式组成该项的字符串,各项的字符串按照对应key的字典序排序(key不相同),然后用半角"&"符号连接形成一个字符串。

- 字符串按照UTF-8编码得到一个字节序列input, secret的字符串按UTF-8编码生成一个字节序列作为key,用hmac-md5的方式计算哈希值的字节序列,哈希值字节序列使用URL-safe-Base64编码,取第6到16个字符作为结果输出。


算法示例:

假设输入是:
kv-pair: {"a":"1", "c":"jerry", "b":"tom"}
appsecret:  123456
连接成的字符串就是:
a=1&b=tom&c=jerry
hmac-md5("a=1&b=tom&c=jerry",123456)
输出得到字节数组:[-117, -27, -78, -5, 73, 68, -64, -50, 4, 21, 16, -55, -55, -39, -31, -15]
转成URL-safe的base64字符串:i-Wy-0lEwM4EFRDJydnh8Q==
取6到16位(初始位为0)子串,包含第6位,不包含第16位,共10位:lEwM4EFRDJ


签名结果:

lEwM4EFRDJ

数据结构

消息体

{
    "room_id":string,      // 房间号
    "room_sys_id": uint64, // 房间ID (内部)
    "msg_type":int,        // 消息类型,见“消息类型说明”
    "mid":long,
    "sender_info":{
        // 发送者的用户信息,见“用户信息”
    },
    "content":string,      // 消息内容
    "extension":string,    // 消息的扩展字段
    "offset": long,        // 消息距离视频开始时间间隔,单位ms
    "created_at":long      // 时间戳,距离1970-01-01 0:00:00 GMT的毫秒数
    // 如果还有其他字段,这些字段在此处继续,相关字段见“各消息类型的额外字段”
}

extension

消息类型1~14时,各类消息会有一些该类型特有的字段用于表示一些业务,这些字段会出现在extension中的sys字段里面,结构如下:

extension = {
    "sys": {
        // 此处出现的字段,见”各类型特有的额外字段“。如果额外字段列表为空,那么"sys"字段可以不存在。
    },
    // "其它透传的字段"
}

各类型特有的额外字段

聊天消息,msg_type=1
"msg_behavior":uint32  //消息的显示行为  0:默认 1.弹幕
 
点赞消息,msg_type=2
"praises_count":int    // 当前总赞数
"inc_praises":long     // 用户点赞次数
 
禁言,msg_type=4
"shut_info":{          // 被禁言的用户信息
    "shutted_until":uint32  //禁言结束的剩余时间,单位s
    "members":[              //被禁言用户列表
     {
       "uid":uint64          //被禁言用户的UID
       "user_system":string  //被禁言用户所属系统
     }
   ]
}
 
房间变更,msg_type=11
"live_status":int      // 表示直播的状态
"room_info": {
    // 房间信息体,见“房间信息”
}
 
加退房间,msg_type=12
"exit_or_enter_room":int  // 0:退出 1:进入
"room_info": {
    // 房间信息体,见“房间信息”
}
 
增加删除管理员,msg_type=14
"admin_info":{            // 被增加或删除的用户信息
    "uid":uint64              //管理员的UID
    "user_system":string      //管理员所属系统
    "type":int               //操作类型 1 增加 2 删除
}

直播接口

请参考直播接口文档

消息类型

   1 - 聊天消息
   2 - 赞消息
   3 - 点亮主播消息
   4 - 禁言消息
   6 - 公告消息
   7 - 分享直播消息
   8 - 关注主播消息
   11 - 直播变更消息(房间的任何状态变更都会进行push)
   12 - 加入/退出房间消息
   13 - 打赏消息
   14 - 管理员变更消息
   100 - 自定义消息类型

错误码定义

错误码 错误说明
9101 认证失败
9102 内部错误
9103 数据格式错误
9104 消息内容包含垃圾信息
9105 已经存在
9106 数据不合法。与9103不同的地方在于:9103是数据格式错误, 比如int型的参数传了一个无法解析成int的字符串。而当前错误码表示数据格式本身没有问题, 但是是一个不合法的数据, 比如ID对应的实体不存在
9107 房间不允许发言
9108 用户不存在
9109 房间不存在
9110 token解析错误
9111 房间状态不正确
9112 用户被禁言
9113 当前操作不允许
1019 当前操作不支持