Authored by zzzzzzz

二维码调用接口

1 'use strict'; 1 'use strict';
2 2
3 -const crypto = global.yoho.crypto; 3 +const model = require('../models/myqrcode');
4 4
5 exports.index = (req, res, next) => { 5 exports.index = (req, res, next) => {
6 let params = req.query; 6 let params = req.query;
7 - params.token = crypto.encryption('yoho9646yoho9646', JSON.stringify({  
8 - tk: params.token,  
9 - ct: Math.floor(Date.now()/1000),  
10 - }));  
11 - console.log(params.token);  
12 - console.log(crypto.decrypt('yoho9646yoho9646', params.token));  
13 7
14 - res.render('myqrcode', {  
15 - title: '查看二维码',  
16 - module: 'home',  
17 - page: 'myqrcode',  
18 - isPassportPage: true,  
19 - data: params,  
20 - }); 8 + model.getQr({
  9 + token: params.token,
  10 + }).then(result => {
  11 + params.token = result;
  12 + res.render('myqrcode', {
  13 + title: '查看二维码',
  14 + module: 'home',
  15 + page: 'myqrcode',
  16 + isPassportPage: true,
  17 + data: params,
  18 + });
  19 + }).catch(next);
21 }; 20 };
1 -"use strict"; 1 +'use strict';
2 2
3 const api = global.yoho.API; 3 const api = global.yoho.API;
4 4
5 exports.getQr = (params) => { 5 exports.getQr = (params) => {
6 return api.get('', { 6 return api.get('', {
7 method: 'app.twoDimen.getCode', 7 method: 'app.twoDimen.getCode',
8 - uid: 1234, 8 + uid: params.token,
9 }).then(result => { 9 }).then(result => {
10 - return result; 10 + return (result && result.date && result.data.code) || '';
11 }); 11 });
12 -}  
  12 +};