Commit 6c66c2eb by 宋毅

tj

parent c8923764
......@@ -191,5 +191,83 @@ class APIBase {
return rtnerror;
}
}
//-----------------------新的模式------------------开始
async doexecMethod(gname, methodname, pobj, query, req) {
var requestid = req.headers["request-id"] || this.getUUID();
if (!req.headers["request-id"]) {
req.headers["request-id"] = requestid;
}
try {
if (pobj.actionType == "createChannelUser") {
if (!pobj.isUser) {
system.getResult(null, "isUser is empty");
}
if (pobj.isUser != "yes") {
system.getResult(null, "isUser value must yes");
}
}
// //验证accesskey或验签
// var isPassResult = await this.checkAcck(gname, methodname, pobj, query, req);
// if (isPassResult.status != 0) {
// isPassResult.requestId = "";
// return isPassResult;
// }
if (pobj.actionType == "createChannelUser") {
var encryptResult = await this.toolSve.encryptStr(req.app, req.user.channelUserId);
if (encryptResult.status != 0) {
system.getResult(null, "encrypt channelUserId is error");
}
req.user.encryptChannelUserId = encryptResult.data;
return system.getResultSuccess(req.user);
}//创建用户
req.requestId = requestid;
var rtn = await this[methodname](pobj, query, req);
if (rtn && !rtn.requestId) {
rtn.requestId = requestid;
}
this.oplogSve.createDb({
appid: req.app.id,
appkey: req.app.uappKey,
requestId: requestid,
op: req.classname + "/" + methodname,
content: JSON.stringify(pobj),
resultInfo: JSON.stringify(rtn),
clientIp: req.clientIp,
agent: req.uagent,
opTitle: "api服务提供方appKey:" + settings.appKey,
});
return rtn;
} catch (e) {
console.log(e.stack, "api调用出现异常,请联系管理员..........")
this.oplogSve.createDb({
appid: req.app.id,
appkey: req.app.uappKey,
requestId: requestid,
op: req.classname + "/" + methodname,
content: JSON.stringify(pobj),
resultInfo: JSON.stringify(e.stack),
clientIp: req.clientIp,
agent: req.uagent,
opTitle: "api调用出现异常,请联系管理员error,appKey:" + settings.appKey,
});
this.logCtl.error({
appid: req.app.id,
appkey: req.app.uappKey,
requestId: requestid,
op: pobj.classname + "/" + methodname,
content: e.stack,
clientIp: pobj.clientIp,
agent: req.uagent,
optitle: "api调用出现异常,请联系管理员",
});
var rtnerror = system.getResultFail(-200, "出现异常,error:" + e.stack);
rtnerror.requestId = requestid;
return rtnerror;
}
}
//-----------------------新的模式------------------结束
}
module.exports = APIBase;
......@@ -8,6 +8,5 @@ var settings = {
db:path.join(basepath,"app/base/db/impl"),
tool:path.join(basepath,"app/base/tool"),
service2:path.join(basepath,"app/base/service"),
applet:path.join(basepath,"app/base/wxapplet/impl"),
};
module.exports = settings;
......@@ -60,56 +60,61 @@ module.exports = function (app) {
res.end(JSON.stringify(r));
});
});
// app.get('/api/:gname/:qname/:method', function (req, res) {
// var classPath = req.params["qname"];
// var methodName = req.params["method"];
// var gname = req.params["gname"];
// classPath = gname + "." + classPath;
// var tClientIp = system.get_client_ip(req);
// req.clientIp = tClientIp;
// req.uagent = req.headers["user-agent"];
// req.classname = classPath;
//-----------------------新的模式------------------开始
// var params = [];
// params.push(gname);
// params.push(methodName);
// params.push(req.body);
// params.push(req.query);
// params.push(req);
// var p = null;
// var invokeObj = system.getObject("api." + classPath);
// if (invokeObj["doexec"]) {
// p = invokeObj["doexec"].apply(invokeObj, params);
// }
// p.then(r => {
// res.end(JSON.stringify(r));
// });
// });
// app.post('/api/:gname/:qname/:method', function (req, res) {
// var classPath = req.params["qname"];
// var methodName = req.params["method"];
// var gname = req.params["gname"];
// var params = [];
// classPath = gname + "." + classPath;
// var tClientIp = system.get_client_ip(req);
app.get('/web/:gname/:qname/:method', function (req, res) {
var classPath = req.params["qname"];
var methodName = req.params["method"];
var gname = req.params["gname"];
// req.clientIp = tClientIp;
// req.uagent = req.headers["user-agent"];
// req.classname = classPath;
classPath = gname + "." + classPath;
var tClientIp = system.get_client_ip(req);
req.clientIp = tClientIp;
req.uagent = req.headers["user-agent"];
req.classname = classPath;
// params.push(gname);
// params.push(methodName);
// params.push(req.query);
// params.push(req.body);
// params.push(req);
// var p = null;
// var invokeObj = system.getObject("api." + classPath);
// if (invokeObj["doexec"]) {
// p = invokeObj["doexec"].apply(invokeObj, params);
// }
// p.then(r => {
// res.end(JSON.stringify(r));
// });
// });
var params = [];
params.push(gname);
params.push(methodName);
params.push(req.body);
params.push(req.query);
params.push(req);
var p = null;
var invokeObj = system.getObject("api." + classPath);
if (invokeObj["doexecMethod"]) {
p = invokeObj["doexecMethod"].apply(invokeObj, params);
}
p.then(r => {
res.end(JSON.stringify(r));
});
});
app.post('/web/:gname/:qname/:method', function (req, res) {
var classPath = req.params["qname"];
var methodName = req.params["method"];
var gname = req.params["gname"];
var params = [];
classPath = gname + "." + classPath;
var tClientIp = system.get_client_ip(req);
req.clientIp = tClientIp;
req.uagent = req.headers["user-agent"];
req.classname = classPath;
params.push(gname);
params.push(methodName);
params.push(req.query);
params.push(req.body);
params.push(req);
var p = null;
var invokeObj = system.getObject("api." + classPath);
if (invokeObj["doexecMethod"]) {
p = invokeObj["doexecMethod"].apply(invokeObj, params);
}
p.then(r => {
res.end(JSON.stringify(r));
});
});
//-----------------------新的模式------------------结束
};
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