保利威文档中心

幫助中心

取得聊天室線上列表

更新時間:2022-08-17 18:12:42

介面說明

1、通过频道号,获取聊天室在线列表

介面URL

https://apichat.polyv.net/front/userlistExternal

請求方式

GET

介面限制

1、介面每次請求最多回傳1000筆資料,建議每次回傳100筆,分頁取得

2、回傳資料量大的情況下,請求頻率間隔大於10秒

3、資料中包含虛擬觀眾的資訊

請求參數說明

參數名 必選 類型 說明
roomId true String 房間號碼
page false Integer 頁碼,預設1
len false String 每頁筆數,預設100,最多回傳1000筆
toGetSubRooms false Boolean 是否取得子頻道的使用者,true為取得,false為不取得
callback false Function 回呼函式,用於解決前端請求跨域問題

回傳結果解密:

const aesjs = require('aes-js');
const Base64 = require('js-base64');
const md5 = require('md5');
 
function decrypt(encrypted, sign) {
  const encryptedBytes = aesjs.utils.hex.toBytes(encrypted);
  const key = str2ab(sign, 16);
  const iv = key;
  const aesCfb = new aesjs.ModeOfOperation.cbc(key, iv, 8);
  const decryptedBytes = aesCfb.decrypt(encryptedBytes);
 
  const decryptedText = aesjs.utils.utf8.fromBytes(decryptedBytes);
  return Base64.decode(decryptedText);
  function str2ab(str, len) {
    const bytes = aesjs.utils.utf8.toBytes(str);
    const bytesLen = bytes.length;
    if (bytesLen > len) {
      return bytes.slice(0, len);
    }
    return (
      [].concat(...(new Array(Math.ceil(len / bytesLen)).fill(bytes)))
    ).slice(0, len);
  }
}
 
function createApiSign(appSecret, data = {}, type = 'upper') {
  //1、把data里的数据按字典序排列
  //2、按照key+value进行拼接,在首尾分别加上appSecret
  //3、MD5加密,默认大写,当type=lower时,为小写
  let content = appSecret;
  const temp = Object.keys(data).sort();
  temp.forEach((item) => {
    if (item === 'sign') {
      return;
    }
    const v = data[item];
    content += item + (isObject(v) ? JSON.stringify(v) : v);
  });
  content += appSecret;
  const sign = md5(content);
  return type === 'lower' ? sign : sign.toLocaleUpperCase();
}
 
function isObject(obj){
return obj !== null && obj instanceof Object;
}
// 1、第一步,访问链接地址,获取返回内容
// http://apichat.polyv.net/front/userlistExternal?roomId=412738&page=1&len=100&hide=0&toGetSubRooms=true
 
const sign = createApiSign('polyvChatSignForExternal', { roomId: '412738', page: '1', len: '100', hide: '0', toGetSubRooms: 'true' }); // 接口请求的参数的签名
//2、第二步,将第一步的返回内容赋值给encrypted进行解析
const encrypted = 'fd1206646ea5e702852157';
console.log(decrypt(encrypted, sign));

回應參數說明

參數名 類型 說明
count Integer 總人數
userlist Array 使用者物件(詳細請看下方使用者物件說明)

使用者物件說明

參數名 類型 說明
actor String 身份資訊,講師、助教等
banned Boolean 是否禁言
channelId String 頻道號碼
clientIp String 使用者IP
nick String 暱稱
pic String 頭像
roomId String 房間號碼
uid String socket id
userId String 使用者ID
userSource String 資訊來源
userType String 使用者類型
assistant:助教
student:一般觀眾
slice:一般觀眾
dummy:虛擬觀眾
teacher:講師
guest:嘉賓
attendee:研討會參與者(頻道場景為研討會場景時才有)
manager:直播監控管理員
talent:同台主播(頻道場景為MR時才有)

javascript請求範例

const formData = {
    roomId: '412738',
    page: 1,
    len: 100,
    hide: 0,
    toGetSubRooms: true,
};
ajax({
  url: 'https://apichat.polyv.net/front/userlistExternal',
  formData,
  type: 'get',
}).then(console.log);

回應範例

成功範例

{
  "count": 1,
  "userlist": [
    {
      "banned": false,
      "channelId": "412738",
      "clientIp": "",
      "nick": "广州观众/70375",
      "param4": "",
      "param5": "",
      "pic": "http://liveimages.videocc.net/defaultImg/avatar/viewer.png",
      "roomId": "412738",
      "uid": "XXl7pssG5JvcNzhbAAAU",
      "userId": "1621838373713",
      "userType": "slice"
    }
  ]
}
联系客服,在线咨询