Commit 14c999f5 by 王昆

gsb

parent 98166452
......@@ -56,7 +56,34 @@ class BpoSDPJApi {
* @returns {Promise<{msg: string, code: number}>}
*/
async cashQRCode(obj, req) {
// 验证合法性
// 检验所有参数是否完整 如果出现非法参数直接返回
if (!obj.appId) {
return this.getBaseResult(1002001,"appId不存在");
}
if (!obj.mchtId) {
return this.getBaseResult(1002001,"mchtId不存在");
}
if (!obj.outTradeNo) {
return this.getBaseResult(1002001,"outTradeNo不存在");
}
if (!obj.amt) {
return this.getBaseResult(1002001,"请设置申请金额");
}
if (!obj.ecid) {
return this.getBaseResult(1002001,"ecid不存在");
}
// 获取api信息
let api = await this.ecompanybusiSve.findOne({
appId: obj.appId,
etemplate_id: obj.ecid,
mchtId: obj.mchtId,
});
if (!api) {
return this.getBaseResult(1001003, "配置信息错误,请联系薪必果人员进行配置");
}
// 签名验证
let param = {
appId: obj.appId,
ecid: obj.ecid,
......@@ -67,85 +94,46 @@ class BpoSDPJApi {
outTradeNo: obj.outTradeNo,
nonceStr: obj.nonceStr
};
let api = await this.ecompanybusiSve.findOne({
appId: obj.appId,
etemplate_id: obj.ecid,
mchtId: obj.mchtId,
});
if (!api) {
return this.getBaseResult(1001003, "配置信息错误,请联系薪必果人员进行配置");
}
let keys = Object.keys(param).sort();
let signArr = [];
for (let k = 0; k < keys.length; k++) {
let tKey = keys[k];
if (this.EXCEPT_KEYS.indexOf(tKey) == -1 && param[tKey]) {
signArr.push(tKey + "=" + param[tKey]);
}
}
let signStr = signArr.join("&") + "&key=" + api.key;
let sign = md5(signStr).toUpperCase();
console.log(obj.sign, signStr, sign);
let sign = system.getSign(param, api.key, this.EXCEPT_KEYS);
if (sign != obj.sign) {
return this.getBaseResult(1001001, "签名失败");
}
try {
if(!obj || !obj.outTradeNo || !obj.mchtId){
return this.getCodeResult(1002001,null);
}
//1.mchtId & ecid 进行联合查询 如果存在直接返回
let _cCashInfo = await this.ccashinfoSve.getBean(obj);
// mchtId & ecid 进行联合查询 如果存在直接返回
let _cCashInfo = await this.ccashinfoSve.findOne({
app_id: obj.appId,
mchtId: obj.mchtId,
outTradeNo: obj.outTradeNo,
}) || {};
console.log(`bpoSDPJApi.js -> cashQRCode -> mchtId & ecid 进行联合查询 :参数=` + JSON.stringify(obj) + " _cCashInfo = " + JSON.stringify(_cCashInfo));
//如果二维码有效直接返回
if(_cCashInfo.qrcode_status && _cCashInfo.qrcode){
if( _cCashInfo.qrcode_status && _cCashInfo.qrcode){
return this.getCodeResult(0,{"qrcode": _cCashInfo.qrcode});
}
//如果二维码没有 可以继续生成二维码
if(_cCashInfo && _cCashInfo.qrcode){
return this.getCodeResult(1002001,null);
}
//2.检验所有参数是否完整 如果出现非法参数直接返回
if(!obj.ecid || !obj.appId || !obj.amt){
return this.getCodeResult(1002001,null);
}
//3.获取签约类型
let _ecompanybusi = await this.ecompanybusiDao.model.findOne({
where:{
appId: this.trim(obj.appId),
mchtId: this.trim(obj.mchtId)
}
});
console.log("查看签约类型 _ecompanybusi=" + JSON.stringify(_ecompanybusi));
if(!_ecompanybusi || !_ecompanybusi.dataValues.hasOwnProperty("app_type")){
return this.getCodeResult(500,null);
}
let _ccashinfoProperty = {};
_ccashinfoProperty.app_type = _ecompanybusi.app_type;
_ccashinfoProperty.outTradeNo = obj.outTradeNo;
_ccashinfoProperty.mchtId = obj.mchtId;
_ccashinfoProperty.ecid = _ecompanybusi.etemplate_id;
_ccashinfoProperty.app_id = obj.appId;
_ccashinfoProperty.amt = Number(obj.amt || 0);
_ccashinfoProperty.idName = this.trim(obj.idName) || "";
_ccashinfoProperty.idNo = this.trim(obj.idNo) || "" ;
//4.保存签约数据
_cCashInfo = await this.ccashinfoSve.save(_ccashinfoProperty);
if(!_cCashInfo){
return this.getCodeResult(500,null);
if (!_cCashInfo.id) {
_cCashInfo.app_type = _ecompanybusi.app_type;
_cCashInfo.outTradeNo = obj.outTradeNo;
_cCashInfo.mchtId = obj.mchtId;
_cCashInfo.ecid = _ecompanybusi.etemplate_id;
_cCashInfo.app_id = obj.appId;
_cCashInfo.amt = Number(obj.amt || 0);
_cCashInfo.idName = this.trim(obj.idName) || "";
_cCashInfo.idNo = this.trim(obj.idNo) || "" ;
// 保存签约数据
_cCashInfo = await this.ccashinfoSve.create(_cCashInfo);
}
//5. 拼接h5 http连接 http//xxx?mchtId=xxx&ecid=xxx&no=id
// 拼接h5 http连接 http//xxx?mchtId=xxx&ecid=xxx&no=id
let _no = await this.setNo(_cCashInfo.id);
let custormUrl = `http://bpohhr.gongsibao.com?no=${_no}&outTradeNo=${_cCashInfo.outTradeNo}&mchtId=${_cCashInfo.mchtId}`;
//6.生成二维码
// 生成二维码
let url =await this.qrClient.generateQR(custormUrl);
_cCashInfo.qrcode=url;
_cCashInfo.qrcode_status=url?1:2;
_cCashInfo.sign_url=custormUrl;
_cCashInfo.qrcode = url;
_cCashInfo.qrcode_status = url ? 1 : 2;
_cCashInfo.sign_url = custormUrl;
_cCashInfo.save();
return this.getCodeResult(0,{"qrcode": url || ""});
} catch (e) {
......
......@@ -47,11 +47,7 @@ class CcashinfoService extends ServiceBase {
return null;
}
try{
await this.dao.create(params);
let res = await this.getBean({
mchtId:params.mchtId,
outTradeNo:params.outTradeNo
})
let res = await this.dao.create(params);
return res;
}catch (e) {
console.log(e);
......
const system = require("../system");
const qr = require("qr-image");
var settings = require("../../config/settings");
var ossClient = require("./ossClient");
const fs = require("fs");
class QrClient{
constructor(){
this.redisClient = system.getObject("util.redisClient");
}
/**
......@@ -17,15 +19,16 @@ class QrClient{
if(!text){
return null;
}
let key = Math.random().toString(36).substr(2,6)+"_" + new Date().getTime(), filePath = settings.localPath();
let key = await this.redisClient.genrateId("qrcode") + ".png";
let filePath = settings.localPath();
var qr_png = qr.image(text, {size :10 });
let _r = await qr_png.pipe(require('fs').createWriteStream(`${filePath}${key}.png`));
let _r = await qr_png.pipe(require('fs').createWriteStream(`${filePath}${key}`));
console.log(_r);
if(!_r){
return null;
}
let urlRes = await new ossClient().upfile(key,`${filePath}${key}.png`);
fs.unlink(`${filePath}${key}.png`, (err) => {
let urlRes = await new ossClient().upfile(key,`${filePath}${key}`);
fs.unlink(`${filePath}${key}`, (err) => {
if (err){
console.log(`二维码删除失败`);
}
......
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