https://apichat.polyv.net/front/userlistExternal
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));
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"
}
]
}