Commit 6701fd59 by linboxuan

ucommunt-back

parent 7817f1e0
var WEBBase = require("../../web.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class ProductAPI extends WEBBase {
constructor() {
super();
this.utilsUcommuneSve = system.getObject("service.backUtilsSve.utilsUcommuneSve");
}
/**
* 优客工厂
* 接口跳转-POST请求
* action_type 执行的类型
* action_body 执行的参数
*/
async springBoard(pobj, qobj, req) {
if (!pobj.actionType) {
return system.getResult(null, "actionType参数不能为空");
}
var result = await this.opActionProcess(pobj, pobj.actionType, req);
return result;
}
async opActionProcess(pobj, action_type, req) {
var opResult = null;
switch (action_type) {
case "getStatistics":// 概览-业务统计
opResult = await this.utilsUcommuneSve.getStatistics(pobj, pobj.actionBody);
break;
case "getTrend":// 概览-业务统计
opResult = await this.utilsUcommuneSve.getTrend(pobj, pobj.actionBody);
break;
case "getProductTypesales":// 概览-产品销售分布
opResult = await this.utilsUcommuneSve.getProductTypesales(pobj, pobj.actionBody);
break;
case "getCustomerArea":// 概览-客户地域分布
opResult = await this.utilsUcommuneSve.getCustomerArea(pobj, pobj.actionBody);
break;
case "getOrderInfo":// 订单列表
opResult = await this.utilsUcommuneSve.getOrderInfo(pobj, pobj.actionBody);
break;
case "getOrderDelivery":// 订单详情
opResult = await this.utilsUcommuneSve.getOrderDelivery(pobj, pobj.actionBody);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
}
return opResult;
}
}
module.exports = ProductAPI;
\ No newline at end of file
var system = require("../../../system");
var settings = require("../../../../config/settings");
const AppServiceBase = require("../../app.base");
const axios = require('axios')
const md5 = require('md5')
var AlipaySdk = require('alipay-sdk').default;
var WXPay = require('wx-pay');
var xml2js = require('xml2js');
//产品操作类
class UtilsUcommuneService extends AppServiceBase {
constructor() {
super();
this.centerOrderUrl = settings.centerOrderUrl();
}
//--------------------------------优客工厂相关接口-start-----------------------------------------------------
/**
* 业务统计
* @param {*} pobj
* @param {*} actionBody
*/
async getStatistics(pobj, actionBody) {
var reqUrl = this.centerOrderUrl + "action/ucommuneOrder/springBoard";
var result = await this.restPostUrl(pobj, reqUrl);
return result;
}
/**
* 趋势分析
* @param {*} pobj
* @param {*} actionBody
*/
async getTrend(pobj, actionBody) {
var obj = {
date : ["1"],
pay : [0,1,2,3,4,5,6,7,8,9,0,1,2],
need : [0,1,2,3,4,5,6,7,8,9,0,1,2]
}
return system.getResultSuccess(obj);
}
/**
* 产品销售分布
* @param {*} pobj
* @param {*} actionBody
*/
async getProductTypesales(pobj, actionBody) {
var obj = {
productType : ["sbzc"],
sum : [666]
}
return system.getResultSuccess(obj);
}
/**
* 客户地域分布
* @param {*} pobj
* @param {*} actionBody
*/
async getCustomerArea(pobj, actionBody) {
var obj = [
{name:"北京",value:1},
{name:"西藏",value:1},
{name:"天津",value:1},
{name:"新疆",value:1},
{name:"青海",value:1},
{name:"甘肃",value:1},
{name:"宁夏",value:1},
{name:"台湾",value:1}
]
return system.getResultSuccess(obj);
}
/**
* 订单列表
* @param {*} pobj
* @param {*} actionBody
*/
async getOrderInfo(pobj, actionBody) {
var obj = [{
orderNo:"OT37202007041210tTCU",
produuctName:"产品名字",
tmName:"商标名字",
quantity:1,
contactName:"lin",
totalSum:"300",
deliveryStatusName:"待审核",
updateAt:"2020-07-14 11:00:00"
}]
return system.getResultSuccess(obj);
}
/**
* 订单详情
* @param {*} pobj
* @param {*} actionBody
*/
async getOrderDelivery(pobj, actionBody) {
return system.getResultSuccess({});
}
//--------------------------------优客工厂相关接口--end----------------------------------------------------
/**
* 优客调取订单列表用
* @param {*} pobj
* @param {*} actionBody
*/
async ucommuneGetOrderList(pobj, actionBody) {
// ucommuneGetOrderList
var reqUrl = this.centerOrderUrl + "action/ucommuneOrder/springBoard";
var result = await this.restPostUrl(pobj, reqUrl);
console.log("-------------ucommuneGetOrderList result start---------------")
console.log(result)
console.log("-------------ucommuneGetOrderList result end---------------")
return result;
}
/**
* 根据优客token获取用户信息,生成userPin返回前端
* @param {*} pobj
* @param {*} actionBody userToken 为优客工厂的userToken
*/
async getUserInfo(pobj, actionBody) {
if (!actionBody.userToken) {
return system.getResult(null, "actionBody.token can not be empty,100410");
}
var url = settings.ucommuneUrl() + "third/getUserInfo"; // 调用优客工场接口 获取用户信息
// 拼接规则curl -k -H 'Content-type: application/json' -H 'authorization:{token}' -X POST {url} pobj作为发生错误时记录日志用
let result = await this.restPostWithHAuthorizationUrl(pobj, actionBody.userToken, url);
if (result.retCode == 0) { // 0成功 1失败
pobj.actionType = "getLoginByUserName";
pobj.actionBody.channelUserId = result.data.nationalCode + "-" + result.data.mobile; // 即:86_18512345678
pobj.actionBody.userName = result.data.mobile;
pobj.actionBody.nickName = result.data.name;
pobj.actionBody.mobile = result.data.mobile;
pobj.actionBody.headUrl = result.data.headImg;
pobj.actionBody.userpin = pobj.actionBody.userpin || this.getUUID();
var tmpOpResult = await this.utilsAuthSve.getLoginByUserName(pobj, pobj.actionBody);
if (tmpOpResult.status != 0 && tmpOpResult.status != 2060) {
return tmpOpResult;
}
return system.getResultSuccess({ userpin: tmpOpResult.data.userpin ? tmpOpResult.data.userpin : pobj.actionBody.userpin })
} else {
// 获取用户信息失败
return system.getResult(null, result);
}
}
/**
* 优客调取订单列表用
* @param {*} pobj
* @param {*} actionBody
*/
async ucommuneGetOrderList(pobj, actionBody) {
// ucommuneGetOrderList
var reqUrl = this.centerOrderUrl + "action/ucommuneOrder/springBoard";
var result = await this.restPostUrl(pobj, reqUrl);
console.log("-------------ucommuneGetOrderList result start---------------")
console.log(result)
console.log("-------------ucommuneGetOrderList result end---------------")
return result;
}
/**
* addOrder后进入支付页面获取支付金额 addorder返回totalsum 此接口可以不调用
* @param {*} pobj
* @param {*} actionBody orderNo orderIndo订单号
*/
async orderTotalSum(pobj, actionBody) {
pobj.actionType = "getOrderDetails" // 获取订单详细信息 totalsum为总金额,返回给前端
var reqUrl = this.centerOrderUrl + "action/order/springBoard";
var result = await this.restPostUrl(pobj, reqUrl);
return result;
}
/**
* 点击确认支付后返回拼接字符串 orderConfirm 的验证数据方法
* @param {*} pobj
* @param {*} actionBody orderNo orderIndo订单号
*/
async orderCheck(pobj, actionBody) {
pobj.actionType = "getOrderDetails" // 获取订单详细信息 totalsum为总金额,返回给前端
var reqUrl = this.centerOrderUrl + "action/order/springBoard";
var result = await this.restPostUrl(pobj, reqUrl);
return result;
}
/**
* 点击确认支付后返回拼接字符串 orderConfirm 的验证数据方法
* @param {*} pobj
* @param {*} actionBody orderNo orderIndo订单号
*/
async orderConfirmValidate(pobj, actionBody) {
if (!actionBody.orderNo) { // 订单号
return system.getResult(null, "actionBody.orderNo can not be empty,100430");
}
if (!actionBody.payWay) { // 支付方式 1 支付宝 3微信
return system.getResult(null, "actionBody.payWay can not be empty,100440");
}
if (actionBody.payWay != 1 || actionBody.payWay != 3) { // payway 非1非3
return system.getResult(null, "actionBody.payWay is eoor values,100450");
}
}
/**
* 订单详情
* @param {*} pobj
* @param {*} actionBody orderNo orderIndo订单号
*/
async ucommuneGetOrderDetail(pobj, actionBody) {
return system.getResultSuccess()
}
}
module.exports = UtilsUcommuneService;
\ No newline at end of file
var url = require("url");
var system = require("../../base/system");
const utilsAuthSve = system.getObject("service.utilsSve.utilsAuthSve");
const logCtl = system.getObject("service.common.oplogSve");
const utilsOrderSve = system.getObject("service.utilsSve.utilsOrderSve");
const utilsFeishuSve = system.getObject("service.utilsSve.utilsFeishuSve");
var md5 = require('md5');
var xml2js = require('xml2js');
var settings = require("../../config/settings");
const axios = require('axios')
module.exports = function (app) {
//-----------------------新的模式---------web---------开始
app.use('/tlpay/aliPayNotify', async function (req, res) {
try {
var client_ip = system.get_client_ip(req);
var result = await utilsOrderSve.opH5AliDingPayBackNotify(req.body, client_ip);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "记录阿里钉钉支付回调处理结果",
op: "center-channel/tlpay/aliPayNotify",
content: "支付回调处理结果:" + JSON.stringify(result),
clientIp: client_ip || ""
});
if (result.status != 0) {
return res.end("FAIL");
}
return res.end("success");
} catch (error) {
logCtl.error({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "阿里钉钉支付回调处理异常",
op: "center-channel/tlpay/aliPayNotify",
content: "回调参数:req=" + JSON.stringify(req) + "error:" + error.stack,
clientIp: client_ip || ""
});
}
});
app.use('/tlpay/notify', async function (req, res) {
try {
var client_ip = system.get_client_ip(req);
var result = await utilsOrderSve.receiveCallBackNotify(req.body, client_ip);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "记录回调处理结果:,method=" + req.body.trxcode,
op: "center-channel/tlpay/notify",
content: "回调参数:" + JSON.stringify(req.body) + "回调结果:" + JSON.stringify(result),
clientIp: client_ip || ""
});
if (result.status != 0) {
return res.end("FAIL");
}
return res.end("success");
} catch (error) {
logCtl.error({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "记录回调处理结果异常:,method=" + req.body.trxcode,
op: "center-channel/tlpay/notify",
content: "回调参数:" + JSON.stringify(req.body) + "error:" + error.stack,
clientIp: client_ip || ""
});
}
});
app.use('/tlpay/opBackNotify', async function (req, res) {
try {
var client_ip = system.get_client_ip(req);
var result = await utilsOrderSve.opBackNotify(req.body, client_ip);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "回调处理订单结果:,method=" + req.body.trxcode,
op: "center-channel/tlpay/opBackNotify",
content: "回调参数:" + JSON.stringify(req.body) + "回调处理订单结果:" + JSON.stringify(result),
clientIp: client_ip || ""
});
res.end(JSON.stringify(result));
} catch (error) {
logCtl.error({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "记录回调处理结果异常:,method=" + req.body.trxcode,
op: "center-channel/tlpay/opBackNotify",
content: "回调参数:" + JSON.stringify(req.body) + "error:" + error.stack,
clientIp: client_ip || ""
});
}
});
//----------------------飞书小程序---------------------------------------------开始
//飞书通知
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) {
var result = system.getResult(null, "req method must is post");
if (req.method != "POST") {
res.end(JSON.stringify(result));
return;
}
if (!req.body.actionType) {
result.msg = "actionType can not be empty";
res.end(JSON.stringify(result));
return;
}
if (["getAppTokenByHosts", "getAppTokenByAppKey", "test"].indexOf(req.body.actionType) >= 0) {
req.body.actionBody.appHosts = req.host;
next();
return;
}
if (req.body.actionType == "receiveCallBackNotify") {
req.body.actionBody.app_hosts = req.host;
next();
return;
}
var token = req.headers["token"] || "";
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;
}
req.body.appInfo = result.data;
req.body.actionProcess = result.data.app_code;
var lst = ["tmConfirm", "getNeedSolutionDetailByUser","getProgrammeInfoByChannelNeedNo",
"submitIcpProgramme", "submitIcpMaterial", "acceptIcpPartnerNotification", "abolishIcpProgramme",
"addOrder", "getH5PayUrl", "getOrderQrCode", "queryOrderStatus", "getOrderInfo", "getOrderDeliveryInfo", "getOrderDetails",
"getOrderDeliveryFlowInfo", "getOrderDeliveryFlowList", "getOrderLogInfo", "updateContacts", "updateTmOrder", "delOrder",
"submitProgramme", "getProgrammeListByUser", "getProgrammeInfoByNeedNo", "abolishProgramme", "getAliPayInfo",
"getPaidLogoListByUser","getCollectibleLogoListByUser","collectLogo","getLogoMaterial","cancelCollectLogo","icpNotify","createName","getNameDetail","orderConfirm",
"orderTotalSum", "collect", "reg", "orderCheck"
];
if (lst.indexOf(req.body.actionType) >= 0) {
var userpin = req.headers["userpin"] || "";
if (!userpin) {
result.status = system.noLogin;
result.msg = "req headers userpin can not be empty";
result.data = null;
res.end(JSON.stringify(result));
return;
} else {
var params = {
"appInfo": req.body.appInfo,
"actionType": "getLoginInfo",
"actionBody": {
"userpin": userpin
}
}
result = await utilsAuthSve.getLoginInfo(params, params.actionBody);
if (result.status != 0) {
result.status = system.noLogin;
result.msg = "user login is invalidation";
res.end(JSON.stringify(result));
return;
}
req.body.userInfo = result.data;
}
}//需要用户登录
next();
});
app.get('/web/: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
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["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.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));
});
});
//-----------------------新的模式---------web---------结束
//-----------------------新的模式---------api---------开始
app.all("/api/*", async function (req, res, next) {
var result = system.getResult(null, "req method must is post");
......@@ -336,93 +12,31 @@ module.exports = function (app) {
res.end(JSON.stringify(result));
return;
}
if (["getAppTokenByHosts", "getAppTokenByAppKey"].indexOf(req.body.actionType) >= 0) {
req.body.actionBody.appHosts = req.host;
next();
return;
}
if (req.path.indexOf("/taskapi/") >= 0) {
next();
return;
}
if (!req.body.actionType) {
result.msg = "actionType can not be empty";
res.end(JSON.stringify(result));
return;
}
var token = req.headers["token"] || "";
if (!token) {
result.msg = "req headers token can not be empty";
var uappId = req.body.actionBody["uappId"] || "";
if (!uappId) {
result.msg = "req body uappId 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;
}
req.body.appInfo = result.data;
req.body.actionProcess = result.data.app_code;
var lst = [
"submitNeed", "paySuccess","icpNotify"
];
if (lst.indexOf(req.body.actionType) >= 0) {
var userpin = req.headers["userpin"] || "";
if (!userpin) {
result.status = system.noLogin;
result.msg = "req headers userpin can not be empty";
var reqUrl = settings.centerAppUrl() + "auth/accessAuth/getAppInfo";
var appResult = await axios.post(reqUrl,{uappId:uappId});
if (appResult.data.status != 0) {// 验证渠道失败
result.msg = appResult.data;
result.data = null;
res.end(JSON.stringify(result));
return;
} else {
var params = {
"appInfo": req.body.appInfo,
"actionType": "getLoginInfo",
"actionBody": {
"userpin": userpin
}
}
result = await utilsAuthSve.getLoginInfo(params, params.actionBody);
if (result.status != 0) {
result.status = system.noLogin;
result.msg = "user login is invalidation";
res.end(JSON.stringify(result));
return;
}
req.body.userInfo = result.data;
}
}//需要用户登录
req.body.appInfo = appResult.data.data;
next();
});
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
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["doexecMethod"]) {
p = invokeObj["doexecMethod"].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"];
......@@ -435,6 +49,14 @@ module.exports = function (app) {
req.uagent = req.headers["user-agent"];
req.classname = classPath;
// 记录参数
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "ucommune-back",
op: "ucommune-back/" + classPath,
content: "参数:" + JSON.stringify(req.body),
clientIp: tClientIp || ""
});
params.push(gname);
params.push(methodName);
params.push(req.body);
......@@ -449,6 +71,4 @@ module.exports = function (app) {
res.end(JSON.stringify(r));
});
});
//-----------------------新的模式---------api---------结束
};
\ 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