Live/im/api/en
第1行: | 第1行: | ||
− | == | + | == 概述 == |
− | + | 微博与接入微博的第三方合作的一种模式是“服务端同步”,即微博直播互动系统和第三方互动系统之间做消息同步,从而实现消息共享的效果。发送消息接口和拉取消息接口(主动拉取和回调拉取)提供第三方的消息同步到微博的功能。 | |
− | == | + | == 互动上行 == |
− | ''' | + | '''说明''' |
− | + | 直播用户上行评论接口 | |
第17行: | 第17行: | ||
− | ''' | + | '''支持格式''' |
JSON | JSON | ||
第23行: | 第23行: | ||
− | ''' | + | '''是否需要登录''' |
− | + | 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 如何登录授权] | |
− | ''' | + | '''请求参数''' |
{| 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"| | + | !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"| | + | !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"| | + | !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"| | + | !width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段说明 |
− | {{api_args| access_token|true|string| | + | {{api_args| access_token|true|string|采用OAuth授权方式为必填参数,OAuth授权后获得}} |
− | {{api_args|room_id|true|string| | + | {{api_args|room_id|true|string|房间id}} |
− | {{api_args|ts|true|long| | + | {{api_args|ts|true|long|时间戳(1970-01-01 00:00:00 起毫秒数),要求不得延迟2min以上}} |
− | {{api_args|msg_type|true|int| | + | {{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| | + | {{api_args|content|true|string|消息内容}} |
− | {{api_args|uid|true|long| | + | {{api_args|uid|true|long|发送者ID}} |
− | {{api_args|nickname|true|string| | + | {{api_args|nickname|true|string|发送者昵称}} |
− | {{api_args|avatar|true|string| | + | {{api_args|avatar|true|string|发送者头像url}} |
− | {{api_args|sign|true|string| | + | {{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| | + | {{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| | + | {{api_args|offset|false|long|发消息的时间距离直播开始的偏移,单位ms。如果不传,或者传的是负数,做0处理,表示当前消息回放时不展示。}} |
|} | |} | ||
− | ''' | + | '''返回结果''' |
− | // | + | //成功返回 |
<pre class="brush:js"> | <pre class="brush:js"> | ||
{ | { | ||
− | "error_code":0, // | + | "error_code":0, // 0表示成功 其他表示失败。需要看错误消息 |
"error_msg":"" | "error_msg":"" | ||
} | } | ||
第62行: | 第62行: | ||
− | // | + | //失败返回 |
<pre class="brush:js"> | <pre class="brush:js"> | ||
{ | { | ||
第70行: | 第70行: | ||
</pre> | </pre> | ||
− | == | + | == 互动下行—Pull方式 == |
− | ''' | + | '''说明''' |
− | + | 该接口提供第三方从微博直播互动系统拉取房间消息的功能。 | |
+ | 第三方发起该请求之后,只要不断开连接,该接口会源源不断的推回房间中最新的消息。如果连接意外断开,只要重连之前累计消息数量不超过商定的阈值,消息都会从上次断开的地方继续推送。 | ||
第81行: | 第82行: | ||
− | ''' | + | '''支持格式''' |
JSON | JSON | ||
− | ''' | + | '''是否需要登录''' |
− | + | 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 如何登录授权] | |
− | ''' | + | '''请求参数''' |
{| 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"| | + | !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"| | + | !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"| | + | !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"| | + | !width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段说明 |
− | {{api_args| access_token|true|string| | + | {{api_args| access_token|true|string|采用OAuth授权方式为必填参数,OAuth授权后获得}} |
− | {{api_args|room_id|true|string| | + | {{api_args|room_id|true|string|房间id}} |
|} | |} | ||
− | ''' | + | '''返回结果''' |
+ | 返回的消息以JSON的方式推送,推送的数据结构如下,每条消息是一个单独的JSON-OBJECT。 | ||
− | + | //成功返回 | |
− | + | ||
− | // | + | |
<pre class="brush:js"> | <pre class="brush:js"> | ||
{ | { | ||
− | "error_code":0, // | + | "error_code":0, // 0表示成功 其他表示失败。需要看错误消息 |
"error_msg":"", | "error_msg":"", | ||
} | } | ||
{ | { | ||
− | // | + | // 消息体。见附件[数据结构/消息体] |
} | } | ||
{ | { | ||
− | // | + | // 消息体 |
} | } | ||
... | ... | ||
第122行: | 第122行: | ||
− | // | + | //失败返回 |
<pre class="brush:js"> | <pre class="brush:js"> | ||
{ | { | ||
第130行: | 第130行: | ||
</pre> | </pre> | ||
− | + | 关于错误返回值与错误代码,参见 [http://open.weibo.com/wiki/Live/im/api#.E9.94.99.E8.AF.AF.E7.A0.81.E5.AE.9A.E4.B9.89 错误码定义] | |
− | == | + | == 互动下行—Callback方式 == |
− | ''' | + | '''说明''' |
− | + | 如果第三方使用的是HTTP Callback的方式接受微博消息,那么第三方也需要提供一个类似[发送消息接口]的接口。要求与那个接口使用相同的参数和返回值。 | |
'''URL''' | '''URL''' | ||
− | + | 第三方自定义 | |
− | ''' | + | '''支持格式''' |
JSON | JSON | ||
− | ''' | + | '''HTTP请求方式''' |
POST | POST | ||
− | ''' | + | '''是否需要登录''' |
− | + | 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 如何登录授权] | |
− | ''' | + | '''请求参数''' |
{| 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"| | + | !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"| | + | !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"| | + | !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"| | + | !width="65%" style="text-align:left;padding-left:5px;font-weight:bolder;border:1px solid #cccccc"|字段说明 |
− | {{api_args| source |true|string| | + | {{api_args| source |true|string|申请应用时分配的AppKey,调用接口时候代表应用的唯一身份(采用OAuth授权方式不需要此参数)}} |
− | {{api_args|room_id|true|string| | + | {{api_args|room_id|true|string|房间id}} |
− | {{api_args|ts|true|long| | + | {{api_args|ts|true|long|时间戳(1970-01-01 00:00:00 起毫秒数)}} |
− | {{api_args|msg_type|true|int| | + | {{api_args|msg_type|true|int|消息类型 1 - 评论消息 2 - 点赞消息}} |
− | {{api_args|content|true|string| | + | {{api_args|content|true|string|消息内容}} |
− | {{api_args|uid|true|long| | + | {{api_args|uid|true|long|发送者ID}} |
− | {{api_args|nickname|true|string| | + | {{api_args|nickname|true|string|发送者昵称}} |
− | {{api_args|avatar|true|string| | + | {{api_args|avatar|true|string|发送者头像url}} |
− | {{api_args|sign|true|string| | + | {{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| | + | {{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| | + | {{api_args|offset|false|long|发消息的时间距离直播开始的偏移,单位ms。如果不传,或者传的是负数,做0处理,表示当前消息回放时不展示。}} |
|} | |} | ||
− | + | 返回结果 | |
− | // | + | //成功返回 |
<pre class="brush:js"> | <pre class="brush:js"> | ||
{ | { | ||
− | "error_code":0, // | + | "error_code":0, // 0表示成功 其他表示失败。需要看错误消息 |
"error_msg":"" | "error_msg":"" | ||
} | } | ||
第190行: | 第190行: | ||
− | // | + | //失败返回 |
<pre class="brush:js"> | <pre class="brush:js"> | ||
{ | { | ||
第198行: | 第198行: | ||
</pre> | </pre> | ||
− | == | + | == 签名算法== |
− | ''' | + | '''输入:''' |
− | - | + | - 键值对列表 |
− | - | + | - 签名时用的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"} | kv-pair: {"a":"1", "c":"jerry", "b":"tom"} | ||
appsecret: 123456 | appsecret: 123456 | ||
− | + | 连接成的字符串就是: | |
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) | ||
− | + | 输出得到字节数组:[-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 | lEwM4EFRDJ | ||
− | == | + | == 数据结构 == |
− | ''' | + | '''消息体''' |
<pre class="brush:js"> | <pre class="brush:js"> | ||
{ | { | ||
− | "room_id":string, // | + | "room_id":string, // 房间号 |
− | "room_sys_id": uint64, // | + | "room_sys_id": uint64, // 房间ID (内部) |
− | "msg_type":int, // | + | "msg_type":int, // 消息类型,见“消息类型说明” |
"mid":long, | "mid":long, | ||
"sender_info":{ | "sender_info":{ | ||
− | // | + | // 发送者的用户信息,见“用户信息” |
}, | }, | ||
− | "content":string, // | + | "content":string, // 消息内容 |
− | "extension":string, // | + | "extension":string, // 消息的扩展字段 |
− | "offset": long, // | + | "offset": long, // 消息距离视频开始时间间隔,单位ms |
− | "created_at":long | + | "created_at":long // 时间戳,距离1970-01-01 0:00:00 GMT的毫秒数 |
− | + | // 如果还有其他字段,这些字段在此处继续,相关字段见“各消息类型的额外字段” | |
} | } | ||
第261行: | 第261行: | ||
'''extension''' | '''extension''' | ||
− | + | 消息类型1~14时,各类消息会有一些该类型特有的字段用于表示一些业务,这些字段会出现在extension中的sys字段里面,结构如下: | |
<pre class="brush:js"> | <pre class="brush:js"> | ||
extension = { | extension = { | ||
"sys": { | "sys": { | ||
− | // | + | // 此处出现的字段,见”各类型特有的额外字段“。如果额外字段列表为空,那么"sys"字段可以不存在。 |
}, | }, | ||
− | // " | + | // "其它透传的字段" |
} | } | ||
</pre> | </pre> | ||
− | + | 各类型特有的额外字段 | |
<pre class="brush:js"> | <pre class="brush:js"> | ||
− | + | 聊天消息,msg_type=1 | |
− | "msg_behavior":uint32 // | + | "msg_behavior":uint32 //消息的显示行为 0:默认 1.弹幕 |
− | + | ||
− | + | 点赞消息,msg_type=2 | |
− | "praises_count":int // | + | "praises_count":int // 当前总赞数 |
− | "inc_praises":long // | + | "inc_praises":long // 用户点赞次数 |
− | + | ||
− | + | 禁言,msg_type=4 | |
− | "shut_info":{ // | + | "shut_info":{ // 被禁言的用户信息 |
− | "shutted_until":uint32 // | + | "shutted_until":uint32 //禁言结束的剩余时间,单位s |
− | "members":[ // | + | "members":[ //被禁言用户列表 |
{ | { | ||
− | "uid":uint64 // | + | "uid":uint64 //被禁言用户的UID |
− | "user_system":string // | + | "user_system":string //被禁言用户所属系统 |
} | } | ||
] | ] | ||
} | } | ||
− | + | ||
− | + | 房间变更,msg_type=11 | |
− | "live_status":int // | + | "live_status":int // 表示直播的状态 |
"room_info": { | "room_info": { | ||
− | // | + | // 房间信息体,见“房间信息” |
} | } | ||
− | + | ||
− | + | 加退房间,msg_type=12 | |
− | "exit_or_enter_room":int // 0: | + | "exit_or_enter_room":int // 0:退出 1:进入 |
"room_info": { | "room_info": { | ||
− | // | + | // 房间信息体,见“房间信息” |
} | } | ||
− | + | ||
− | + | 增加删除管理员,msg_type=14 | |
− | "admin_info":{ // | + | "admin_info":{ // 被增加或删除的用户信息 |
− | "uid":uint64 // | + | "uid":uint64 //管理员的UID |
− | "user_system":string // | + | "user_system":string //管理员所属系统 |
− | "type":int // | + | "type":int //操作类型 1 增加 2 删除 |
} | } | ||
</pre> | </pre> | ||
− | == | + | == 直播接口 == |
− | + | 请参考[http://open.weibo.com/wiki/Live/api 直播接口文档] | |
− | == | + | == 消息类型 == |
− | 1 - | + | 1 - 聊天消息 |
− | 2 - | + | 2 - 赞消息 |
− | 3 - | + | 3 - 点亮主播消息 |
− | 4 - | + | 4 - 禁言消息 |
− | 6 - | + | 6 - 公告消息 |
− | 7 - | + | 7 - 分享直播消息 |
− | 8 - | + | 8 - 关注主播消息 |
− | 11 - | + | 11 - 直播变更消息(房间的任何状态变更都会进行push) |
− | 12 - | + | 12 - 加入/退出房间消息 |
− | 13 - | + | 13 - 打赏消息 |
− | 14 - | + | 14 - 管理员变更消息 |
− | 100 - | + | 100 - 自定义消息类型 |
− | == | + | == 错误码定义 == |
<table class="wiki_table"> | <table class="wiki_table"> | ||
<tr> | <tr> | ||
− | <th style="width: 10%"> | + | <th style="width: 10%">错误码</th> |
− | <th> | + | <th>错误说明</th> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9101</td> | <td>9101</td> | ||
− | <td> | + | <td>认证失败</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9102</td> | <td>9102</td> | ||
− | <td> | + | <td>内部错误</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9103</td> | <td>9103</td> | ||
− | <td> | + | <td>数据格式错误</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9104</td> | <td>9104</td> | ||
− | <td> | + | <td>消息内容包含垃圾信息</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9105</td> | <td>9105</td> | ||
− | <td> | + | <td>已经存在</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9106</td> | <td>9106</td> | ||
− | <td> | + | <td>数据不合法。与9103不同的地方在于:9103是数据格式错误, 比如int型的参数传了一个无法解析成int的字符串。而当前错误码表示数据格式本身没有问题, 但是是一个不合法的数据, 比如ID对应的实体不存在</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9107</td> | <td>9107</td> | ||
− | <td> | + | <td>房间不允许发言</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9108</td> | <td>9108</td> | ||
− | <td> | + | <td>用户不存在</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9109</td> | <td>9109</td> | ||
− | <td> | + | <td>房间不存在</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9110</td> | <td>9110</td> | ||
− | <td> | + | <td>token解析错误</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9111</td> | <td>9111</td> | ||
− | <td> | + | <td>房间状态不正确</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9112</td> | <td>9112</td> | ||
− | <td> | + | <td>用户被禁言</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>9113</td> | <td>9113</td> | ||
− | <td> | + | <td>当前操作不允许</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>1019</td> | <td>1019</td> | ||
− | <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 | 当前操作不支持 |