Commit 42e34f5e authored by 李尚科's avatar 李尚科

fix

parent 1990eff7
...@@ -5,7 +5,7 @@ const Controller = require('egg').Controller; ...@@ -5,7 +5,7 @@ const Controller = require('egg').Controller;
class CallriskController extends Controller { class CallriskController extends Controller {
/** /**
* 获取黑名单报告 * 通话记录风险检测报告
*/ */
async getReport() { async getReport() {
...@@ -14,8 +14,8 @@ class CallriskController extends Controller { ...@@ -14,8 +14,8 @@ class CallriskController extends Controller {
if (!report_id) { if (!report_id) {
ctx.failed('error report id'); ctx.failed('error report id');
} }
const ret = await ctx.service.credit.callrisk.getReport(report_id); const result = await ctx.service.credit.callrisk.getReport(report_id);
ctx.success(ret); ctx.success({ result });
} }
...@@ -24,12 +24,12 @@ class CallriskController extends Controller { ...@@ -24,12 +24,12 @@ class CallriskController extends Controller {
*/ */
async callriskInit() { async callriskInit() {
const { ctx } = this; const { ctx } = this;
const ret = await ctx.service.credit.apply.callriskInit(); const result = await ctx.service.credit.apply.callriskInit();
ctx.success(ret); ctx.success({ result });
} }
/** /**
* 获取数据报告信息 * 立即检测
*/ */
async applyCallriskReport() { async applyCallriskReport() {
...@@ -42,20 +42,36 @@ class CallriskController extends Controller { ...@@ -42,20 +42,36 @@ class CallriskController extends Controller {
password: { type: 'string', required: true } password: { type: 'string', required: true }
} }
ctx.validate(rule, input_params); ctx.validate(rule, input_params);
await ctx.service.credit.callrisk.checkThreeElements(input_params); const result = await ctx.service.credit.apply.applyCallrisk(input_params);
const ret = await ctx.service.credit.apply.applyCallrisk(input_params); ctx.success({ result });
ctx.success(ret);
}
async getCode() {
const { ctx } = this;
const order_id = ctx.request.body.order_id;
const result = await ctx.service.credit.callrisk.getCode(order_id);
ctx.success({ result });
} }
async confirmCaptcha() { async commitTask() {
const { ctx } = this; const { ctx } = this;
const code = ctx.request.body.code; const { order_id, code } = ctx.request.body;
const result = await ctx.service.credit.callrisk.verifyCode(code); const result = await ctx.service.credit.callrisk.commitTask({ order_id, code });
// const result = true;
ctx.success({ result }); ctx.success({ result });
}
async queryTaskStatus() {
const { ctx } = this;
const order_id = ctx.params.order_id;
const result = await ctx.service.credit.callrisk.queryTaskStatus(order_id);
ctx.success({ result });
} }
......
...@@ -25,6 +25,22 @@ module.exports = app => { ...@@ -25,6 +25,22 @@ module.exports = app => {
r_code: STRING, r_code: STRING,
r_msg: STRING, r_msg: STRING,
r_order_id: STRING, r_order_id: STRING,
operator: {
type: STRING,
allowNull: true,
field: 'operator',
get() {
const operator = this.getDataValue('operator');
if (operator) {
try {
return JSON.parse(operator);
} catch (error) {
return [];
}
}
return [];
},
},
valid: INTEGER, valid: INTEGER,
created_at: { created_at: {
type: DATE, type: DATE,
......
...@@ -18,15 +18,15 @@ module.exports = app => { ...@@ -18,15 +18,15 @@ module.exports = app => {
}, },
active_call_count: { active_call_count: {
type: INTEGER, type: INTEGER,
allowNull: false, allowNull: true,
}, },
passive_call_count: { passive_call_count: {
type: INTEGER, type: INTEGER,
allowNull: false, allowNull: true,
}, },
each_call_count: { each_call_count: {
type: INTEGER, type: INTEGER,
allowNull: false, allowNull: true,
}, },
silence_count_3day: { silence_count_3day: {
type: INTEGER, type: INTEGER,
...@@ -50,7 +50,7 @@ module.exports = app => { ...@@ -50,7 +50,7 @@ module.exports = app => {
}, },
maximum_active_call_city: { maximum_active_call_city: {
type: STRING, type: STRING,
allowNull: false, allowNull: true,
}, },
maximum_passive_call_count: { maximum_passive_call_count: {
type: INTEGER, type: INTEGER,
...@@ -62,7 +62,7 @@ module.exports = app => { ...@@ -62,7 +62,7 @@ module.exports = app => {
}, },
maximum_passive_call_city: { maximum_passive_call_city: {
type: STRING, type: STRING,
allowNull: false, allowNull: true,
}, },
maximum_call_time: { maximum_call_time: {
type: INTEGER, type: INTEGER,
...@@ -74,7 +74,7 @@ module.exports = app => { ...@@ -74,7 +74,7 @@ module.exports = app => {
}, },
maximum_call_time_city: { maximum_call_time_city: {
type: STRING, type: STRING,
allowNull: false, allowNull: true,
}, },
// is_deleted: { // is_deleted: {
// type: INTEGER, // type: INTEGER,
......
'use strict';
const moment = require('moment');
module.exports = app => {
const { INTEGER, STRING, DATE, TEXT } = app.Sequelize;
const CreditYysOrder = app.prometheusModel.define('credit_yys_order', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
tyorder_idpe: INTEGER,
user_id: STRING,
app_user_id: STRING,
app_id: STRING,
app_type_id: STRING,
name: STRING,
phone: STRING,
id_card: STRING,
password: STRING,
r_order_sn: STRING,
operator: TEXT,
valid: INTEGER,
created_at: {
type: DATE,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
}
}, {
timestamps: false,
tableName: 'credit_yys_order',
});
return CreditYysOrder;
};
...@@ -26,7 +26,10 @@ module.exports = app => { ...@@ -26,7 +26,10 @@ module.exports = app => {
router.get('/callrisk/report/:report_id', 'credit.callrisk.getReport');//获取报告信息 router.get('/callrisk/report/:report_id', 'credit.callrisk.getReport');//获取报告信息
router.post('/callrisk/report', 'credit.callrisk.applyCallriskReport');//查询个人通话信息 router.post('/callrisk/report', 'credit.callrisk.applyCallriskReport');//查询个人通话信息
router.get('/callrisk/init', 'credit.callrisk.callriskInit');//进入个人通话风险检测页面 router.get('/callrisk/init', 'credit.callrisk.callriskInit');//进入个人通话风险检测页面
router.post('/callrisk/confirm_captcha', 'credit.callrisk.confirmCaptcha');//获取短信验证码 // router.post('/callrisk/confirm_captcha', 'credit.callrisk.confirmCaptcha');//获取短信验证码
router.post('/callrisk/get_code', 'credit.callrisk.getCode');//获取短信验证码
router.post('/callrisk/commit', 'credit.callrisk.commitTask');//提交任务
router.get('/callrisk/query/:order_id', 'credit.callrisk.queryTaskStatus');//检查任务状态
}; };
...@@ -320,102 +320,76 @@ class ApplyService extends Service { ...@@ -320,102 +320,76 @@ class ApplyService extends Service {
const app_type_id = ctx.appTypeId; const app_type_id = ctx.appTypeId;
const app_user_id = ctx.appUserId; const app_user_id = ctx.appUserId;
const app_id = ctx.appId; const app_id = ctx.appId;
const type = TypeConfigp['callrisk'];//个人通话类型 const type = TypeConfig['callrisk'];//个人通话类型
let report_id = null;
//数盒魔方三要素校验 //数盒魔方三要素校验
await ctx.service.credit.common.shuhemofangCheck('callrisk', input); // await ctx.service.credit.callrisk.checkThreeElements(input);
// await ctx.service.credit.common.shuhemofangCheck('callrisk', input);
//判断用户当前三要素是否是二次查询未支付订单 //判断用户当前三要素是否是二次查询未支付订单
const check_second_ret = await this.checkSecond(); const check_second_ret = await this.checkSecond({ name, phone, id_card });
if (!check_second_ret.order_id) { if (check_second_ret.order_id) {
return check_second_ret; return check_second_ret;
} }
// let ret = {
// order_id,
// report_id: null,
// first: check_second_ret.first,
// second: check_second_ret.second,
// order_sn: null
// }
//生成订单 //生成订单
const order_data = { type, name, phone, id_card }; const order_data = { type, name, phone, id_card };
const order = await ctx.service.credit.order.createOrder(order_data); const order = await ctx.service.credit.order.createOrder(order_data);
const order_id = order.id; const order_id = order.id;
//运营商API.创建订单号 //创建yys-order apply 记录
const order_sn_info = await ctx.service.credit.yys.getOrderSn(phone); const apply = await this.createYysApply({ name, phone, id_card, password, order_id });
if (orderSnInfo.code !== 0) { const order_sn = apply.r_order_id;
ctx.failed('getOrderSn error msg:' + orderSnInfo.msg);
} //第一次调用运营商获取验证码接口
const order_sn = order_sn_info.data.orderSn; const operator_params = apply.operator.params;
const addYysOrder = { let get_code_params = { orderSn: order_sn, data: {} };
order_id, for (let k in operator_params) {
user_id, const operator_params_val = operator_params[k];
app_type_id, if (operator_params_val.name === 'phone') {
app_user_id, continue;
app_id, }
name, get_code_params.data[operator_params_val.name] = input[operator_params_val.name];
phone, }
id_card, // get_code_params.data.phoneCode = '';
password, const yys_get_code = await ctx.service.credit.yys.getCode(get_code_params);
r_order_sn: order_sn,
order_sn_operator: orderSnInfo.data.operator
}
const yys_order_info = await ctx.prometheusModel.CreditYysOrder.create(addYysOrder);
// ret.order_sn = yys_order_info.data.orderSn;
//调用运营商获取验证码接口
const yys_get_code = await ctx.service.credit.yys.getCode({ password, order_sn });
if (yys_get_code.code !== 0) { if (yys_get_code.code !== 0) {
ctx.failed('getCode error msg:' + yys_get_code.msg); ctx.failed('getCode error msg:' + yys_get_code.msg);
} }
const order_no = await ctx.service.credit.common.getOrdertNo('callrisk', order_id);
// //提交任务 await ctx.prometheusModel.CreditOrder.update({ order_no, apply_id: apply.id }, { where: { id: order_id } });
// const yys_commit = await this.commitYys(orderSnInfo.data.orderSn, { phone, name, ID: id_card, password, phoneCode });
// if (yys_commit.code !== 0) {
// ctx.failed('getCode error msg:' + yys_commit.msg);
// }
return { order_id, report_id, first: check_second_ret.first, second: check_second_ret.second, order_sn }; return { order_id, report_id, first: check_second_ret.first, second: check_second_ret.second, order_sn };
} }
async createApply() {
async createYysApply(input) {
const { ctx } = this; const { ctx } = this;
const user_id = ctx.userId; const user_id = ctx.userId;
const app_type_id = ctx.appTypeId; const app_type_id = ctx.appTypeId;
const app_user_id = ctx.appUserId; const app_user_id = ctx.appUserId;
const app_id = ctx.appId; const app_id = ctx.appId;
//获取签名 const { name, phone, id_card, password, order_id } = input;
const timestamp = String(new Date().getTime());
const appKey = ''; //运营商API.创建订单号
const sign_params = { appKey, timestamp, }; const order_sn_info = await ctx.service.credit.yys.getOrderSn(phone);
const sign = await ctx.service.credit.common.sign(sign_params, this.config.BLACKLIST_APPLY_APPSECRET); if (order_sn_info.code !== 0) {
//调用数据接口获取个人通话风险数据 TODO ctx.failed('getOrderSn error msg:' + order_sn_info.msg);
const params = { sign, phone, name, idcard, } }
const url = '';
const result = await ctx.helper.send_request(url, params, { method: 'POST' }); //创建申请订单
const apply_data = { const apply_data = {
type, type: 2, user_id, app_user_id, app_id, app_type_id, name, phone, id_card,
user_id, appkey: this.config.YYS_APP_KEY,
app_user_id, service_code: password,
app_id, r_code: order_sn_info.code,
app_type_id, r_msg: order_sn_info.msg,
timestamp, r_order_id: order_sn_info.data.orderSn,
appkey: '', operator: JSON.stringify(order_sn_info.data.operator)
sign,
r_code: result.data.code,
r_msg: result.data.msg,
r_order_id: result.data.data.order_id,
} }
const apply = await ctx.prometheusModel.CreditApply.create(apply_data); const apply = await ctx.prometheusModel.CreditApply.create(apply_data);
if (result.data.code !== 0) {
ctx.failed('数据获取异常');
}
return apply; return apply;
} }
...@@ -425,7 +399,7 @@ class ApplyService extends Service { ...@@ -425,7 +399,7 @@ class ApplyService extends Service {
const { ctx } = this; const { ctx } = this;
const { name, phone, id_card } = input; const { name, phone, id_card } = input;
const { user_id } = this; const { user_id } = this;
const type = TypeConfigp['callrisk'];//个人通话类型 const type = TypeConfig['callrisk'];//个人通话类型
let first = false;//首次通过三要素验证后弹框提示:报告生成后,将无法查询其他人的报告 let first = false;//首次通过三要素验证后弹框提示:报告生成后,将无法查询其他人的报告
let second = false;//再次查询的是待支付中的订单 let second = false;//再次查询的是待支付中的订单
let order_id = null; let order_id = null;
......
This diff is collapsed.
...@@ -19,7 +19,14 @@ class YysService extends Service { ...@@ -19,7 +19,14 @@ class YysService extends Service {
} }
let url = this.config.NODE_BASE_URL + '/yys_api/getorderSn' + '?appKey=' + this.config.YYS_APP_KEY; let url = this.config.NODE_BASE_URL + '/yys_api/getorderSn' + '?appKey=' + this.config.YYS_APP_KEY;
let resp = await ctx.helper.send_request(url, params, { method: 'POST' }); let resp = await ctx.helper.send_request(url, params, { method: 'POST' });
ctx.logger.info({ url: JSON.stringify(resp) }); ctx.logger.info(JSON.stringify({ yys_getorderSn_params: params, yys_getorderSn_result: resp }));
if (resp.data.code === undefined || resp.data.code !== 0) {
ctx.failed('getorderSn error:' + resp.data.msg);
}
let order_sn = resp.data.data.orderSn;
await this.addCreditLogYys(order_sn, '/yys_api/getorderSn', params, resp.data);
// ctx.logger.info(JSON.stringify(resp));
// ctx.logger.info(JSON.stringify({ yys_getorderSn_params: params, yys_getorderSn_result: resp }));
return resp.data; return resp.data;
} }
...@@ -29,15 +36,17 @@ class YysService extends Service { ...@@ -29,15 +36,17 @@ class YysService extends Service {
*/ */
async getCode(params) { async getCode(params) {
const { ctx } = this; const { ctx } = this;
let params = { // let params_data = {
orderSn: params.order_sn, // orderSn: params.order_sn,
data: { // data: {
password: params.password // password: params.password
} // }
} // }
let url = this.config.NODE_BASE_URL + '/yys_api/getCode' + '?appKey=' + this.config.YYS_APP_KEY; let url = this.config.NODE_BASE_URL + '/yys_api/getCode' + '?appKey=' + this.config.YYS_APP_KEY;
let resp = await ctx.helper.send_request(url, params, { method: 'POST' }); let resp = await ctx.helper.send_request(url, params, { method: 'POST' });
ctx.logger.info({ url: JSON.stringify(resp) }); ctx.logger.info(JSON.stringify({ yys_getCode_params: params, yys_getCode_result: resp }));
await this.addCreditLogYys(params.orderSn, '/yys_api/getCode', params, resp.data);
// console.info(resp);
return resp.data; return resp.data;
} }
...@@ -57,7 +66,8 @@ class YysService extends Service { ...@@ -57,7 +66,8 @@ class YysService extends Service {
// } // }
const url = this.config.NODE_BASE_URL + '/yys_api/commit' + '?appKey=' + this.config.YYS_APP_KEY; const url = this.config.NODE_BASE_URL + '/yys_api/commit' + '?appKey=' + this.config.YYS_APP_KEY;
const resp = await ctx.helper.send_request(url, params, { method: 'POST' }); const resp = await ctx.helper.send_request(url, params, { method: 'POST' });
ctx.logger.info({ url: JSON.stringify(resp) }); ctx.logger.info(JSON.stringify({ yys_commit_params: params, yys_commit_result: resp }));
await this.addCreditLogYys(params.orderSn, '/yys_api/commit', params, resp.data);
return resp.data; return resp.data;
} }
...@@ -72,7 +82,8 @@ class YysService extends Service { ...@@ -72,7 +82,8 @@ class YysService extends Service {
} }
let url = this.config.NODE_BASE_URL + '/yys_api/query' + '?appKey=' + this.config.YYS_APP_KEY; let url = this.config.NODE_BASE_URL + '/yys_api/query' + '?appKey=' + this.config.YYS_APP_KEY;
let resp = await ctx.helper.send_request(url, params, { method: 'POST' }); let resp = await ctx.helper.send_request(url, params, { method: 'POST' });
ctx.logger.info({ url: JSON.stringify(resp) }); ctx.logger.info(JSON.stringify({ yys_query_params: params, yys_query_result: resp }));
await this.addCreditLogYys(orderSn, '/yys_api/query', params, resp.data);
return resp.data; return resp.data;
} }
...@@ -88,19 +99,33 @@ class YysService extends Service { ...@@ -88,19 +99,33 @@ class YysService extends Service {
let params = { let params = {
sign: "", sign: "",
signParams: { signParams: {
appKey: this.config.YYS_APP_KEY, appKey: this.config.YYS_REPORT_KEY,
timestamp: String(new Date().getTime()), timestamp: String(new Date().getTime()),
}, },
orderSn, orderSn,
} }
params.sign = await ctx.service.credit.common.sign(params.signParams, this.config.YYS_APPLY_APPSECRET); params.sign = await ctx.service.credit.common.sign(params.signParams, this.config.YYS_REPORT_APPSECRET);
const url = this.config.YYS_APPLY_URL; const url = this.config.YYS_REPORT_URL;
const result = await ctx.helper.send_request(url, params, { method: 'POST' }); const result = await ctx.helper.send_request(url, params, { method: 'POST' });
ctx.logger.info(JSON.stringify({ thxdReport_parmas: params, thxdReport_result: result })); ctx.logger.info(JSON.stringify({ thxdReport_parmas: params, thxdReport_result: result }));
return result.data; return result.data;
} }
async addCreditLogYys(order_sn, request_url, params, resp) {
const { ctx } = this;
const user_id = ctx.userId;
const app_type_id = ctx.appTypeId;
const app_user_id = ctx.appUserId;
const app_id = ctx.appId;
const log_data = { user_id, app_type_id, app_user_id, app_id, r_order_sn: order_sn, request_url, params: JSON.stringify(params), resp: JSON.stringify(resp) }
const ret = await ctx.prometheusModel.CreditLogYys.create(log_data);
return ret;
}
} }
......
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