let crypto = require('crypto');
function md5(content) {
return crypto.createHash('md5').update(content).digest("hex")
}
function expiredTime(minute) {
return Math.floor(new Date().getTime() / 1000 + minute * 60);
}
function getZeGouToken(appId, appSign, userID, minute) {
let nonce = new Date().getTime().toString();
let time = expiredTime(minute)
let appSign32 = appSign.replace(/0x/g, '').replace(/,/g, '').substring(0, 32);
console.log('appSign:' + time + ' ' + appSign32 + ' ' + nonce);
if (appSign32.length < 32) {
console.log('private sign erro!!!!');
return null;
}
let sourece = md5(appId + appSign32 + userID + nonce + time);
console.log('hash:' + sourece);
let jsonStr = JSON.stringify({
'ver': 1,
'expired': time,
'nonce': nonce,
'hash': sourece
});
console.log('json', jsonStr);
return Buffer.from(jsonStr).toString('base64');
}
const appID = 1386410308;
const appSigin = '0xa5,0x45,0x62,xxxxx';
const userID = 'zego-userID';
const minute = 30;
let token = getZeGouToken(appID, appSigin, userID, minute);
console.log('token:',token);