Commit 5146fdf9 by linboxuan

ordercallback

parent 9aa53296
......@@ -580,21 +580,27 @@ class UtilsOrderService extends AppServiceBase {
return system.getResult(null, "trade_status状态有误,100473");
}
// 2020 0621 支付宝验签接口
// var url = "https://yf-api.gongsibao.com/pay/v1/checkAliPaySign";
// let params = {
// "app": "ukgc", //应用名称 固定
// "key": "a1519e2eab53dfb909e4c32a86b2ea2b", //应用 key 固定
// "tData" : params
// }
// var sign = JSON.stringify(params);
// sign += "ab53dfb909e4c32a"
// sign = md5(sign).toUpperCase()
// params.sign = sign
// let res = await axios.post(url, params)
// if (res.status != 0) {
// res.msg = res.msg + ",100480";
// return res;
// }
var url = "https://yf-api.gongsibao.com/pay/v1/checkAliPaySign";
let params = {
"app": "ukgc", //应用名称 固定
"key": "a1519e2eab53dfb909e4c32a86b2ea2b", //应用 key 固定
"tData" : parmas
}
var sign = JSON.stringify(params);
sign += "ab53dfb909e4c32a"
sign = md5(sign).toUpperCase()
params.sign = sign
let res = await axios.post(url, params)
this.logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "支付宝回调参数验签结果",
op: "service/impl/utilsSve/utilsOrderSve.js/aliPayNotify",
content: JSON.stringify(res),
clientIp: client_ip || ""
});
if (res.status != 0) {
res.msg = res.msg + ",100480";
return res;
}
// 模拟验签结果
var outTradeInfo = parmas.out_trade_no.split('-');
//
......@@ -666,24 +672,30 @@ class UtilsOrderService extends AppServiceBase {
content: JSON.stringify(parmas),
clientIp: client_ip || ""
});
if (!parmas.trade_status) {
return system.getResult(null, "trade_status参数不能为空,100470");
if (!parmas.result_code) {
return system.getResult(null, "result_code参数不能为空,100670");
}
if (parmas.trade_status != "TRADE_FINISHED" && parmas.trade_status != "TRADE_SUCCESS") {
return system.getResult(null, "trade_status状态有误,100473");
if (parmas.result_code != "SUCCESS") {
return system.getResult(null, "result_code状态有误,100673");
}
// 2020 0621 支付宝验签接口
// var url = "https://yf-api.gongsibao.com/pay/v1/checkAliPaySign";
// var url = "https://yf-api.gongsibao.com/pay/v1/checkWXPaySign";
// let params = {
// "app": "ukgc", //应用名称 固定
// "key": "a1519e2eab53dfb909e4c32a86b2ea2b", //应用 key 固定
// "tData" : params
// "tData" : parmas
// }
// var sign = JSON.stringify(params);
// sign += "ab53dfb909e4c32a"
// sign = md5(sign).toUpperCase()
// params.sign = sign
// let res = await axios.post(url, params)
// this.logCtl.info({
// optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "微信回调参数验签结果",
// op: "service/impl/utilsSve/utilsOrderSve.js/wxPayNotify",
// content: JSON.stringify(res),
// clientIp: client_ip || ""
// });
// if (res.status != 0) {
// res.msg = res.msg + ",100480";
// return res;
......@@ -712,10 +724,11 @@ class UtilsOrderService extends AppServiceBase {
}
parmas.appInfo = { appInfo: { uapp_id: opResult.data.uappId } };
parmas.orderNo = opResult.data.orderNo;
parmas.pay_type = "alipay";
parmas.pay_type = "wxpay";
//修改并返回订单支付状态,创建收款单
// 这里修改了order_info的状态(status/paytime等)
var url = this.centerOrderUrl + "opaction/opPayOrder/receivePayCallBackNotifyByAliDing";
// var url = this.centerOrderUrl + "opaction/opPayOrder/receivePayCallBackNotifyByAliDing";
var url = this.centerOrderUrl + "opaction/opPayOrder/receivePayCallBackNotifyByWX";
var opOrderResult = await this.restPostUrl(parmas, url);
if (opOrderResult.status != 0) {
opOrderResult.data = null;
......
......@@ -83,7 +83,8 @@ class UtilsUcommuneService extends AppServiceBase {
var reqUrl = settings.centerOrderUrl() + "action/order/springBoard";
var orderResult = await this.restPostUrl(pobj, reqUrl);
if(orderResult.status != 0) {
return system.getResult(null, "Failed to get orderResult 100470");
// return system.getResult(null, "Failed to get orderResult or order has been paid 100470");
return system.getResult(null, orderResult);
} else {
if(actionBody.payWay == 1) { // 支付宝
let creatPayRequrl = "https://yf-api.gongsibao.com/pay/v1/aliPay/getPrePayIdAliPay";
......@@ -196,38 +197,68 @@ class UtilsUcommuneService extends AppServiceBase {
// console.log(alipayResponse);
}
if(actionBody.payWay == 3) { // 微信
await this.cacheManager["TlPayLocker"].init(orderResult.data.receiptVoucher.sourceOrderNo);
let creatPayRequrl = "https://yf-api.gongsibao.com/pay/v1/createSign";
let params = {
"app": "ukgc",
"key": "a1519e2eab53dfb909e4c32a86b2ea2b",
"payParam": [
{
"name":"appid",
// 后期修改
// "value":"1"
"value":"wx6f3ebe44defe336a"
},
{
"name":"mch_id",
// "value":"1"
"value":"1232813602"
},
{
"name":"device_info",
"value":"1000"
},
{
"name":"body",
"value":orderResult.data.orderProduct.channelItemName
"value":"商标"
// "value":orderResult.data.orderProduct.channelItemName
},
{
"name":"outTradeNo",
"value":orderResult.data.receiptVoucher.sourceOrderNo + "-" + pobj.appInfo.uapp_id.toString() + "-" + orderResult.data.orderProduct.id.toString()
"name":"nonce_str",
// "value":"ibuaiVcKdpRxkhJA"
"value":WxPayUtil.generateNonceString()
},
{
"name":"totalFee",
"value":orderResult.data.receiptVoucher.totalSum
"name":"openid",
"value":"o7kgSs_2cuJxyBoIEWMwRUPfobLg"
},
{
"name":"spbillCreateIp",
"value":'192.168.2.210'
"name":"notify_url",
"value":"http://"
// "value":this.centerChannelUrl + "orderNotify/wxPayNotify",
},
{
"name":"notifyUrl",
"value":this.centerChannelUrl + "orderNotify/wxPayNotify"
"name":"out_trade_no",
// "value": "OT37202006221758koyn-37-69"
"value":orderResult.data.receiptVoucher.sourceOrderNo + "-" + pobj.appInfo.uapp_id.toString() + "-" + orderResult.data.orderProduct.id.toString()
},
{
"name":"tradeType",
"value":"JSAPI"
"name":"sign_type",
"value":"MD5"
},
{
"name":"total_fee",
"value":"399"
// "value":orderResult.data.receiptVoucher.totalSum,
},
// {
// "name":"spbill_create_ip",
// // "value":'1'
// "Value": '192.168.2.210',
// },
{
"name": "nonceStr",
"value": "5K8264ILTKCH16CQ2502SI8ZNMTM67VS"
"name":"trade_type",
"value":"JSAPI"
}
],
"paymentType": "3"
......@@ -246,6 +277,7 @@ class UtilsUcommuneService extends AppServiceBase {
sign += "ab53dfb909e4c32a"
sign = md5(sign).toUpperCase()
params.sign = sign
console.log(params)
let res = await axios.post(creatPayRequrl, params)
if(res.status == 200 && res.data.code == 200) {
await this.cacheManager["TlPayLocker"].init(orderResult.data.receiptVoucher.sourceOrderNo);
......@@ -427,3 +459,15 @@ PayUtil = {
module.exports = UtilsUcommuneService;
WxPayUtil = {
generateNonceString: function(length) {
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var maxPos = chars.length;
var noceStr = "";
for (var i = 0; i < (length || 32); i++) {
noceStr += chars.charAt(Math.floor(Math.random() * maxPos));
}
return noceStr;
}
}
\ No newline at end of file
......@@ -448,18 +448,28 @@ module.exports = function (app) {
// wx支付回调
app.post('/orderNotify/wxPayNotify', async function (req, res) {
try{
var client_ip = system.get_client_ip(req);
var result = await utilsOrderSve.wxPayNotify(req.body);
logCtl.info({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "记录微信支付回调处理结果",
op: "center-channel/orderNotify/wxPayNotify",
content: "支付回调处理结果:" + JSON.stringify(result),
clientIp: client_ip || ""
var body = "";
req.on('data', function(data) {
body += data;
});
if (result.status != 0) {
return res.end("FAIL");
}
return res.end("success");
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 {
logCtl.error({
optitle: (new Date()).Format("yyyy-MM-dd hh:mm:ss") + "微信回调处理异常",
......
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