197 lines
5.0 KiB
JavaScript
197 lines
5.0 KiB
JavaScript
'use strict';
|
|
const { verify } = require("crypto");
|
|
var CryptoJS = require("crypto-js");
|
|
var vk; // 全局vk实例
|
|
// 涉及的表名
|
|
const dbName = {
|
|
//test: "vk-test", // 测试表
|
|
};
|
|
|
|
var db = uniCloud.database(); // 全局数据库引用
|
|
var _ = db.command; // 数据库操作符
|
|
var $ = _.aggregate; // 聚合查询操作符
|
|
/**
|
|
* 权限注意:访问以下链接查看
|
|
* 文档地址:https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#内置权限
|
|
*/
|
|
var cloudObject = {
|
|
isCloudObject: true, // 标记为云对象模式
|
|
/**
|
|
* 请求前处理,主要用于调用方法之前进行预处理,一般用于拦截器、统一的身份验证、参数校验、定义全局对象等。
|
|
* 文档地址:https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#before-预处理
|
|
*/
|
|
_before: async function() {
|
|
vk = this.vk; // 将vk定义为全局对象
|
|
// let { customUtil, uniID, config, pubFun } = this.getUtil(); // 获取工具包
|
|
},
|
|
/**
|
|
* 请求后处理,主要用于处理本次调用方法的返回结果或者抛出的错误
|
|
* 文档地址:https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#after-后处理
|
|
*/
|
|
_after: async function(options) {
|
|
let { err, res } = options;
|
|
if (err) {
|
|
return; // 如果方法抛出错误,直接return;不处理
|
|
}
|
|
return res;
|
|
},
|
|
/**
|
|
* 获取列表
|
|
* @url client/fadada.getList 前端调用的url参数地址
|
|
*/
|
|
getList: async function(data) {
|
|
let res = { code: 0, msg: '' };
|
|
let { uid } = this.getClientInfo(); // 获取客户端信息
|
|
// 业务逻辑开始-----------------------------------------------------------
|
|
|
|
|
|
// 业务逻辑结束-----------------------------------------------------------
|
|
return res;
|
|
},
|
|
/**
|
|
* 模板函数
|
|
* @url client/fadada.test 前端调用的url参数地址
|
|
*/
|
|
test: async function(data) {
|
|
|
|
},
|
|
/**
|
|
* 实名认证异步通知回调
|
|
* @param {Object} data
|
|
*/
|
|
async pub_verifyNotify(data) {
|
|
let { customUtil, uniID, config, pubFun } = this.getUtil(); // 获取工具包
|
|
const {customerId} = data;
|
|
// 查询认证结果
|
|
let user = await vk.baseDao.findByWhereJson({
|
|
dbName:"uni-id-users",
|
|
whereJson:{
|
|
fadadaCustomerId: customerId,
|
|
}
|
|
});
|
|
let res
|
|
|
|
if(user.accountType == 1) {
|
|
res = await pubFun.fadada('find_personCertInfo.api', {
|
|
verified_serialno: user.fadadaVerify.transactionNo
|
|
})
|
|
}else {
|
|
res = await pubFun.fadada('find_companyCertInfo.api', {
|
|
verified_serialno: user.fadadaVerify.transactionNo
|
|
})
|
|
}
|
|
|
|
|
|
|
|
// 认证成功
|
|
if(res.code == 1) {
|
|
await vk.baseDao.setById({
|
|
dbName:"fadada-verify-record",
|
|
dataJson:{
|
|
_id: user._id,
|
|
...res.data
|
|
}
|
|
})
|
|
|
|
await vk.baseDao.updateById({
|
|
dbName:"uni-id-users",
|
|
id: user._id,
|
|
dataJson:{
|
|
person: res.data.person,
|
|
company: res.data.company,
|
|
manager: res.data.manager,
|
|
BankCard: res.data.BankCard,
|
|
fadadaConfirm: true
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
return res
|
|
},
|
|
/**
|
|
* 获取用户认证结果
|
|
*/
|
|
async getVerifyResult() {
|
|
let { customUtil, uniID, config, pubFun } = this.getUtil(); // 获取工具包
|
|
let res = { code: 0, msg: '' };
|
|
let { uid } = this.getClientInfo(); // 获取客户端信息
|
|
let {accountType,fadadaCustomerId} = await this.getUserInfo();
|
|
|
|
res.data = await vk.baseDao.findById({
|
|
dbName:"fadada-verify-record",
|
|
id: uid
|
|
});
|
|
|
|
|
|
return res
|
|
},
|
|
/**
|
|
* 获取实名认证地址
|
|
*/
|
|
async getVerifyUrl() {
|
|
let { customUtil, uniID, config, pubFun } = this.getUtil(); // 获取工具包
|
|
let res = { code: 0, msg: '' };
|
|
let { uid } = this.getClientInfo(); // 获取客户端信息
|
|
let {accountType,fadadaCustomerId, fadadaVerify} = await this.getUserInfo();
|
|
// 业务逻辑开始-----------------------------------------------------------
|
|
|
|
if(fadadaVerify) {
|
|
res.data = fadadaVerify
|
|
return res;
|
|
}
|
|
|
|
|
|
let verify_url_res ;
|
|
|
|
if(accountType === 1) {
|
|
verify_url_res = await pubFun.fadada('get_person_verify_url.api', {
|
|
customer_id: fadadaCustomerId,
|
|
verified_way: 2,
|
|
page_modify: 1,
|
|
notify_url: 'https://fc-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/fadada_verify_notify'
|
|
|
|
})
|
|
}else {
|
|
verify_url_res = await pubFun.fadada('get_company_verify_url.api', {
|
|
customer_id: fadadaCustomerId,
|
|
page_modify: 1,
|
|
notify_url: 'https://fc-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/fadada_verify_notify'
|
|
})
|
|
console.log(': ',);
|
|
}
|
|
|
|
console.log('verify_url_res: ',verify_url_res);
|
|
let {transactionNo, url} = verify_url_res.data
|
|
var parsedWordArray = CryptoJS.enc.Base64.parse(url);
|
|
url = parsedWordArray.toString(CryptoJS.enc.Utf8);
|
|
|
|
await vk.baseDao.update({
|
|
dbName: "uni-id-users",
|
|
whereJson: {
|
|
_id: uid
|
|
},
|
|
dataJson: {
|
|
fadadaVerify: {
|
|
transactionNo,
|
|
url
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
|
|
res.data = {
|
|
transactionNo,
|
|
url
|
|
}
|
|
|
|
// 业务逻辑结束-----------------------------------------------------------
|
|
return res;
|
|
|
|
}
|
|
};
|
|
|
|
module.exports = cloudObject;
|