Commit bfbd0267 authored by Hsinli's avatar Hsinli

addd

parent b6f746d6
Pipeline #19277 passed with stage
in 57 seconds
'use strict';
const Controller = require('egg').Controller;
class CheckController extends Controller {
/**
* 获取用户手机
*/
async getUserHidePhone() {
const { ctx } = this;
ret = await ctx.service.duxiaoman.check.getUserHidePhone();
ctx.success(ret);
}
/**
* 获取度小满查询结果
*/
async getCheck() {
const { ctx } = this;
const ret = await ctx.service.duxiaoman.check.check();
ctx.success(ret);
}
}
module.exports = CheckController;
'use strict';
module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/duxiaoman/check');
router.get('/phone', 'duxiaoman.check.getUserHidePhone');
router.get('/result', 'duxiaoman.check.getCheck');
};
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
class CheckService extends Service {
/**
* 获取用户的手机号(打码)
*/
async getUserHidePhone() {
const { ctx } = this;
let ret = {
isLogin: false,
hidePhone: ''
};
if (!ctx.appUserId || !ctx.deviceId || !ctx.deviceLoginId || !ctx.userId) {
//如果没有登录就不做处理
return ret;
}
let filter = {
attributes: ['passport'],
where: {
sid: ctx.oldUserId,
yys_cid: 10
}
}
let userInfo = await ctx.gjjModel.SysUser.findOne(filter);
if (!userInfo) {
ctx.failed('没有找到对应的手机号');
}
ret.hidePhone = userInfo.passport.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
return ret;
}
/**
* 签名,加密
* @param {object} params 需要加密的参数对象
*/
async sign(params) {
const { ctx } = this;
let signKey = this.config.DXM_SECRET;
let sign = '';
if (!params) {
ctx.failed('params is empty');
}
//键名排序
const sortParamsKey = Object.keys(params).sort();
//键值拼接-升序
let sortValues = '';
for (let i in sortParamsKey) {
if (['sign', 'Sign'].includes(sortParamsKey[i])) {
continue;
}
sortValues += sortParamsKey[i] + '=' + params[sortParamsKey[i]] + '&';
}
sortValues = sortValues.substring(0, sortValues.length - 1) + signKey;
sign = ctx.helper.md5(sortValues);
ctx.logger.info({ sign: sign });
return sign;
}
async check() {
const { ctx } = this;
if (!ctx.appUserId || !ctx.oldUserId || !ctx.userId) {
//如果没有登录就不做处理
ctx.failed('登录异常');
}
//获取用户手机号
let filter = {
attributes: ['passport'],
where: {
sid: ctx.oldUserId,
yys_cid: 10
}
}
let userInfo = await ctx.gjjModel.SysUser.findOne(filter);
if (!userInfo) {
ctx.failed('没有找到对应的手机号');
}
let params = {
app_id: this.config.DXM_APP_ID,
datetime: new Date.getTime(),
phone: ctx.helper.md5(userInfo.passport),
fr: 'gjj_test',//TODO,线下测试随意,不为空即可
sign: '',
}
params.sign = await this.sign(params);
let dxmUrl = this.config.DXM_URL + '?';
for (let i in params) {
dxmUrl += i + '=' + params[i] + '&';
}
dxmUrl = dxmUrl.substring(0, dxmUrl.length - 1);
ctx.logger.info('dxmUrl:' + dxmUrl);
let result = await ctx.helper.send_request(dxmUrl, {}, { method: 'GET' });
ctx.logger.info('result:' + JSON.stringify(result));
return result;
}
}
module.exports = CheckService;
......@@ -14,7 +14,7 @@ module.exports = appInfo => {
dir: '/jianbing/logs/51business',
};
// add your config here
config.middleware = [ 'errorHandler', 'deviceLogin', 'deviceInit', 'responseSet' ];
config.middleware = ['errorHandler', 'deviceLogin', 'deviceInit', 'responseSet'];
// 是否启用csrf安全
config.security = {
......@@ -159,5 +159,11 @@ module.exports = appInfo => {
config.YYS_REPORT_APPSECRET = process.env.YYS_REPORT_APPSECRET;
config.YYS_REPORT_URL = process.env.YYS_REPORT_URL;
//度小满金融查询
config.DXM_APP_ID = process.env.DXM_APP_ID;
config.DXM_SECRET = process.env.DXM_SECRET;
config.DXM_URL = process.env.DXM_URL;
return config;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment