Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
50df8206
Commit
50df8206
authored
Jun 22, 2020
by
linboxuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ucommune order api
parent
4d2c8cbb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
176 additions
and
139 deletions
+176
-139
center-channel/app/base/service/impl/utilsSve/utilsOrderSve.js
+82
-5
center-channel/app/base/service/impl/utilsSve/utilsUcommuneSve.js
+66
-31
center-channel/app/config/routes/api.js
+28
-103
No files found.
center-channel/app/base/service/impl/utilsSve/utilsOrderSve.js
View file @
50df8206
...
@@ -562,11 +562,88 @@ class UtilsOrderService extends AppServiceBase {
...
@@ -562,11 +562,88 @@ class UtilsOrderService extends AppServiceBase {
}
}
async
aliPayNotify
(
pobj
)
{
// 微信支付回调
async
aliPayNotify
(
parmas
,
client_ip
)
{
// 支付宝回调
return
{
try
{
code
:
0
,
//日志记录
msg
:
"success"
this
.
logCtl
.
info
({
}
optitle
:
(
new
Date
()).
Format
(
"yyyy-MM-dd hh:mm:ss"
)
+
"支付宝回调参数信息"
,
op
:
"service/impl/utilsSve/utilsOrderSve.js/aliPayNotify"
,
content
:
JSON
.
stringify
(
parmas
),
clientIp
:
client_ip
||
""
});
if
(
!
parmas
.
trade_status
)
{
return
system
.
getResult
(
null
,
"trade_status参数不能为空,100470"
);
}
if
(
parmas
.
trade_status
!=
"TRADE_FINISHED"
&&
parmas
.
trade_status
!=
"TRADE_SUCCESS"
)
{
return
system
.
getResult
(
null
,
"trade_status状态有误,100473"
);
}
// 2020 0621 支付宝验签接口
// var url = this.centerAppUrl + "payment/aliPayment/verifyAliPayReturnSign";
// var url = this.centerAppUrl + "";
// var opResult = await this.restPostUrl(parmas, url);
// if (opResult.status != 0) {
// opResult.msg = opResult.msg + ",100480";
// return opResult;
// }
// 模拟验签结果
var
outTradeInfo
=
parmas
.
out_trade_no
.
split
(
'-'
);
//
var
opResult
=
{}
opResult
.
data
=
{
orderNo
:
outTradeInfo
[
0
],
uappId
:
Number
(
outTradeInfo
[
1
]),
productId
:
outTradeInfo
.
length
==
3
?
Number
(
outTradeInfo
[
2
])
:
0
}
// 拿锁
var
locker
=
await
this
.
cacheManager
[
"TlPayLocker"
].
enter
(
opResult
.
data
.
orderNo
);
if
(
!
locker
||
locker
!=
"1"
)
{
this
.
logCtl
.
info
({
appid
:
opResult
.
data
.
uappId
,
appkey
:
""
,
op
:
"service/impl/utilsSve/utilsOrderSve.js/opH5AliDingPayBackNotify"
,
content
:
"参数="
+
JSON
.
stringify
(
parmas
),
clientIp
:
parmas
.
client_ip
||
""
,
optitle
:
"阿里回调操作频繁---太频繁了,太频繁了"
});
return
system
.
getResultFail
(
-
200
,
"阿里回调操作频繁---太频繁了,太频繁了"
);
}
parmas
.
appInfo
=
{
appInfo
:
{
uapp_id
:
opResult
.
data
.
uappId
}
};
parmas
.
orderNo
=
opResult
.
data
.
orderNo
;
parmas
.
pay_type
=
"alipay"
;
//修改并返回订单支付状态,创建收款单
// 这里修改了order_info的状态(status/paytime等)
var
url
=
this
.
centerOrderUrl
+
"opaction/opPayOrder/receivePayCallBackNotifyByAliDing"
;
var
opOrderResult
=
await
this
.
restPostUrl
(
parmas
,
url
);
if
(
opOrderResult
.
status
!=
0
)
{
opOrderResult
.
data
=
null
;
return
opOrderResult
;
}
opOrderResult
.
data
.
appInfo
=
{
uapp_id
:
opResult
.
data
.
uappId
};
opOrderResult
.
data
.
userInfo
=
{
channel_userid
:
opOrderResult
.
data
.
order_info
.
channelUserId
,
channel_username
:
opOrderResult
.
data
.
order_info
.
channelUserId
,
channel_nickname
:
opOrderResult
.
data
.
order_info
.
channelUserId
};
opOrderResult
.
data
.
orderNo
=
opResult
.
data
.
orderNo
;
var
pobj
=
{
appInfo
:
opOrderResult
.
data
.
appInfo
,
actionBody
:
opOrderResult
.
data
}
this
.
utilsPushSve
.
pushBusInfo
(
pobj
,
"createAliTmApply"
,
1
);
opOrderResult
.
data
=
null
;
return
opOrderResult
;
}
catch
(
e
)
{
await
this
.
cacheManager
[
"TlPayLocker"
].
release
(
parmas
.
out_trade_no
);
this
.
logCtl
.
error
({
optitle
:
"回调处理订单---error异常"
,
op
:
"center-app/app/base/service/impl/utilsSve/utilstlbankSve.js/opBackNotify"
,
content
:
"参数="
+
JSON
.
stringify
(
parmas
)
+
",error:"
+
e
.
stack
,
clientIp
:
client_ip
||
""
});
return
system
.
getResultFail
(
-
200
,
e
.
stack
);
}
}
}
}
}
module
.
exports
=
UtilsOrderService
;
module
.
exports
=
UtilsOrderService
;
center-channel/app/base/service/impl/utilsSve/utilsUcommuneSve.js
View file @
50df8206
...
@@ -85,32 +85,53 @@ class UtilsUcommuneService extends AppServiceBase {
...
@@ -85,32 +85,53 @@ class UtilsUcommuneService extends AppServiceBase {
return
system
.
getResult
(
null
,
"Failed to get orderResult 100470"
);
return
system
.
getResult
(
null
,
"Failed to get orderResult 100470"
);
}
else
{
}
else
{
if
(
actionBody
.
payWay
==
1
)
{
// 支付宝
if
(
actionBody
.
payWay
==
1
)
{
// 支付宝
let
sign
=
await
PayUtil
.
getSign
(
null
,
"1"
)
let
creatPayRequrl
=
"https://yf-api.gongsibao.com/pay/v1/aliPay/getPrePayIdAliPay"
;
let
params
=
{
let
params
=
{
"partner"
:
"2019022163300183"
,
"app"
:
"ukgc"
,
//固定
"seller_id"
:
"353494220@qq.com"
,
'body'
:
orderResult
.
data
.
orderProduct
.
channelItemName
,
// "out_trade_no" : orderResult.data.channelOrderNo ,
"key"
:
"a1519e2eab53dfb909e4c32a86b2ea2b"
,
//固定
"out_trade_no"
:
orderResult
.
data
.
receiptVoucher
.
sourceOrderNo
+
"-"
+
pobj
.
appInfo
.
uapp_id
.
toString
()
+
"-"
+
orderResult
.
data
.
orderProduct
.
id
.
toString
(),
"notifyUrl"
:
this
.
centerChannelUrl
+
"orderNotify/aliPayNotify"
,
"outTradeNo"
:
orderResult
.
data
.
receiptVoucher
.
sourceOrderNo
+
"-"
+
pobj
.
appInfo
.
uapp_id
.
toString
()
+
"-"
+
orderResult
.
data
.
orderProduct
.
id
.
toString
(),
"productCode"
:
orderResult
.
data
.
orderProduct
.
channelItemCode
,
"subject"
:
orderResult
.
data
.
orderProduct
.
channelItemName
,
"subject"
:
orderResult
.
data
.
orderProduct
.
channelItemName
,
"body"
:
orderResult
.
data
.
orderProduct
.
channelItemName
,
"timeoutExpress"
:
'10m'
,
"total_fee"
:
Number
(
orderResult
.
data
.
receiptVoucher
.
totalSum
)
,
"totalAmount"
:
orderResult
.
data
.
receiptVoucher
.
totalSum
,
"service"
:
"alipay.trade.app.pay"
,
"payment_type"
:
"1"
,
"_input_charset"
:
"utf-8"
,
"it_b_pay"
:
"10m"
,
"notify_url"
:
this
.
centerChannelUrl
+
"orderNotify/aliPayNotify"
,
"enable_paymethod"
:
"balance,moneyFund,coupon,pcredit,pcreditpayInstallment,creditCard,creditCardExpress,creditCardCartoon,credit_group,debitCardExpress,mcard,pcard,promotion"
,
"sign"
:
sign
,
"sign_type"
:
"RSA2"
,
}
}
let
str
=
""
;
var
sign
=
JSON
.
stringify
(
params
);
for
(
var
k
in
params
)
{
sign
+=
"ab53dfb909e4c32a"
console
.
log
(
k
)
sign
=
md5
(
sign
).
toUpperCase
()
str
+=
k
+
"=
\"
"
+
params
[
k
]
+
"
\"
&"
;
params
.
sign
=
sign
let
res
=
await
axios
.
post
(
creatPayRequrl
,
params
)
if
(
res
.
status
==
200
&&
res
.
data
.
code
==
200
)
{
return
system
.
getResultSuccess
(
res
.
data
)
}
}
str
=
str
.
substr
(
0
,
str
.
length
-
1
)
return
system
.
getResult
(
null
,
res
.
data
.
msg
);
console
.
log
(
str
)
// let sign = await PayUtil.getSign(null,"1")
return
system
.
getResultSuccess
(
str
);
// let params = {
// "partner" : "2019022163300183" ,
// "seller_id" : "353494220@qq.com" ,
// // "out_trade_no" : orderResult.data.channelOrderNo ,
// "out_trade_no": orderResult.data.receiptVoucher.sourceOrderNo + "-" + pobj.appInfo.uapp_id.toString() + "-" + orderResult.data.orderProduct.id.toString(),
// "subject" : orderResult.data.orderProduct.channelItemName ,
// "body" : orderResult.data.orderProduct.channelItemName ,
// "total_fee" : Number(orderResult.data.receiptVoucher.totalSum) ,
// "service" : "alipay.trade.app.pay" ,
// "payment_type" : "1" ,
// "_input_charset" : "utf-8" ,
// "it_b_pay" : "10m" ,
// "notify_url" : this.centerChannelUrl + "orderNotify/aliPayNotify" ,
// "enable_paymethod" : "balance,moneyFund,coupon,pcredit,pcreditpayInstallment,creditCard,creditCardExpress,creditCardCartoon,credit_group,debitCardExpress,mcard,pcard,promotion" ,
// "sign" : sign ,
// "sign_type" : "RSA2",
// }
// let str = "";
// for(var k in params) {
// console.log(k)
// str += k + "=\"" + params[k] + "\"&";
// }
// str = str.substr(0,str.length-1)
// console.log(str)
// return system.getResultSuccess(str);
// let alipayAgentInformation = await this.redisClient.get("alipayAgentInformation")
// let alipayAgentInformation = await this.redisClient.get("alipayAgentInformation")
// if(!alipayAgentInformation) {
// if(!alipayAgentInformation) {
// console.log("11111")
// console.log("11111")
...
@@ -173,16 +194,30 @@ class UtilsUcommuneService extends AppServiceBase {
...
@@ -173,16 +194,30 @@ class UtilsUcommuneService extends AppServiceBase {
// console.log(alipayResponse);
// console.log(alipayResponse);
}
}
if
(
actionBody
.
payWay
==
3
)
{
// 微信
if
(
actionBody
.
payWay
==
3
)
{
// 微信
let
sign
=
await
PayUtil
.
getSign
(
'wx6f3ebe44defe336a'
,
"3"
)
let
requrl
=
""
;
let
wxpayJson
=
{
let
params
=
{
"appid"
:
"wx05b764a334ca0472"
,
'body'
:
orderResult
.
data
.
orderProduct
.
channelItemName
,
"noncestr"
:
"fdbe012e2e11314b96402b32c0df26b7"
,
"outTradeNo"
:
orderResult
.
data
.
receiptVoucher
.
sourceOrderNo
+
"-"
+
pobj
.
appInfo
.
uapp_id
.
toString
()
+
"-"
+
orderResult
.
data
.
orderProduct
.
id
.
toString
(),
"package"
:
"Sign=WXPay"
,
"totalAmount"
:
Number
(
orderResult
.
data
.
receiptVoucher
.
totalSum
),
"partnerid"
:
"1525494731"
,
"spbill_create_ip"
:
"192.168.2.210"
,
"prepayid"
:
"wx221007210600552805dae6511340418300"
,
"notifyUrl"
:
this
.
centerChannelUrl
+
"orderNotify/wxPayNotify"
,
"sign"
:
"7BACA717B040DEEA7A8940CEC94A3318"
,
"trade_type"
:
"APP"
,
"timestamp"
:
"1592791641"
}
}
let
res
=
await
axios
(
reqUrl
,
params
)
console
.
log
(
res
);
// let sign = await PayUtil.getSign('wx6f3ebe44defe336a',"3")
// let wxpayJson = {
// "appid": "wx05b764a334ca0472",
// "noncestr": "fdbe012e2e11314b96402b32c0df26b7",
// "package": "Sign=WXPay",
// "partnerid": "1525494731",
// "prepayid": "wx221007210600552805dae6511340418300",
// "sign": "7BACA717B040DEEA7A8940CEC94A3318",
// "timestamp": "1592791641"
// }
// let wxAgentInformation = await this.redisClient.get("wxAgentInformation")
// let wxAgentInformation = await this.redisClient.get("wxAgentInformation")
// if(!wxAgentInformation) {
// if(!wxAgentInformation) {
// console.log("11111")
// console.log("11111")
...
...
center-channel/app/config/routes/api.js
View file @
50df8206
...
@@ -425,10 +425,10 @@ module.exports = function (app) {
...
@@ -425,10 +425,10 @@ module.exports = function (app) {
app
.
post
(
'/orderNotify/aliPayNotify'
,
async
function
(
req
,
res
)
{
app
.
post
(
'/orderNotify/aliPayNotify'
,
async
function
(
req
,
res
)
{
try
{
try
{
var
client_ip
=
system
.
get_client_ip
(
req
);
var
client_ip
=
system
.
get_client_ip
(
req
);
var
result
=
await
utilsOrderSve
.
opH5AliDingPayBackNotify
(
req
.
body
);
var
result
=
await
utilsOrderSve
.
aliPayNotify
(
req
.
body
,
client_ip
);
logCtl
.
info
({
logCtl
.
info
({
optitle
:
(
new
Date
()).
Format
(
"yyyy-MM-dd hh:mm:ss"
)
+
"记录
阿里钉钉支付
回调处理结果"
,
optitle
:
(
new
Date
()).
Format
(
"yyyy-MM-dd hh:mm:ss"
)
+
"记录
支付宝
回调处理结果"
,
op
:
"center-channel/
tlpa
y/aliPayNotify"
,
op
:
"center-channel/
orderNotif
y/aliPayNotify"
,
content
:
"支付回调处理结果:"
+
JSON
.
stringify
(
result
),
content
:
"支付回调处理结果:"
+
JSON
.
stringify
(
result
),
clientIp
:
client_ip
||
""
clientIp
:
client_ip
||
""
});
});
...
@@ -438,110 +438,35 @@ module.exports = function (app) {
...
@@ -438,110 +438,35 @@ module.exports = function (app) {
return
res
.
end
(
"success"
);
return
res
.
end
(
"success"
);
}
catch
{
}
catch
{
logCtl
.
error
({
logCtl
.
error
({
optitle
:
(
new
Date
()).
Format
(
"yyyy-MM-dd hh:mm:ss"
)
+
"
阿里钉钉支付
回调处理异常"
,
optitle
:
(
new
Date
()).
Format
(
"yyyy-MM-dd hh:mm:ss"
)
+
"
支付宝
回调处理异常"
,
op
:
"center-channel/
tlpa
y/aliPayNotify"
,
op
:
"center-channel/
orderNotif
y/aliPayNotify"
,
content
:
"回调参数:req="
+
JSON
.
stringify
(
req
)
+
"error:"
+
error
.
stack
,
content
:
"回调参数:req="
+
JSON
.
stringify
(
req
)
+
"error:"
+
error
.
stack
,
clientIp
:
client_ip
||
""
clientIp
:
client_ip
||
""
});
});
}
}
});
});
// wx支付回调
app
.
post
(
'/orderNotify/wxPayNotify'
,
async
function
(
req
,
res
)
{
app
.
post
(
'/pay/test'
,
async
function
(
req
,
res
)
{
try
{
var
unifiedorderUrl
=
"https://api.mch.weixin.qq.com/pay/unifiedorder"
;
var
client_ip
=
system
.
get_client_ip
(
req
);
var
opts
=
{};
var
result
=
await
utilsOrderSve
.
wxPayNotify
(
req
.
body
);
opts
.
nonce_str
=
WxPayUtil
.
generateNonceString
();
logCtl
.
info
({
optitle
:
(
new
Date
()).
Format
(
"yyyy-MM-dd hh:mm:ss"
)
+
"记录微信支付回调处理结果"
,
opts
.
appid
=
'wx05b764a334ca0472'
;
op
:
"center-channel/orderNotify/wxPayNotify"
,
content
:
"支付回调处理结果:"
+
JSON
.
stringify
(
result
),
opts
.
mch_id
=
'1232813602'
;
clientIp
:
client_ip
||
""
opts
.
device_info
=
"WEB"
;
opts
.
sign
=
'CE7022B710720E681230CE61CC3F6D9625115E07B3EFF1E740174F5EBC22026D'
;
opts
.
body
=
"1111"
;
opts
.
out_trade_no
=
"123123123"
;
opts
.
total_fee
=
123123
;
opts
.
spbill_create_ip
=
"192.169.1.1"
;
opts
.
notify_url
=
"https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1"
,
opts
.
trade_type
=
"APP"
var
postXml
=
WxPayUtil
.
buildXML
({
xml
:
opts
});
// console.log("微信付款单请求postXml",postXml);
axios
.
post
(
unifiedorderUrl
,
postXml
).
then
(
function
(
result
)
{
// console.log("微信付款单请求result.data",result.data);
WxPayUtil
.
parseXML
(
result
.
data
,
function
(
json
){
console
.
log
(
json
)
});
});
if
(
result
.
status
!=
0
)
{
}).
catch
(
function
(
error
){
return
res
.
end
(
"FAIL"
);
console
.
log
(
"微信生成付款单错误"
,
error
);
})
})
};
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
;
},
mix
:
function
()
{
var
root
=
arguments
[
0
];
if
(
arguments
.
length
==
1
)
{
return
root
;
}
for
(
var
i
=
1
;
i
<
arguments
.
length
;
i
++
)
{
for
(
var
k
in
arguments
[
i
])
{
root
[
k
]
=
arguments
[
i
][
k
];
}
}
return
res
.
end
(
"success"
);
}
catch
{
logCtl
.
error
({
optitle
:
(
new
Date
()).
Format
(
"yyyy-MM-dd hh:mm:ss"
)
+
"微信回调处理异常"
,
op
:
"center-channel/orderNotify/wxPayNotify"
,
content
:
"回调参数:req="
+
JSON
.
stringify
(
req
)
+
"error:"
+
error
.
stack
,
clientIp
:
client_ip
||
""
});
}
}
return
root
;
});
},
};
encodeUTF8
:
function
(
str
)
{
\ No newline at end of file
var
temp
=
""
,
rs
=
""
;
for
(
var
i
=
0
,
len
=
str
.
length
;
i
<
len
;
i
++
)
{
temp
=
str
.
charCodeAt
(
i
).
toString
(
16
);
rs
+=
"
\\
u"
+
new
Array
(
5
-
temp
.
length
).
join
(
"0"
)
+
temp
;
}
return
rs
;
},
buildXML
:
function
(
json
)
{
var
builder
=
new
xml2js
.
Builder
();
return
builder
.
buildObject
(
json
);
},
parseXML
:
function
(
xml
,
func
)
{
// var parser = new xml2js.Parser({ trim: true, explicitArray: false, explicitRoot: false });
xml2js
.
parseString
(
xml
,
{
trim
:
true
,
explicitArray
:
false
,
explicitRoot
:
false
},
function
(
err
,
result
){
if
(
err
){
console
.
log
(
err
);
}
else
{
func
(
result
)
}
});
},
sign
:
function
(
param
)
{
var
querystring
=
Object
.
keys
(
param
).
filter
(
function
(
key
)
{
return
param
[
key
]
!==
undefined
&&
param
[
key
]
!==
''
&&
[
'pfx'
,
'partner_key'
,
'sign'
,
'key'
].
indexOf
(
key
)
<
0
;
}).
sort
().
map
(
function
(
key
)
{
return
key
+
'='
+
param
[
key
];
}).
join
(
"&"
)
+
"&key="
+
config
.
wechat
.
pay
.
partnerKey
;
// console.log("sign:");
// console.log(querystring);
var
hash
=
md5
(
querystring
).
toUpperCase
();
return
hash
},
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment