Commit d8ca5d89 by 宋毅

tj

parent a374b20e
......@@ -118,6 +118,10 @@ class tmqueryCtl extends CtlBase {
var opJdPayPageInfoResult = await this.opJdPayPageInfo(pobj, result, req);
return opJdPayPageInfoResult;
}
else if (["gsb"].indexOf(pobj.actionProcess) >= 0 && pobj.actionType == "subTmOrder") {
var opGsbPayPageInfoResult = await this.opGsbPayPageInfo(pobj, result, req);
return opGsbPayPageInfoResult;
}
return result;
} catch (e) {
console.log(e.stack, "操作error...................");
......@@ -501,7 +505,7 @@ class tmqueryCtl extends CtlBase {
var reqUrl = this.channelApiUrl + "/action/tmOrder/springBoard";
this.logClient.error("jd", "req---->pushJdPayOrder---->params:" + JSON.stringify(param) + ",reqUrl:" + reqUrl);
var resultUser = await this.execClient.execPostTK(param, reqUrl, tokenInfo.data.token);
if (!resultUser) {
this.logClient.error("jd", "req---->pushJdPayOrder---->error:" + JSON.stringify(resultUser));
......@@ -522,95 +526,46 @@ class tmqueryCtl extends CtlBase {
if (!pobj.actionBody.itemCode) {
return system.getResult(null, "itemCode param is not empty");
}
return system.getResultSuccess();
}
async getGsbPayPageAddr(itemCode, itemCodeList, req) {//获取京东下单
try {
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');
let credentials = {
accessKeyId: 'C6D680733C19362B5DF478207D6A90A4', //替换自己的AK
secretAccessKey: 'EB9AFEE49CE41700CADD5F2EE3B2122C' //替换自己的SK--jd>>>>>>>
var tokenInfo = await this.getToken(pobj.actionProcess);
if (tokenInfo.status != 0) {
return tokenInfo;
}
//测试报文:
//ctx.body = "pin=jcloud_pRiHQTd&serviceId=580010&itemCode=FW_GOODS-580010-1&platform=6"
//POST
var qs = require('querystring');
// var post_data = { pin: "syaify", serviceId: 580010, itemCode: "FW_GOODS-580010-1", platform: 6, orderNum: 1, articleType: 1 };//这是需要提交的数据
var post_data = {
pin: req.session.userPinInfo.channelUserId,
serviceId: itemCodeList[1],
itemCode: itemCode,
platform: 6,
orderNum: 1,
articleType: 1,
additions: '{ \"246\": 0 }'
};//这是需要提交的数据
// var tmpContent = '{"pin":"syaify","serviceId":"581976","itemCode":"FW_GOODS-581976","platform":6,"orderNum":1,"articleType":1,"additions":{"246":0}}';
var tmpContent = JSON.stringify(post_data);
var tmpContentLength = Buffer.byteLength(tmpContent);
ctx.body = tmpContent;
ctx.method = 'POST'
var signer = new Signer(ctx, credentials);
ctx.headers.set('Content-Length', tmpContentLength)
ctx.buildNonce()
var dd = new Date();
var auth = signer.sign(dd)
console.log("POST签名为:", auth)
ctx.headers.set('Authorization', auth)
////////////////////////////////////////////////////////////////////////////////////////////////////////////
var http = require('https');
var options = {
host: 'x3k0s704lfun.cn-north-1.jdcloud-api.net',
port: 443,
path: '/market/order/api/submit',
method: 'POST',
headers: {
}
var param = {
actionProcess: pobj.actionProcess,
actionType: "subGsbOrderInfo",
actionBody: {
channelUserId: req.session.userPinInfo.channelUserId,
channelItemCode: pobj.actionBody.itemCode,
order_param: {
mobile_phone: pobj.actionBody.apply.mobile || "18888888888",//必填
goods_list: [{//必填
goods_name: pobj.actionBody.itemCode,
goods_quantity: 1,
}],
order_price: 300,//必填
province_name: "",//省
city_name: "",//市
district_name: ""//区
}
},
isUser: "yes"
};
for (let [key, value] of ctx.headers) {
options.headers[key] = value
var reqUrl = this.channelApiUrl + "/action/tmOrder/springBoard";
console.log("req---->opGsbPayPageInfo---->params:" + JSON.stringify(param) + ",reqUrl:" + reqUrl);
var result = await this.execClient.execPostTK(param, reqUrl, tokenInfo.data.token);
if (!result) {
console.log("req---->opGsbPayPageInfo---->error:" + JSON.stringify(result));
return system.getResult(null, "req error");
}
return result;
this.logClient.info("jd", "req---->getJdPayPageAddr---->options:" + JSON.stringify(options));
this.logClient.info("jd", "req---->getJdPayPageAddr---->tmpContent:" + tmpContent);
var reqResult = await new Promise(function (resolve, reject) {
let req = http.request(options, function (res) {
// res.setEncoding(encoding);
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
var _data = '';
res.on('data', function (chunk) {
_data += chunk;
});
res.on('end', function () {
console.log("\n--req---成功->>\nresult:", _data)
resolve({ result: true, data: _data });
});
});
req.on('error', (e) => {
console.error(`请求遇到问题-------------: ${e.message}`);
resolve({ result: false, errmsg: e.message });
});
req.write(tmpContent);
req.end();
});
return reqResult;
} catch (errorMsg) {
this.logClient.error("jd", "req---->getJdPayPageAddr---->error:" + error.stack);
return { success: false, code: -200, msg: error.stack };
} catch (error) {
console.log("req---->opGsbPayPageInfo---->操作error:" + error.stack);
return system.getResultFail(-200, "操作error");
}
return system.getResultSuccess();
}
async pushGsbPayOrder(pushData, req) {//处理京东推送的订单信息
try {
......
......@@ -7,6 +7,11 @@ var logClient = system.getObject("util.logClient");
const jwt = require('jsonwebtoken');
const secret = '3rZ3aNfGAyQAB4sE'; //自定义
module.exports = function (app) {
app.get("/admin", async function (req, res) {
res.redirect("http://oauth2.jdcloud.com/authorize?response_type=token&redirect_uri=http://tm.plus.jdcloud.com/jdtm/getUser&state=OAjdlist&client_id=9841572588670903");
return;
});
app.get("/jdtm/getUser", async function (req, res) {
try {
var params = req.query;
......@@ -48,47 +53,6 @@ module.exports = function (app) {
});
}
});
// app.get("/login", async function (req, res) {
// try {
// var params = req.query;
// if (!params.state || !params.token_type || !params.access_token) {
// res.redirect("http://oauth2.jdcloud.com/authorize?response_type=token&redirect_uri=http://tm.plus.jdcloud.com/jdtm/getUser&state=jdindentlist&client_id=9841572588670903");
// return;
// }
// var getUserparams = {
// actionProcess: "jd",
// authUrl: "https://oauth2.jdcloud.com/userinfo",
// authToken: params.token_type + " " + params.access_token
// };
// var userItemResult = await tmqueryCtl.getJdUserInfo(getUserparams, req.query, req);
// logClient.info("jd", {
// optitle: "###获取京东用户结果...getJdUserInfo",
// op: "/jdtm/loginUser",
// content: "参数=" + JSON.stringify(getUserparams) + ",result=" + JSON.stringify(userItemResult),
// clientIp: ""
// });
// if (userItemResult.status != 0) {
// res.redirect("/#/jd/jdindentlist");
// return;
// }
// if (!userItemResult.data.encryptChannelUserId || userItemResult.data.encryptChannelUserId == "undefined") {
// userItemResult = await tmqueryCtl.getUserIdEncryptStr(getUserparams, req.query, req);
// if (userItemResult.status != 0) {
// res.redirect("/#/jd/jdindentlist");
// return;
// }
// }
// var skipUrl = "/#/jd/" + params.state + "?channelUserId=" + encodeURIComponent(userItemResult.data.encryptChannelUserId);
// res.redirect(skipUrl);
// } catch (error) {
// logClient.error("jd", {
// optitle: "###获取京东用户异常...getJdUserInfo",
// op: "/jdtm/loginUser",
// content: error.stack,
// clientIp: ""
// });
// }
// });
app.get("/jd/orderNotify", async function (req, res) {
logClient.payLog("jd", {
optitle: "###操作订单结果参数...orderNotify",
......@@ -202,8 +166,13 @@ module.exports = function (app) {
res.redirect(skipUrl);
});
app.get("/gsb/selfRegister", async function (req, res) {
app.get("/gsb", async function (req, res) {
var skipUrl = "/#/gsb/selftmreg?channelUserId=";
var params = req.query;
if (!params.state) {
res.redirect(skipUrl);
return;
}
var token = req.cookies.ic_token;
if (!token) {
res.redirect(skipUrl);
......@@ -230,9 +199,39 @@ module.exports = function (app) {
res.redirect(skipUrl);
return;
}
skipUrl = skipUrl + encodeURIComponent(userItemResult.data.encryptChannelUserId);
skipUrl = "/#/gsb/" + params.state + "?channelUserId=" + encodeURIComponent(userItemResult.data.encryptChannelUserId);
res.redirect(skipUrl);
});
app.get("/gsb/orderNotify", async function (req, res) {
logClient.payLog("jd", {
optitle: "###操作订单结果参数...orderNotify",
op: "/jd/orderNotify",
content: "req.query=" + JSON.stringify(req.query) + ",req.body=" + JSON.stringify(req.body),
clientIp: ""
});
req.query.actionProcess = "jd";
var result = await tmqueryCtl.pushJdPayOrder(req.query, req);
logClient.payLog("jd", {
optitle: "###操作订单结果...orderNotify",
op: "/jd/orderNotify",
content: "result=" + JSON.stringify(result),
clientIp: ""
});
if (result.status != 0) {
res.end(JSON.stringify(result));
return;
}
var params =
{
instanceId: req.query.orderBizId,
appInfo: {
authUrl: "https://tm.plus.jdcloud.com/jd/skipPage?channelUserId=" + req.query.jdPin,
adminUrl: "https://tm.plus.jdcloud.com"
}
};
res.end(JSON.stringify(params));
return;
});
app.get("/", async function (req, res) {
try {
var appinfo = await metaCtl.getAppInfo(req);
......
......@@ -106,12 +106,6 @@ basecomp.forEach(function (comp) {
}else{
this.logins.push({"icon":"el-icon-arrow-right","title":"退出","type":"text",key:"exit","isOnGrid":true});
}
this.checkLogin(()=>{
if(location.hash=="#/"){
this.$router.push("/index");
}
});
},
methods:{
initWindowShow(){
......
......@@ -209,7 +209,6 @@ axios.get("/web/common/metaCtl/getRouteConfig").then(d => {
} else {
this.logins.push({ "icon": "el-icon-arrow-right", "title": "退出", "type": "text", key: "exit", "isOnGrid": true });
}
this.checkLogin();
},
methods: {
// 返回当前接入渠道标识
......
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