Commit e3fe1a74 by 宋毅

添加京东再次推送

parent ee6d2a0f
node_modules/
logs/
.idea
\ No newline at end of file
......@@ -2,17 +2,19 @@ var system = require("../../../system");
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const md5 = require("MD5");
class tmqueryCtl extends CtlBase {
constructor() {
super();
this.channelApiUrl = settings.channelApiUrl();
this.appInfo = {
jd: { appkey: "201911251551", secret: "56006077354d48858026c80c0e10bef6" },
1688: { appkey: "201911131657", secret: "eeb18393aade40149287b024d8ba0850" },
gsbhome: { appkey: "201912141625", secret: "8cbb846776874167b5c7e01cd0116c66" },
bw: { appkey: "202001081738", secret: "9bdcbc48afd04d9ba54236947a78210b" },
jd: {appkey: "201911251551", secret: "56006077354d48858026c80c0e10bef6"},
1688: {appkey: "201911131657", secret: "eeb18393aade40149287b024d8ba0850"},
gsbhome: {appkey: "201912141625", secret: "8cbb846776874167b5c7e01cd0116c66"},
bw: {appkey: "202001081738", secret: "9bdcbc48afd04d9ba54236947a78210b"},
};
}
async doPost(pobj, obj, req) {
if (["getOrderDeliveryInfo", "getOrderInfo", "subOtherOrder", "subTmOrder", "getTmOrderList", "getTmOrderInfo", "getTmApplyInfo", "getTmNclList",
"getNeedInfo", "tmConfirm", "updateTmInfo", "updateNclInfo",
......@@ -73,7 +75,7 @@ class tmqueryCtl extends CtlBase {
reqobj.actionType = "decryptStr";
reqobj.isUser = "no";
let currentDate = Math.floor(new Date().getTime() / 1000);
reqobj.actionBody = { opStr: decodeURIComponent(oldActionBody.channelUserId), timeStamp: currentDate };
reqobj.actionBody = {opStr: decodeURIComponent(oldActionBody.channelUserId), timeStamp: currentDate};
var decryptSignResult = await this.createSign(reqobj.actionBody, tokenInfo.data.secret);
if (decryptSignResult.status != 0) {
return decryptSignResult;
......@@ -123,8 +125,7 @@ class tmqueryCtl extends CtlBase {
if (["jd"].indexOf(pobj.actionProcess) >= 0 && pobj.actionType == "subTmOrder") {
var opJdPayPageInfoResult = await this.opJdPayPageInfo(pobj, result, req);
return opJdPayPageInfoResult;
}
else if (["gsbhome"].indexOf(pobj.actionProcess) >= 0 && pobj.actionType == "subTmOrder") {
} else if (["gsbhome"].indexOf(pobj.actionProcess) >= 0 && pobj.actionType == "subTmOrder") {
var opGsbPayPageInfoResult = await this.opGsbPayPageInfo(pobj, result, req);
return opGsbPayPageInfoResult;
}
......@@ -142,6 +143,7 @@ class tmqueryCtl extends CtlBase {
return system.getResult(null, "操作失败");
}
}
async getToken(reqType) {
var self = this;
var token = "";
......@@ -176,6 +178,7 @@ class tmqueryCtl extends CtlBase {
}
return tokenResult;
}
/**
* 验证签名
* @param {*} params 要验证的参数
......@@ -214,6 +217,7 @@ class tmqueryCtl extends CtlBase {
var resultTmpSign = md5(resultSignStr).toUpperCase();
return system.getResultSuccess(resultTmpSign);
}
async getUserIdEncryptStr(pobj, qobj, req) {
try {
if (!req.session.userPinInfo) {
......@@ -222,11 +226,11 @@ class tmqueryCtl extends CtlBase {
return system.getResult(null, "user is not login...");
}
if (req.session.userPinInfo.encryptChannelUserId) {
return system.getResultSuccess({ encryptChannelUserId: req.session.userPinInfo.encryptChannelUserId });
return system.getResultSuccess({encryptChannelUserId: req.session.userPinInfo.encryptChannelUserId});
}
}
if (req.session.userPinInfo.encryptChannelUserId) {
return system.getResultSuccess({ encryptChannelUserId: req.session.userPinInfo.encryptChannelUserId });
return system.getResultSuccess({encryptChannelUserId: req.session.userPinInfo.encryptChannelUserId});
}
var tokenInfo = await this.getToken(pobj.actionProcess);
if (tokenInfo.status != 0) {
......@@ -236,7 +240,10 @@ class tmqueryCtl extends CtlBase {
var param = {
actionProcess: pobj.actionProcess,
actionType: "encryptStr",
actionBody: { channelUserId: req.session.userPinInfo.channelUserId, opStr: req.session.userPinInfo.channelUserId },
actionBody: {
channelUserId: req.session.userPinInfo.channelUserId,
opStr: req.session.userPinInfo.channelUserId
},
isUser: "yes"
};
var reqUrl = this.channelApiUrl + "/action/tmTools/springBoard";
......@@ -248,12 +255,13 @@ class tmqueryCtl extends CtlBase {
return system.getResult(null, "encryptStr resultUser is error");
}
req.session.userPinInfo.encryptChannelUserId = resultUser.data || "";
return system.getResultSuccess({ encryptChannelUserId: resultUser.data || "" });
return system.getResultSuccess({encryptChannelUserId: resultUser.data || ""});
} catch (error) {
console.log(error.stack, "操作error...................getUserIdEncryptStr");
return system.getResultFail(-200, "操作error");
}
}
async createUserInfo(pobj, qobj, req) {
try {
var tokenInfo = await this.getToken(pobj.actionProcess);
......@@ -264,7 +272,7 @@ class tmqueryCtl extends CtlBase {
var param = {
actionProcess: pobj.actionProcess,
actionType: "createChannelUser",
actionBody: { channelUserId: pobj.channelUserId, channelUserMoblie: pobj.channelUserMoblie || "" },
actionBody: {channelUserId: pobj.channelUserId, channelUserMoblie: pobj.channelUserMoblie || ""},
isUser: "yes"
};
var reqUrl = this.channelApiUrl + "/action/tmTools/springBoard";
......@@ -279,6 +287,7 @@ class tmqueryCtl extends CtlBase {
return system.getResultFail(-200, "操作error");
}
}
async putPayOrderData(pobj, orderResult, needNo, needNoOrderNo, req) {//关联下单的数据
var tokenInfo = await this.getToken(pobj.actionProcess);
if (tokenInfo.status != 0) {
......@@ -335,12 +344,13 @@ class tmqueryCtl extends CtlBase {
return system.getResultFail(-200, "操作error");
}
}
//----------------------------jd------操作------------start
async getJdUserInfo(pobj, qobj, req) {
try {
req.session.userPinInfo = null;
if (req.session.userPinInfo) {
return system.getResultSuccess({ encryptChannelUserId: req.session.userPinInfo.encryptChannelUserId || "" });
return system.getResultSuccess({encryptChannelUserId: req.session.userPinInfo.encryptChannelUserId || ""});
}
var authUrl = pobj.authUrl;
var authToken = pobj.authToken;
......@@ -367,7 +377,7 @@ class tmqueryCtl extends CtlBase {
var param = {
actionProcess: actionProcess,
actionType: "createChannelUser",
actionBody: { channelUserId: result.account },
actionBody: {channelUserId: result.account},
isUser: "yes"
};
var reqUrl = this.channelApiUrl + "/action/tmTools/springBoard";
......@@ -382,7 +392,7 @@ class tmqueryCtl extends CtlBase {
return system.getResult(null, "处理请求失败");
}
req.session.userPinInfo = resultUser.data;
return system.getResultSuccess({ encryptChannelUserId: resultUser.data.encryptChannelUserId || "" });
return system.getResultSuccess({encryptChannelUserId: resultUser.data.encryptChannelUserId || ""});
} catch (error) {
this.error({
optitle: "###获取京东用户异常",
......@@ -393,6 +403,7 @@ class tmqueryCtl extends CtlBase {
return system.getResultFail(-200, "操作error");
}
}
async opJdPayPageInfo(pobj, orderResult, req) {//操作下单的数据跟渠道订单关联
this.info({
......@@ -430,7 +441,7 @@ class tmqueryCtl extends CtlBase {
var needNo = pobj.actionBody.itemCode + "_" + payDataResult.data.orderNumber;
var needNoOrderNo = payDataResult.data.orderNumber;
await this.putPayOrderData(pobj, orderResult, needNo, needNoOrderNo, req);
return system.getResultSuccess({ payUrl: payDataResult.data.returnUrl });
return system.getResultSuccess({payUrl: payDataResult.data.returnUrl});
}//成功
}
return system.getResult(null, "pay page is error");
......@@ -440,7 +451,7 @@ class tmqueryCtl extends CtlBase {
async getJdPayPageAddr(itemCode, itemCodeList, req) {//获取京东下单
try {
const { Signer, Context } = require('../jd-gateway-sdk');
const {Signer, Context} = require('../jd-gateway-sdk');
let ctx = new Context('x3k0s704lfun.cn-north-1.jdcloud-api.net', '/market/order/api/submit', 'POST', null, 'empty');
ctx.regionId = 'cn-north-1'
ctx.headers.set('content-type', 'application/json');
......@@ -493,8 +504,7 @@ class tmqueryCtl extends CtlBase {
port: 443,
path: '/market/order/api/submit',
method: 'POST',
headers: {
}
headers: {}
};
for (let [key, value] of ctx.headers) {
......@@ -517,12 +527,12 @@ class tmqueryCtl extends CtlBase {
});
res.on('end', function () {
console.log("\n--req---成功->>\nresult:", _data)
resolve({ result: true, data: _data });
resolve({result: true, data: _data});
});
});
req.on('error', (e) => {
console.error(`请求遇到问题-------------: ${e.message}`);
resolve({ result: false, errmsg: e.message });
resolve({result: false, errmsg: e.message});
});
req.write(tmpContent);
req.end();
......@@ -535,14 +545,21 @@ class tmqueryCtl extends CtlBase {
content: "error=" + JSON.stringify(error.stack),
clientIp: ""
});
return { success: false, code: -200, msg: error.stack };
return {success: false, code: -200, msg: error.stack};
}
}
async doPushJdPayOrderPost(pobj, obj, req) {
if (pobj.actionType != "pushJdPayOrder") {
return system.getResultFail(-1, "actionType pushJdPayOrder");
}
return await this.pushJdPayOrder(pobj.actionBody, req)
}
async pushJdPayOrder(pushData, req) {//处理京东推送的订单信息
this.info({
optitle: "###处理京东推送的订单信息参数",
op: "/jd/pushJdPayOrder",
op: "/jd/pushJdPayOrder,reqUrl=" + req.url,
content: "pushData参数=" + JSON.stringify(pushData),
clientIp: ""
});
......@@ -606,6 +623,7 @@ class tmqueryCtl extends CtlBase {
return system.getResultFail(-200, "操作error");
}
}
//----------------------------jd------操作------------end
//----------------------------gsb------操作------------start
......@@ -666,7 +684,7 @@ class tmqueryCtl extends CtlBase {
var needNo = "zzsbzc_" + payDataResult.data.order_no;
var needNoOrderNo = payDataResult.data.order_no;
await this.putPayOrderData(pobj, orderResult, needNo, needNoOrderNo, req);
return system.getResultSuccess({ payUrl: payDataResult.data.order_detail_url });
return system.getResultSuccess({payUrl: payDataResult.data.order_detail_url});
} catch (error) {
console.log("req---->opGsbPayPageInfo---->操作error:" + error.stack);
this.error({
......@@ -679,6 +697,7 @@ class tmqueryCtl extends CtlBase {
}
return system.getResultSuccess();
}
async pushGsbPayOrder(pushData, req) {//处理公司宝推送的订单信息
this.info({
optitle: "###处理公司宝推送的订单信息参数",
......@@ -750,4 +769,5 @@ class tmqueryCtl extends CtlBase {
return system.getResultSuccess(user);
}
}
module.exports = tmqueryCtl;
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