Commit 565694e3 authored by Hsinli's avatar Hsinli

addd

parent 29cc4525
Pipeline #13656 passed with stage
in 7 seconds
'use strict';
const moment = require('moment');
module.exports = app => {
const { INTEGER, STRING, DATE } = app.Sequelize;
const CreditShuhemofang = app.prometheusModel.define('credit_shuhemofang', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
type: INTEGER,
user_id: STRING,
app_user_id: STRING,
app_id: STRING,
app_type_id: STRING,
name: STRING,
phone: STRING,
id_card: STRING,
status: 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: 'credit_shuhemofang',
});
return CreditShuhemofang;
};
......@@ -7,6 +7,55 @@ const _ = require('lodash');
class ApplyService extends Service {
/**
* 进入黑名单查询页面
*/
async blacklistInit() {
const { ctx } = this;
let ret = {
have_be_pay_order: false,
order_id: null,
placeholder: {
name: '',
id_card: ''
}
}
if (!ctx.userId) {
ctx.failed('登录异常');
}
let bePayOrder = await ctx.service.credit.order.getBePayOrder(1);
if (bePayOrder.length !== 0) {
ret.have_be_pay_order = true;
ret.order_id = bePayOrder[0].id;
}
//第一次查询成功的订单,反显姓名和身份证
let filter = {
where: {
user_id: ctx.userId,
type: 1,
valid: 1,
},
order: [['id', 'asc']]
}
let orderInfo = await ctx.prometheusModel.CreditOrder.findOne(filter);
if (orderInfo != null) {
let applyFilter = {
where: {
id: orderInfo.apply_id
}
}
let applyInfo = await ctx.prometheusModel.CreditApply.findOne(applyFilter);
if (applyInfo != null) {
ret.placeholder.name = applyInfo.name;
ret.placeholder.id_card = applyInfo.id_card;
}
}
return ret;
}
/**
* 获取短信验证码
* @param {*} inputParams
......@@ -35,17 +84,10 @@ class ApplyService extends Service {
ctx.failed('姓名输入有误,请校验后输入');
}
//TODO 三要素校验
//生成四位验证码
/**
* redis保存
* SET KEY VALUE [EX seconds]|[PX milliseconds] [NX|XX]
* EX seconds − 设置指定的到期时间(以秒为单位)。
* PX milliseconds - 设置指定的到期时间(以毫秒为单位)。
* NX - 仅在键不存在时设置键。
* XX - 只有在键已存在时才设置。
*/
//数盒魔方三要素校验
await ctx.service.credit.common.shuhemofangCheck('blacklist', inputParams);
//验证码
//60秒只能获取一次
let lockKey = 'mine:credit:black:lock' + inputParams.phone;
let lock = await app.redis.get(lockKey);
......@@ -79,7 +121,12 @@ class ApplyService extends Service {
}
}
let codeKey = 'mine:credit:black:code' + inputParams.phone;
await app.redis.set(codeKey, code, 'EX', 60 * 5);//5分钟有效时间
let codeData = {//用于避免用户获取验证码之后修改姓名/身份证等
code: code,
name: inputParams.name,
id_card: inputParams.id_card
}
await app.redis.set(codeKey, codeData, 'EX', 60 * 5);//5分钟有效时间
let smsParams = {
......@@ -95,53 +142,6 @@ class ApplyService extends Service {
}
/**
* 进入黑名单查询页面
*/
async blacklistInit() {
const { ctx } = this;
let ret = {
have_be_pay_order: false,
order_id: null,
placeholder: {
name: '',
id_card: ''
}
}
if (!ctx.userId) {
ctx.failed('登录异常');
}
let bePayOrder = await ctx.service.credit.order.getBePayOrder(1);
if (bePayOrder.length != 0) {
ret.have_be_pay_order = true;
ret.order_id = bePayOrder[0].id;
}
//第一次查询成功的订单,反显姓名和身份证
let filter = {
where: {
user_id: ctx.userId,
type: 1,
valid: 1,
},
order: [['id', 'asc']]
}
let orderInfo = await ctx.prometheusModel.CreditOrder.findOne(filter);
if (orderInfo != null) {
let applyFilter = {
where: {
id: orderInfo.apply_id
}
}
let applyInfo = await ctx.prometheusModel.CreditApply.findOne(applyFilter);
if (applyInfo != null) {
ret.placeholder.name = applyInfo.name;
ret.placeholder.id_card = applyInfo.id_card;
}
}
return ret;
}
/**
* 从数据接口获取用户的黑名单报告信息
......@@ -160,10 +160,13 @@ class ApplyService extends Service {
}
//验证码校验
let codeKey = 'mine:credit:black:code' + inputParams.phone;
let code = await app.redis.get(codeKey);
if (code !== inputParams.code) {
let codeData = await app.redis.get(codeKey);
if (codeData.code !== inputParams.code) {
ctx.failed('验证码错误,请重试');
}
if (codeData.name !== inputParams.name || codeData.id_card !== inputParams.id_card) {
ctx.failed('获取验证码后请不要修改姓名、身份证等信息');
}
//判断用户是否第一次三要素核验成功
let applyFilter = {
......
......@@ -164,7 +164,7 @@ class CommonService extends Service {
error_msg = ret_data.return_msg ? ret_data.return_msg : error_msg;
ctx.failed(error_msg);
}
if (ret_data.trade_state === 'SUCCESS') {
return false;
}
......@@ -244,6 +244,120 @@ class CommonService extends Service {
return sign;
}
/**
* 数盒魔方三要素认证和存贮
* @param {*} data
* @param {*} type 黑名单blacklist通话callrisk
*/
async queryShuhemofang(type, data) {
const { ctx } = this;
if (['blacklist', 'callrisk'].includes(type)) {
ctx.failed('未知类型的数据检测');
}
let need = ['name', 'id_card', 'phone'];
for (let i in need) {
if (!data.hasOwnProperty(need[i] || !data[need[i]])) {
ctx.failed(need[i] + '参数缺失');
}
}
let ret = await this.requestShuhemofang(data);
let shuhemofangData = {
type: type === 'blacklist' ? 1 : 2,
user_id: ctx.userId,
app_user_id: ctx.appUserId,
app_id: ctx.appId,
app_type_id: ctx.appTypeId,
name: data.name,
phone: data.phone,
id_card: data.id_card,
status: (ret.hasOwnProperty('result') && ret.result.hasOwnProperty('data')) ? ret.result.data : ret.code,
response: ret,
}
let shuhemofang = await ctx.prometheusModel.CreditShuhemofang.create(shuhemofangData);
return shuhemofang;
}
/**
* 请求数盒魔方
* @param {*} data name,phone,id_card三要素
*/
async requestShuhemofang(data) {
let timestamp = new Date().getTime().toString();
let params = {
mobile: data.phone,
idNo: data.id_card,
name: data.name,
appkey: this.config.SHUHEMOFANG_APP_KEY,
timestamp: timestamp,
sign: md5(this.config.SHUHEMOFANG_APP_KEY + this.config.SHUHEMOFANG_APP_SECRET + timestamp),
}
let resp = await this.helper.send_request(this.config.SHUHEMOFANG_URL, params, { method: 'POST' });
return resp.data;
}
/**
* 根据数盒魔方结果提示
* @param {*} status 数盒魔方返回状态码
*/
async noticeShuhemofang(status) {
//异常情况
if (status === '2') {
ctx.failed('手机号已实名,身份证姓名均不匹配,请重新输入');
}
if (status === '3') {
ctx.failed('手机号已实名,姓名不匹配,请重新输入');
}
if (status === '4') {
ctx.failed('手机号已实名,身份证不匹配,请重新输入');
}
//未知情况
if (status != '1') {
ctx.failed('认证过程中出现了一些问题,请稍后重试');
}
}
/**
* 数盒魔方校验
* @param {*} type 黑名单(blacklist)通话(callrisk)
* @param {object} inputParams name,phone,id_card
*/
async shuhemofangCheck(type, inputParams) {
const { ctx } = this;
if (['blacklist', 'callrisk'].includes(type)) {
ctx.failed('未知类型的数据检测');
}
//1:判断用户当前三要素是否已经校验过
//2:有记录根据记录弹框,没记录判断该用户是否已经校验满5次
let shmfFilter = {
user_id: ctx.userId
}
let shmfList = await ctx.prometheusModel.CreditShuhemofang.findAll(shmfFilter);
if (shmfList !== undefined && shmfList.length > 0) {
let history = {
in: false,
detail: {}
};
for (let i in shmfList) {
if (shmfList[i].name === inputParams.name && shmfList[i].phone === inputParams.phone && shmfList[i].id_card === inputParams.id_card) {
history.in = true;
history.detail = shmfList[i];
break;
}
}
if (history.in) {
await this.noticeShuhemofang(Number(history.detail.status));
} else {
if (shmfList.length >= 5) {
ctx.failed('您输入的想要检测人数已超过最大限制,仅可检测输入过的检测信息');
} else {
let resp = this.queryShuhemofang(type, inputParams);
await this.noticeShuhemofang(resp.status);
}
}
}
}
}
module.exports = CommonService;
......@@ -131,6 +131,11 @@ module.exports = appInfo => {
config.BLACKLIST_APPLY_APPSECRET = '233B8E10E31B4C899EE6FEB3AEC22F140B6528BF';
config.BLACKLIST_APPLY_URL = 'http://47.96.253.64:8049/mycredit/blackList';
//数盒魔方
config.SHUHEMOFANG_APP_KEY = 'BdNFbog6';
config.SHUHEMOFANG_APP_SECRET = 'a695e9b3c0f1e3f15fb0b958fd3a4b67';
config.SHUHEMOFANG_URL = 'https://api.soohaid.com:8211/api/mobile/factor3s';
return config;
};
......@@ -118,9 +118,14 @@ module.exports = appInfo => {
config.BLACKLIST_APPLY_URL = process.env.BLACKLIST_APPLY_URL;
//微信支付相关内容
config.MCH_APPID = process.env.MCH_APPID;;//商户关联的APPID
config.MCH_ID = process.env.MCH_ID;;//商户id
config.MCH_KEY = process.env.MCH_KEY;;//商户秘钥
config.MCH_APPID = process.env.MCH_APPID;//商户关联的APPID
config.MCH_ID = process.env.MCH_ID;//商户id
config.MCH_KEY = process.env.MCH_KEY;//商户秘钥
//数盒魔方
SHUHEMOFANG_APP_KEY = process.env.SHUHEMOFANG_APP_KEY;
SHUHEMOFANG_APP_SECRET = process.env.SHUHEMOFANG_APP_SECRET;
SHUHEMOFANG_URL = process.env.SHUHEMOFANG_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