Commit 8e1d3ac7 by 王昆

gsb

parent c4ed4688
......@@ -159,11 +159,59 @@ class BpoSDPJApi {
}
async setNo(no){
return no;
return system.encryption(no);
}
async getNo(no) {
return no;
return system.decryption(no);
}
/**
* 二维码作废
* @param obj
* @param req
* @returns {Promise<{msg: string, code: number, data: {}}>}
*/
async removeQRCode(obj, req) {
try {
let params = {
appId: obj.appId,
mchtId: obj.mchtId,
ecid: obj.ecid,
outTradeNo: obj.outTradeNo,
nonceStr: obj.nonceStr,
sign: obj.sign,
};
let api = await this.ecompanybusiSve.findOne({
appId: obj.appId,
etemplate_id: obj.ecid,
mchtId: obj.mchtId,
});
if (!api) {
return this.getBaseResult(1001003, "配置信息错误,请联系薪必果人员进行配置");
}
let sign = system.getSign(params, api.key, this.EXCEPT_KEYS);
if (obj.sign != sign) {
return this.getBaseResult(1001001, "签名失败");
}
let cashInfo = await this.ccashinfoSve.findOne({
mchtId: params.mchtId,
outTradeNo: params.outTradeNo,
});
if (!cashInfo) {
return this.getErrResult("二维码不存在");
}
cashInfo.qrcode_status = 2;
await cashInfo.save();
} catch (e) {
console.log(e);
return this.getErrResult("接口异常");
}
return this.getSuccessResult();
}
/**
......@@ -203,12 +251,13 @@ class BpoSDPJApi {
* @returns {Promise<void>}
*/
async authentication(obj, req){
if(!obj || !obj.id_name || !obj.id_no || !obj.no){
if(!obj || !obj.id_name || !obj.id_no || !obj.no || !obj.openId){
return this.getCodeResult(1002001,null);
}
let id = this.getNo(obj.no);
try{
let ccashinfo = await this.ccashinfoSve.getBean({
id: this.getNo(obj.no)
id: id
});
if(!ccashinfo){
this.getErrResult("信息不存在");
......@@ -266,15 +315,27 @@ class BpoSDPJApi {
if(!obj.no){
return this.getBaseResult(1, 'ID不能为空');
}
let key = `SDPJ_CASH_${ccashinfo.id}`;
let _lock = uuidv1();
try {
let ccashinfo = await this.ccashinfoSve.getBean({
id: this.getNo(obj.no)
});
if(!ccashinfo){
this.getErrResult("信息不存在");
return this.getErrResult("信息不存在");
}
return await this.cashOut(ccashinfo);
}catch (e) {
if (ccashinfo.qrcode_status != 1) {
return this.getErrResult("二维码已作废,禁止提现");
}
if (ccashinfo.trade_status != "00") {
return this.getErrResult("已提现,不要重复提现");
}
await this.redisLock.lock(key, _lock, 20);
let result = await this.cashOut(ccashinfo);
} catch (e) {
console.log(e);
let result = {
code: 500,
......@@ -282,6 +343,8 @@ class BpoSDPJApi {
};
console.log(e.stack);
return result;
} finally {
await this.redisLock.unLock(key, _lock);
}
}
......
......@@ -2,6 +2,7 @@ var fs=require("fs");
var objsettings=require("../config/objsettings");
var settings=require("../config/settings");
const crypto = require('crypto');
const md5 = require('md5');
class System {
static declare(ns) {
......@@ -267,6 +268,24 @@ class System {
cipherChunks.push(decipher.final('utf8'));
return cipherChunks.join('');
}
static getSign(params, secret, exceptKeys = []) {
console.log("---------签名参数-----------", params, secret, exceptKeys);
let keys = Object.keys(params).sort();
let signArr = [];
for (let k = 0; k < keys.length; k++) {
let tKey = keys[k];
if (exceptKeys.indexOf(tKey) == -1 && params[tKey]) {
signArr.push(tKey + "=" + params[tKey]);
}
}
let signStr = signArr.join("&") + "&key=" + secret;
let sign = md5(signStr).toUpperCase();
console.log("---------签名结果-----------", signStr, sign);
return sign;
}
// static buildObjectFactory(){
// for(var k in objsettings){
// let classpath=objsettings[k];
......
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