Commit 0c6c7cfc by linboxuan

Merge branch 'center-channel' of http://gitlab.gongsibao.com/jiangyong/zhichan into center-channel

parents 6eca1879 d54106be
var url = require("url"); var url = require("url");
var system = require("../../base/system"); var system = require("../../base/system");
const utilsAuthSve = system.getObject("service.utilsSve.utilsAuthSve"); const utilsAuthSve = system.getObject("service.utilsSve.utilsAuthSve");
const logCtl = system.getObject("service.common.oplogSve"); const logCtl = system.getObject("service.common.oplogSve");
const utilsOrderSve = system.getObject("service.utilsSve.utilsOrderSve"); const utilsOrderSve = system.getObject("service.utilsSve.utilsOrderSve");
const utilsFeishuSve = system.getObject("service.utilsSve.utilsFeishuSve"); const utilsFeishuSve = system.getObject("service.utilsSve.utilsFeishuSve");
var axios = require('axios');
var md5 = require('md5'); var md5 = require('md5');
var xml2js = require('xml2js'); var xml2js = require('xml2js');
...@@ -77,6 +76,130 @@ module.exports = function (app) { ...@@ -77,6 +76,130 @@ module.exports = function (app) {
}); });
} }
}); });
//----------------------飞书小程序---------------------------------------------开始
//飞书通知
app.use('/feishu/notify', async function (req, res) {
try {
var client_ip = system.get_client_ip(req);
var result = await utilsFeishuSve.notify(req.body);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "飞书小程序记录回调处理结果,method=notify",
op: "app/config/routes/api.js/feishu/notify",
content: "回调参数:" + JSON.stringify(req.body) + "回调结果:" + JSON.stringify(result),
clientIp: client_ip || ""
});
var returnObj = JSON.stringify(result);
return res.end(returnObj);
} catch (error) {
logCtl.error({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "飞书小程序记录回调处理结果异常:,method=notify",
op: "app/config/routes/api.js/feishu/notify",
content: "回调参数:" + JSON.stringify(req.body) + "error:" + error.stack,
clientIp: client_ip || ""
});
}
});
app.use('/feishu/login', async function (req, res) {
try {
var result = system.getResult(null, "login fail");
// console.log(req,"/feishu/login++++++++++++++++++++++++++++++++++++++");
var client_ip = system.get_client_ip(req);
var pobj = req.query;
var token = pobj.state || "";
if (!token) {
result.msg = "req headers token can not be empty";
result.data = null;
res.end(JSON.stringify(result));
return;
}
var cacheManager = system.getObject("db.common.cacheManager");
var result = await cacheManager["AppTokenByHostsCache"].getCache(token, system.exTime);
if (result.status != 0) {
res.end(JSON.stringify(result));
return;
}
pobj.appInfo = result.data;
result = await utilsFeishuSve.checkAndLogin(pobj);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "飞书小程序记录回调处理结果,method=login",
op: "app/config/routes/api.js/feishu/notify",
content: "回调参数:" + JSON.stringify(pobj) + "回调结果:" + JSON.stringify(result),
clientIp: client_ip || ""
});
var returnObj = JSON.stringify(result);
return res.end(returnObj);
} catch (error) {
logCtl.error({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "飞书小程序记录回调处理结果异常:,method=login",
op: "app/config/routes/api.js/feishu/notify",
content: "回调参数:" + JSON.stringify(req.query) + "error:" + error.stack,
clientIp: client_ip || ""
});
}
});
//----------------------飞书小程序---------------------------------------------结束
// app-ali支付回调通知
app.use('/orderNotify/aliPayNotify', async function (req, res) {
try{
var client_ip = system.get_client_ip(req);
var result = await utilsOrderSve.aliPayNotify(req.body, client_ip);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "记录支付宝回调处理结果 api层",
op: "center-channel/orderNotify/aliPayNotify",
content: "支付回调处理结果:" + JSON.stringify(result),
clientIp: client_ip || ""
});
if (result.status != 0) {
return res.end("FAIL");
}
return res.end("success");
} catch(e) {
logCtl.error({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "支付宝回调处理异常 api层",
op: "center-channel/orderNotify/aliPayNotify",
content: "回调参数:req=" + JSON.stringify(req) + "error:" + e.stack,
clientIp: client_ip || ""
});
}
});
// app-wx支付回调
app.use('/orderNotify/wxPayNotify', async function (req, res) {
try{
var body = "";
req.on('data', function(data) {
body += data;
});
req.on('end', async function() {
xml2js.parseString(body, { trim: true, explicitArray: false, explicitRoot: false }, async function(err, json) {
var client_ip = system.get_client_ip(req);
var result = await utilsOrderSve.wxPayNotify(json);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "记录微信支付回调处理结果",
op: "center-channel/orderNotify/wxPayNotify",
content: "支付回调处理结果:" + JSON.stringify(result),
clientIp: client_ip || ""
});
if (result.status != 0) {
return res.end("FAIL");
}
return res.end("success");
})
})
} catch(e) {
logCtl.error({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "微信回调处理异常",
op: "center-channel/orderNotify/wxPayNotify",
content: "回调参数:req=" + JSON.stringify(req) + "error:" + e.stack,
clientIp: client_ip || ""
});
}
});
app.all("/web/*", async function (req, res, next) { app.all("/web/*", async function (req, res, next) {
var result = system.getResult(null, "req method must is post"); var result = system.getResult(null, "req method must is post");
if (req.method != "POST") { if (req.method != "POST") {
...@@ -329,71 +452,6 @@ module.exports = function (app) { ...@@ -329,71 +452,6 @@ module.exports = function (app) {
//-----------------------新的模式---------api---------结束 //-----------------------新的模式---------api---------结束
//----------------------飞书小程序---------------------------------------------开始
//飞书通知
app.use('/feishu/notify', async function (req, res) {
try {
var client_ip = system.get_client_ip(req);
var result = await utilsFeishuSve.notify(req.body);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "飞书小程序记录回调处理结果,method=notify",
op: "app/config/routes/api.js/feishu/notify",
content: "回调参数:" + JSON.stringify(req.body) + "回调结果:" + JSON.stringify(result),
clientIp: client_ip || ""
});
var returnObj = JSON.stringify(result);
return res.end(returnObj);
} catch (error) {
logCtl.error({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "飞书小程序记录回调处理结果异常:,method=notify",
op: "app/config/routes/api.js/feishu/notify",
content: "回调参数:" + JSON.stringify(req.body) + "error:" + error.stack,
clientIp: client_ip || ""
});
}
});
app.use('/feishu/login', async function (req, res) {
try {
var result = system.getResult(null, "login fail");
// console.log(req,"/feishu/login++++++++++++++++++++++++++++++++++++++");
var client_ip = system.get_client_ip(req);
var pobj = req.query;
var token = pobj.state || "";
if (!token) {
result.msg = "req headers token can not be empty";
result.data = null;
res.end(JSON.stringify(result));
return;
}
var cacheManager = system.getObject("db.common.cacheManager");
var result = await cacheManager["AppTokenByHostsCache"].getCache(token, system.exTime);
if (result.status != 0) {
res.end(JSON.stringify(result));
return;
}
pobj.appInfo = result.data;
result = await utilsFeishuSve.checkAndLogin(pobj);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "飞书小程序记录回调处理结果,method=login",
op: "app/config/routes/api.js/feishu/notify",
content: "回调参数:" + JSON.stringify(pobj) + "回调结果:" + JSON.stringify(result),
clientIp: client_ip || ""
});
var returnObj = JSON.stringify(result);
return res.end(returnObj);
} catch (error) {
logCtl.error({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "飞书小程序记录回调处理结果异常:,method=login",
op: "app/config/routes/api.js/feishu/notify",
content: "回调参数:" + JSON.stringify(req.query) + "error:" + error.stack,
clientIp: client_ip || ""
});
}
});
//----------------------飞书小程序---------------------------------------------结束
//--------------------------起名宝------------------------------------// //--------------------------起名宝------------------------------------//
app.post('/name/:gname/:qname/:method', function (req, res) { app.post('/name/:gname/:qname/:method', function (req, res) {
var classPath = req.params["qname"]; var classPath = req.params["qname"];
...@@ -409,7 +467,7 @@ module.exports = function (app) { ...@@ -409,7 +467,7 @@ module.exports = function (app) {
params.push(gname); params.push(gname);
params.push(methodName); params.push(methodName);
params.push(req.body); params.push(req.body)
params.push(req.query); params.push(req.query);
params.push(req); params.push(req);
var p = null; var p = null;
...@@ -421,63 +479,4 @@ module.exports = function (app) { ...@@ -421,63 +479,4 @@ module.exports = function (app) {
res.end(JSON.stringify(r)); res.end(JSON.stringify(r));
}); });
}); });
// 支付回调通知
app.use('/orderNotify/aliPayNotify', async function (req, res) {
try{
var client_ip = system.get_client_ip(req);
var result = await utilsOrderSve.aliPayNotify(req.body, client_ip);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "记录支付宝回调处理结果 api层",
op: "center-channel/orderNotify/aliPayNotify",
content: "支付回调处理结果:" + JSON.stringify(result),
clientIp: client_ip || ""
});
if (result.status != 0) {
return res.end("FAIL");
}
return res.end("success");
} catch(e) {
logCtl.error({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "支付宝回调处理异常 api层",
op: "center-channel/orderNotify/aliPayNotify",
content: "回调参数:req=" + JSON.stringify(req) + "error:" + e.stack,
clientIp: client_ip || ""
});
}
});
// wx支付回调
app.use('/orderNotify/wxPayNotify', async function (req, res) {
try{
var body = "";
req.on('data', function(data) {
body += data;
});
req.on('end', async function() {
xml2js.parseString(body, { trim: true, explicitArray: false, explicitRoot: false }, async function(err, json) {
var client_ip = system.get_client_ip(req);
var result = await utilsOrderSve.wxPayNotify(json);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "记录微信支付回调处理结果",
op: "center-channel/orderNotify/wxPayNotify",
content: "支付回调处理结果:" + JSON.stringify(result),
clientIp: client_ip || ""
});
if (result.status != 0) {
return res.end("FAIL");
}
return res.end("success");
})
})
} catch(e) {
logCtl.error({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "微信回调处理异常",
op: "center-channel/orderNotify/wxPayNotify",
content: "回调参数:req=" + JSON.stringify(req) + "error:" + e.stack,
clientIp: client_ip || ""
});
}
});
}; };
\ No newline at end of file
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