北斗启航科技教育平台登录系统
This commit is contained in:
75
app/service/Id2MVService.js
Normal file
75
app/service/Id2MVService.js
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const fileName = "Id2MVService";
|
||||
|
||||
const Cloudauth20190307 = require('@alicloud/cloudauth20190307');
|
||||
const OpenApi = require('@alicloud/openapi-client');
|
||||
const Util = require('@alicloud/tea-util');
|
||||
|
||||
class Client {
|
||||
static createClient() {
|
||||
let config = new OpenApi.Config({
|
||||
// 凭证类型。
|
||||
// type: 'access_key',
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
accessKeyId: "LTAI5tM3QC6kY4r23sWnsvuY",
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
accessKeySecret: "Lj9QTWVMJSTAffscjykhaKZt7RN0Xh",
|
||||
// 访问的地域
|
||||
// regionId: 'cn-beijing'
|
||||
});
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
||||
// 访问的地址
|
||||
config.endpoint = `cloudauth.cn-beijing.aliyuncs.com`;
|
||||
return new Cloudauth20190307.default(config);
|
||||
}
|
||||
}
|
||||
|
||||
class Id2MVServiceService extends Service {
|
||||
// 身份二要素核验
|
||||
async checkIdCard(idCard, name) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let client = Client.createClient();
|
||||
// 创建请求对象并设置入参
|
||||
let id2MetaVerifyRequest = new Cloudauth20190307.Id2MetaVerifyRequest({
|
||||
paramType: "md5",
|
||||
identifyNum: idCard.substring(0, 6) + this.calculateMD5(idCard.substring(6, 14)) + idCard.substring(14),
|
||||
userName: this.calculateMD5(name.substring(0, 1)) + name.substring(1),
|
||||
});
|
||||
// 创建运行时配置对象
|
||||
let runtime = new Util.RuntimeOptions({});
|
||||
runtime.readTimeout = 5000;
|
||||
runtime.connectTimeout = 5000;
|
||||
// 发起请求
|
||||
const response = await client.id2MetaVerifyWithOptions(id2MetaVerifyRequest, runtime);
|
||||
const { code, data } = response.body;
|
||||
if(code == "OK" && data.isConsistent == "1") return { status: 1, msg: "姓名与身份证信息核验一致" };
|
||||
if(code == "OK" && data.isConsistent == "2") return { status: 2, msg: "姓名与身份证信息核验不一致" };
|
||||
if(code == "OK" && data.isConsistent == "3") return { status: 3, msg: "查无此人" };
|
||||
} catch (error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
// console.log('1===========================================')
|
||||
// console.log(error.message);
|
||||
// 若捕捉到 ConnectTimeout 错误,则尝试重发
|
||||
if(error.message.includes("ConnectTimeout")) return { status: 600, msg: "尝试重新核验" };
|
||||
// console.log('2===========================================')
|
||||
// 诊断地址
|
||||
console.log(error);
|
||||
// console.log('3===========================================')
|
||||
// console.log(error.data);
|
||||
// console.log('4===========================================')
|
||||
// console.log(error.data["Recommend"]);
|
||||
// Util.default.assertAsString(error.message);
|
||||
|
||||
const blockName = fileName + "--" + "checkIdCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Id2MVServiceService;
|
||||
Reference in New Issue
Block a user