Commit 85d10e42 by 王昆

gsb

parent 4ac220de
var system = require("../../system")
const md5 = require("md5");
class BpWXSignApi {
constructor() {
this.cwxsignapiSve = system.getObject("service.cwxsignapiSve");
this.redisClient = system.getObject("util.redisClient");
this.cwxsigninfoSve = system.getObject("service.cwxsigninfoSve");
this.utilesignbaoSve = system.getObject("service.utilesignbaoSve");
this.ecompanySve = system.getObject("service.ecompanySve");
this.etemplateSve = system.getObject("service.etemplateSve");
this.econtractSve = system.getObject("service.econtractSve");
this.dkcompanySve = system.getObject("service.dkcompanySve");
this.dktemplateSve = system.getObject("service.dktemplateSve");
this.dkcontractSve = system.getObject("service.dkcontractSve");
this.EXCEPT_KEYS = ['sign'];
}
trim(o) {
if(!o) {
return "";
}
return o.toString().trim();
}
/**
* 生成二维码
* @param obj
* @param req
* @returns {Promise<{msg: string, code: number}>}
*/
async cashQRCode(obj, req) {
// 验证合法性
let p = {
appId: this.trim(obj.appId),
nonceStr: this.trim(obj.nonceStr),
ecid: Number(obj.ecid || 0),
idNo: this.trim(obj.idNo),
};
let keys = Object.keys(p).sort();
let signArr = [];
for (let k = 0; k < keys.length; k++) {
let tKey = keys[k];
if (this.EXCEPT_KEYS.indexOf(tKey) == -1 && p[tKey]) {
signArr.push(tKey + "=" + p[tKey]);
}
}
let signStr = signArr.join("&") + "&key=" + api.app_secret;
let sign = md5(signStr).toUpperCase();
console.log(obj.sign, signStr, sign);
if (sign != obj.sign) {
return {
code: 1001001,
msg: "签名失败"
};
}
try {
return {code: 0, msg: "暂未提供,工程师正在紧急加班开发"};
} catch (e) {
let result = {
code: 500,
msg: "接口异常"
};
console.log(e.stack);
return result;
}
}
}
module.exports = BpWXSignApi;
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