分页获取聊天室信息
更新时间:2022-05-23 14:30:29
接口URL
http://api.polyv.net/live/v2/chat/{channelId}/getHistoryByPage
接口说明
1、作用:查询一段时间内的聊天记录,时间格式为yyyy-MM-dd 或 yyyy-MM-dd HH:mm:ss。
如未提交具体时间,只提交了日期,开始时间默认为日期当天的 00:00:00,结束时间为日期当天的23:59:59
2、接口支持https协议
3、接口URL中的{channelId}为 频道ID
支持格式
JSON
请求方式
POST,GET
请求参数
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| startDay | 是 | String | 聊天记录的开始时间,格式要求为yyyy-MM-dd(如:2017-08-01)或者 yyyy-MM-dd HH:mm:ss (如:2017-08-01 16:30:12) |
| endDay | 是 | string | 聊天记录的结束时间,要求同上 |
| appId | 是 | string | 从API设置中获取,在直播系统登记的appId |
| page | 否 | int | 获取第几页聊天记录,默认为1 |
| limit | 否 | int | 每页记录数,默认为1000 |
| timestamp | 是 | string | 当前13位毫秒级时间戳,3分钟内有效 |
| sign | 是 | string | 签名,32位大写MD5值 |
| userType | 否 | string | 用户类型,可以选择多个类型,用英文逗号隔开 |
响应成功JSON示例
{
"code": 200,
"data": {
"list": [
{
"clientIP": "",
"content": "ss",
"event": "0",
"id": "29451af0-e936-11e7-b267-81b6b5e6b627",
"image": "",
"msyType": "0",
"roomId": "110867",
"time": 1514180448799,
"user": {
"banned": false,
"clientIp": "39.155.185.29",
"nick": "游客",
"pic": "http://www.polyv.net/images/effect/effect-device.png",
"roomId": "110867",
"uid": "P-X2nETUdWGEGmEJEqL8",
"userId": "4b6c3fba-5774-4807-a34e-bb9bc306236e",
"userType": "slice"
},
"userType": "\"slice\""
},
{
"clientIP": "",
"content": "哈哈",
"event": "0",
"id": "f812f360-e94b-11e7-b267-81b6b5e6b627",
"image": "",
"msyType": "0",
"roomId": "110867",
"time": 1514189815190,
"user": {
"banned": false,
"clientIp": "",
"nick": "游客",
"pic": "http://www.polyv.net/images/effect/effect-device.png",
"roomId": "110867",
"uid": "hzx-KN4fAjBnEeumEsY1",
"userId": "1514189810254",
"userType": ""
},
"userType": ""
}
],
"page": 1,
"size": 2,
"totalCount": 6126,
"totalPage": 3063
},
"message": "",
"status": "success"
}
响应失败JSON示例
未输入appId
{
"code": 400,
"status": "error",
"message": "appId not found.",
"data": ""
}
appId不正确
{
"code": 400,
"status": "error",
"message": "application not found.",
"data": ""
}
时间戳错误
{
"code": 400,
"status": "error",
"message": "invalid timestamp.",
"data": ""
}
签名错误
{
"code": 403,
"status": "error",
"message": "invalid signature.",
"data": ""
}
频道号错误
{
"code": 400,
"status": "error",
"message": "channel not found.",
"data": ""
}
开始时间为空
{
"code": 400,
"status": "error",
"message": "startDay can not be empty.",
"data": ""
}
结束时间为空
{
"code": 400,
"status": "error",
"message": "endDay can not be empty.",
"data": ""
}
开始时间格式不正确 (正确格式为yyyy-MM-dd)
{
"code": 400,
"status": "error",
"message": "the startDay is no right.",
"data": ""
}
开始时间格式不正确 (正确格式为yyyy-MM-dd)
{
"code": 400,
"status": "error",
"message": "the endDay is no right.",
"data": ""
}
结束时间晚于开始时间
{
"code": 400,
"status": "error",
"message": "the endDay can not be earlier than the startDay.",
"data": ""
}
其他错误
{
"code": 400,
"status": "error",
"message": "无法访问聊天室数据",
"data": ""
}
字段说明
| 参数 | 名说明 |
|---|---|
| code | 请求状态响应码 |
| status | 请求状态 |
| message | 错误信息 |
| clientIP | 用户IP |
| content | 聊天内容 |
| id | 聊天消息id |
| image | 图片消息的图片地址 |
| roomId | 频道号 |
| time | 发送消息时的时间戳 |
| clientIp | 用户IP |
| nick | 观众昵称 |
| pic | 观众头像 |
| roomId | 频道号 |
| uid | socket分配的id,其中 uid=1 表示打赏、uid=2 表示自定义消息、uid=3 表示红包 |
| userId | 用户唯一标示 |
| userType | 用户类型,目前有teacher(老师)、assistant(助教)、manager(管理员)、slice(云课堂学员) |
| page | 当前页 |
| size | 每页数据大小 |
| totalCount | 总数据大小 |
| totalPage | 总页数 |
php请求示例
<?php
//引用config.php
include 'config.php';
//接口需要的参数(非sign)赋值
$channelId = "127075";
$startDay = "2017-08-24";
$endDay = "2018-08-24";
$params = array(
'appId'=>$appId,
'startDay'=>$startDay,
'endDay'=>$endDay,
'timestamp'=>$timestamp
);
//生成sign
$sign = getSign($params); //详细查看config.php文件的getSign方法
//接口请求url
$url = "http://api.polyv.net/live/v2/chat/{channelId}/getHistoryByPage?appId=$appId×tamp=$timestamp&sign=$sign&startDay=$startDay&endDay=$endDay";
//输出接口请求结果
echo file_get_contents($url);
?>
