Commit ce5f3be2 authored by 任国军's avatar 任国军
parents facab3dc 47d85cc9
Pipeline #19310 passed with stage
in 8 seconds
'use strict';
const Controller = require('egg').Controller;
class CheckController extends Controller {
/**
* 获取用户手机
*/
async getUserHidePhone() {
const { ctx } = this;
let 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;
......@@ -24,6 +24,9 @@ class ResponseController extends Controller {
target_url += `?channel_id=${channel_alias}`;
}
const target_url1 = decodeURI(target_url);
const target_url2 = encodeURI(target_url1);
//如果cookie中已存在 5要素 则可直接 跳到目标地址
const token = ctx.cookies.get('token', { signed: false });
const user_id = ctx.cookies.get('user_id', { signed: false });
......@@ -32,7 +35,7 @@ class ResponseController extends Controller {
const device_login_id = ctx.cookies.get('device_login_id', { signed: false });
ctx.logger.info('target_user--' + JSON.stringify({ target_cookies_user: { token, user_id, app_user_id, device_id, device_login_id } }));
if (token && user_id && app_user_id && device_id && device_login_id) {
ctx.redirect(target_url);
ctx.redirect(target_url2);
return;
}
......@@ -111,7 +114,7 @@ class ResponseController extends Controller {
}
}
ctx.redirect(target_url);
ctx.redirect(target_url2);
return;
}
......
......@@ -5,7 +5,7 @@ const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const SysUser = app.gjjModel.define('sys_suer', {
const SysUser = app.gjjModel.define('sys_user', {
sid: {
type: INTEGER,
primaryKey: true,
......
'use strict';
const moment = require('moment');
module.exports = app => {
const { INTEGER, STRING, DATE } = app.Sequelize;
const DuxiaomanLog = app.prometheusModel.define('duxiaoman_log', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
user_id: STRING,
app_user_id: STRING,
app_id: STRING,
app_type_id: STRING,
user_sid: INTEGER,
phone: STRING,
is_target_user: INTEGER,
request: STRING,
response: STRING,
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
}
}, {
timestamps: false,
tableName: 'duxiaoman_log',
});
return DuxiaomanLog;
};
'use strict';
module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/duxiaoman');
const loginAuth = app.middleware.loginAuth({ type: 'new' });//登录中间件
router.get('/user/phone', loginAuth, 'duxiaoman.check.getUserHidePhone');
router.get('/check', loginAuth, '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 = {
hide_phone: '',
is_reject: false,//30天之内是否有被拒记录
};
if (!ctx.oldUserId || !ctx.userId) {
//如果没有登录就不做处理
return ret;
}
let userSid = isNaN(ctx.oldUserId) ? ctx.helper.decodeUserSid(ctx.oldUserId) : ctx.oldUserId;
let filter = {
attributes: ['passport'],
where: {
sid: userSid,
yys_cid: 10
}
}
let userInfo = await ctx.gjjModel.SysUser.findOne(filter);
if (!userInfo) {
ctx.failed('没有找到对应的手机号');
}
ret.hide_phone = userInfo.passport.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
//最近30天是否有被拒记录
let rejectFilter = {
attributes: ['user_sid'],
where: {
user_sid: userSid,
created_at: { $gt: moment().subtract(30, 'days').format('YYYY-MM-DD HH:mm:ss') },
is_target_user: { $ne: 1 }
}
}
let rejectRecord = await ctx.prometheusModel.DuxiaomanLog.findOne(rejectFilter);
ret.is_reject = !rejectRecord ? false : true;
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;
let ret = {
is_target_user: 0,//1 true 0 false -1 NOT_FOUND
url: ''
}
if (!ctx.oldUserId || !ctx.userId) {
//如果没有登录就不做处理
ctx.failed('登录异常');
}
let userSid = isNaN(ctx.oldUserId) ? ctx.helper.decodeUserSid(ctx.oldUserId) : ctx.oldUserId;
let filter = {
attributes: ['passport'],
where: {
sid: userSid,
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_md5: 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));
if (result.status === 200) {
if (result.data.retCode === 0) {
ret.is_target_user = result.data.result.is_target_user;
}
//数据库记录
let addData = {
user_id: ctx.userId,
app_user_id: ctx.appUserId,
app_id: ctx.appId,
app_type_id: ctx.appTypeId,
user_sid: userSid,
phone: userInfo.passport,
is_target_user: result.data.result.is_target_user,
request: JSON.stringify(params),
response: JSON.stringify(result.data),
}
await ctx.prometheusModel.DuxiaomanLog.create(addData);
} else {
ctx.failed('服务异常,请稍后再试');
}
if (ret.is_target_user === 1) {
let businessId = this.config.CFG_ENV === 'dev' ? 1 : (this.config.CFG_ENV === 'uat' ? 175 : 3);
let businessInfo = await this.getBusinessInfo(businessId);
ret.url = businessInfo.url;
}
return ret;
}
/**
* 获取业务信息,type=4表示普通贷款
* @param {integer|string} id 业务编号
* @returns {object} businessInfo 业务相关信息
*/
async getBusinessInfo(id) {
const { ctx } = this;
let url = this.config.CASSANDRA_API + '/huodong/bu_basic/' + id + '?type=4';
let result = await ctx.helper.send_request(url, {}, {
method: 'GET',
});
ctx.logger.info(url + ':' + JSON.stringify(result));
let businessInfo = (result.status === 200 && result.data && result.data.ret) ? result.data.ret : {};
return businessInfo;
}
}
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,15 @@ 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;
config.CFG_ENV = process.env.CFG_ENV;
config.CASSANDRA_API = process.env.CASSANDRA_API;
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