微信小程序多人音视频参数处理

  |  

使用的是koa2

const got = require('got');
const moment = require('moment')

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
let { code = '', groupId = '1559_6729', roomType = 'voice' } = ctx.request.body;
if (!code) throw new CustomError('缺少code', ErrorConf.DefectParam);

let appid = wxConf.student_appid,
appsecret = wxConf.student_appsecret;
let WxLoginInfo = (await got.get(`https://api.weixin.qq.com/sns/jscode2session?appid=${appid}&secret=${appsecret}&js_code=${code}&grant_type=authorization_code`, { 'json': true })).body;
// 返回值
let { session_key, errcode, errmsg, openid } = WxLoginInfo || {};
if (errmsg) throw new CustomError(errmsg, ErrorConf.ParamError);

let params = {
'appId': appid,
'groupId': groupId,
'nonceStr': Math.random().toString(36).substr(2, 15),
'timeStamp': moment(moment().format('YYYY-MM-DD HH:mm:ss')).valueOf() / 1000 + '',
'roomType': roomType,
'signature': '',
};

const str = Object.keys(params).filter(function(key) {
return params[key] !== undefined && params[key] !== '' && ![ 'roomType', 'signature', 'session_key' ].includes(key);
}).map(function(key) {
return params[key];
})
.sort()
.join('');

params.signature = crypto.createHmac('sha256', session_key)
.update(str)
.digest('hex');

delete params['appId'];
params['openid'] = openid;
params['timeStamp'] = parseInt(params['timeStamp']);

console.log('params', params)

voip-room
wx.joinVoIPChat
签名算法

文章目录
  1. 1. 使用的是koa2