Commit bed102db by 王昆

gsb

parent fb84a94f
......@@ -15,6 +15,12 @@ class APIBase extends DocBase {
var u = uuid.replace(/\-/g, "");
return u;
}
trim(o) {
if (!o) {
return "";
}
return o.toString().trim();
}
/**
* 验证签名
* @param {*} params 要验证的参数
......@@ -95,12 +101,18 @@ class APIBase extends DocBase {
}
async doexec(gname, methodname, pobj, query, req) {
var requestid = this.getUUID();
let rtn;
try {
var rtn = await this[methodname](pobj, query, req);
rtn = await this[methodname](pobj, query, req) || {};
rtn.requestid = requestid;
} catch (e) {
console.log(e.stack, "api调用出现异常,请联系管理员..........")
rtn = system.getResultFail(-200, "出现异常,请联系管理员");
rtn.requestid = requestid;
}
try {
this.oplogSve.createDb({
appid: req.headers["app_id"] || "",
appid: "",
appkey: "",
requestId: requestid,
op: req.classname + "/" + methodname,
......@@ -110,23 +122,10 @@ class APIBase extends DocBase {
agent: req.uagent,
opTitle: "api服务提供方appKey:" + settings.appKey,
});
return rtn;
} catch (e) {
console.log(e.stack, "api调用出现异常,请联系管理员..........")
this.logCtl.error({
appid: "" + pobj.action_process,
appkey: "",
requestId: requestid,
op: pobj.classname + "/" + methodname,
content: e.stack,
clientIp: pobj.clientIp,
agent: req.uagent,
optitle: "api调用出现异常,请联系管理员",
});
var rtnerror = system.getResultFail(-200, "出现异常,请联系管理员");
rtnerror.requestid = requestid;
return rtnerror;
console.log(new Date(), requestid, e.stack);
}
return rtn;
}
}
module.exports = APIBase;
......
var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
const APIBase = require("../../api.base");
const system = require("../../../system");
const settings = require("../../../../config/settings");
const md5 = require("md5");
class ActionAPI extends APIBase {
constructor() {
super();
this.authSve = system.getObject("service.sign.authSve");
// this.userSve = system.getObject("service.user.userSve");
this.merchantSve = system.getObject("service.merchant.merchantSve");
}
/**
* 接口跳转
......@@ -14,9 +15,6 @@ class ActionAPI extends APIBase {
* action_body 执行的参数
*/
async springboard(pobj, qobj, req) {
// 接口层请求报文保存
await this.saveApiInfo(pobj.action_process, pobj.action_type, pobj.action_body);
let result;
if (!pobj.action_process) {
return system.getResult(null, "action_process参数不能为空");
......@@ -26,7 +24,10 @@ class ActionAPI extends APIBase {
}
try {
// 验证签名
await this.validSign(pobj.action_body);
let signRes = await this.validSign(pobj.action_body);
if (signRes.status !== 0) {
return signRes;
}
result = await this.handleRequest(pobj.action_process, pobj.action_type, pobj.action_body);
} catch (error) {
console.log(error);
......@@ -73,13 +74,44 @@ class ActionAPI extends APIBase {
return opResult;
}
async validSign() {
async validSign(params) {
// 1000000 报文参数问题 1001001 签名错误
let appId = this.trim(params.appId);
let timestamp = Number(params.timestamp);
let nonceStr = Number(params.nonceStr);
let now = new Date().getTime();
if (now - timestamp > 60 * 1000) {
return system.getResult(1000000, "请求超时");
}
if (!appId) {
return system.getResult(1000000, "请填写appId");
}
if (!nonceStr) {
return system.getResult(1000000, "随机码为空");
}
}
// TODO redis通过sign幂等验证
// 幂等验证代码xxxx
let app = await this.merchantSve.apiInfo({id: appId}).data || {};
if (!app.id) {
return system.getResult(1000000, "appId不存在");
}
async saveApiInfo() {
let keys = Object.keys(params).sort();
let signArr = [];
for (let k = 0; k < keys.length; k++) {
let tKey = keys[k];
if (tKey != "sign" && params[tKey]) {
signArr.push(tKey + "=" + params[tKey]);
}
}
let sign = md5(signArr.join("&") + "&key=" + app.secret).toUpperCase();
if (params.sign != sign) {
return system.getResult(1001001, "签名验证失败");
}
}
exam() {
return `<pre><pre/>`;
}
......
......@@ -6,41 +6,9 @@ class MerchantService extends ServiceBase {
super();
}
async merchantOfList(params) {
async apiInfo(params) {
try {
return await this.callms("sve_merchant", "merchantOfList", params);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
async merchantOfInfo(params) {
try {
return await this.callms("sve_merchant", "merchantOfInfo", params);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
async addModifyMerchants(params) {
try {
return await this.callms("sve_merchant", "addModifyMerchants", params);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
async merchantSuggest(params) {
try {
return await this.callms("sve_merchant", "merchantSuggest", params);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
async auditMerchant(params) {
try {
return await this.callms("sve_merchant", "auditMerchant", params);
return await this.callms("sve_merchant", "apiInfoById", params);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
......
const system = require("../../../system");
const ServiceBase = require("../../svems.base")
class MerchantaccountService extends ServiceBase {
constructor() {
super();
}
async reduceAccountBalance(params) {
try {
return await this.callms("sve_merchant", "reduceAccountBalance", params);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
async addordelavailable(params) {
try {
return await this.callms("sve_merchant", "addordelavailable", params);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
}
module.exports = MerchantaccountService;
......@@ -31,8 +31,9 @@ class AuthService extends ServiceBase {
async doAuth(params) {
// 1. 扣费
// 2. 调用认证引擎
// 3. 异步调用订单逻辑
// 3. 异步调用订单消费逻辑
// 4. 返回认证结果
}
}
......
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