123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 'use strict';
- const _ = require('lodash');
- const meta = require('./.user.js');
- const Controller = require('egg').Controller;
- const { CrudController } = require('naf-framework-mongoose/lib/controller');
- const TLSSigAPIv2 = require('tls-sig-api-v2');
- const qiniu = require('qiniu');
- class UserController extends Controller {
- constructor(ctx) {
- super(ctx);
- this.service = this.ctx.service.user;
- }
- async uppasswd() {
- const res = await this.service.uppasswd(this.ctx.request.body);
- this.ctx.ok({ data: res });
- }
- async querymenus() {
- const res = await this.service.querymenus(this.ctx.query);
- this.ctx.ok({ data: res });
- }
- async updatebyuid() {
- const res = await this.service.updatebyuid(this.ctx.params, this.ctx.request.body);
- this.ctx.ok({ data: res });
- }
- async bind() {
- const res = await this.service.bind(this.ctx.request.body);
- this.ctx.ok({ data: res });
- }
- async gensign() {
- const api = new TLSSigAPIv2.Api(this.app.config.sdkappid, this.app.config.secretkey);
- const res = api.genSig(this.ctx.request.body.userid, 86400 * 180);
- console.log('sig ' + res);
- // sig = api.genSigWithUserbuf(this.ctx.request.body.userid, 86400 * 180, this.ctx.request.body.name);
- // console.log('sig with userbuf ' + sig);
- this.ctx.ok({ data: res });
- }
- async gensignqili() {
- const ak = 'CNOr-D4vAG3bNP3uXfwsL_n2FMXFm5C-MUof3goK';
- const sk = 'GL5k-Hc-MPM1ZPlRPYfNhMgN-pPGRTuua8gTc2Pj';
- const credentials = new qiniu.Credentials(ak, sk);
- const roomToken = await qiniu.room.getRoomToken({
- appId: 'f3m2e54ms',
- roomName: this.ctx.request.body.roomname,
- userId: this.ctx.request.body.userid,
- expireAt: Date.now() + (1000 * 60 * 60 * 3), // token 的过期时间默认为当前时间之后 3 小时
- permission: 'user',
- }, credentials);
- console.log('sig ' + roomToken);
- // sig = api.genSigWithUserbuf(this.ctx.request.body.userid, 86400 * 180, this.ctx.request.body.name);
- // console.log('sig with userbuf ' + sig);
- this.ctx.ok({ data: roomToken });
- }
- }
- module.exports = CrudController(UserController, meta);
|