Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rs-cloud-platform
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
周健威
rs-cloud-platform
Commits
987a0c91
Commit
987a0c91
authored
Dec 14, 2020
by
unset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改支付信息
parent
2d93c9b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
635 additions
and
603 deletions
+635
-603
OrderPayBiz.java
...ava/com/upyuns/platform/rs/universal/biz/OrderPayBiz.java
+635
-603
No files found.
rs-universal/rs-universal-server/src/main/java/com/upyuns/platform/rs/universal/biz/OrderPayBiz.java
View file @
987a0c91
...
@@ -54,634 +54,666 @@ import static com.upyuns.platform.rs.universal.constant.DictionaryKey.UNIVERSAL_
...
@@ -54,634 +54,666 @@ import static com.upyuns.platform.rs.universal.constant.DictionaryKey.UNIVERSAL_
*/
*/
@Service
@Service
@Slf4j
@Slf4j
public
class
OrderPayBiz
extends
BaseBiz
<
OrderPayMapper
,
OrderPay
>{
public
class
OrderPayBiz
extends
BaseBiz
<
OrderPayMapper
,
OrderPay
>
{
@Autowired
@Autowired
DictionaryBiz
dictionaryBiz
;
DictionaryBiz
dictionaryBiz
;
@Autowired
@Autowired
HttpServletRequest
request
;
HttpServletRequest
request
;
@Autowired
@Autowired
MQServiceBiZ
mqServiceBiZ
;
MQServiceBiZ
mqServiceBiZ
;
@Value
(
"${universal.url}"
)
@Value
(
"${universal.url}"
)
String
weixinHost
;
String
weixinHost
;
@Value
(
"${wx.appid}"
)
@Value
(
"${wx.appid}"
)
private
String
wy_appid
;
private
String
wy_appid
;
@Value
(
"${wx.appSercet}"
)
@Value
(
"${wx.appSercet}"
)
private
String
wy_secret
;
private
String
wy_secret
;
private
static
final
String
SUCCESS
=
"SUCCESS"
;
private
static
final
String
SUCCESS
=
"SUCCESS"
;
public
JSONObject
preparepay
(
OrderPayVo
orderPayVo
)
{
public
JSONObject
preparepay
(
OrderPayVo
orderPayVo
)
{
if
(
null
==
orderPayVo
)
{
if
(
null
==
orderPayVo
)
{
log
.
error
(
"-----参数为空-----------"
);
log
.
error
(
"-----参数为空-----------"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
}
}
if
(
orderPayVo
.
getAmount
()
==
null
||
orderPayVo
.
getAmount
()
==
0
)
{
if
(
orderPayVo
.
getAmount
()
==
null
||
orderPayVo
.
getAmount
()
==
0
)
{
log
.
error
(
"-----金额不为为0-----------"
);
log
.
error
(
"-----金额不为为0-----------"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"金额不为为0"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"金额不为为0"
);
}
}
if
(
StringUtils
.
isBlank
(
orderPayVo
.
getOrderNo
()))
{
if
(
StringUtils
.
isBlank
(
orderPayVo
.
getOrderNo
()))
{
log
.
error
(
"-----订单不能为空-----------"
);
log
.
error
(
"-----订单不能为空-----------"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"订单不能为空"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"订单不能为空"
);
}
}
log
.
info
(
"订单支付参数:orderVo = {}"
,
orderPayVo
.
toString
());
log
.
info
(
"订单支付参数:orderVo = {}"
,
orderPayVo
.
toString
());
String
trade_no
=
OrderUtil
.
GetOrderNumber
(
""
);
String
trade_no
=
OrderUtil
.
GetOrderNumber
(
""
);
orderPayVo
.
setTradeNo
(
trade_no
);
orderPayVo
.
setTradeNo
(
trade_no
);
String
order_no
=
orderPayVo
.
getOrderNo
();
String
order_no
=
orderPayVo
.
getOrderNo
();
Integer
amount
=
orderPayVo
.
getAmount
();
Integer
amount
=
orderPayVo
.
getAmount
();
log
.
error
(
"---下单---order_no====="
+
order_no
+
"--支付订单号--trade_no===="
+
trade_no
+
"--金额---amount===="
+
amount
);
log
.
error
(
"---下单---order_no====="
+
order_no
+
"--支付订单号--trade_no===="
+
trade_no
+
"--金额---amount===="
+
amount
);
//报名费回调路径
//报名费回调路径
//临时处理
//临时处理
Map
<
String
,
Dictionary
>
dictionaryMap
=
dictionaryBiz
.
getAll4Map
();
Map
<
String
,
Dictionary
>
dictionaryMap
=
dictionaryBiz
.
getAll4Map
();
Integer
demotion
=
Integer
.
valueOf
(
dictionaryMap
.
get
(
UNIVERSAL_PAY
+
"_"
+
PAY_DEMOTION
).
getDetail
());
Integer
demotion
=
Integer
.
valueOf
(
dictionaryMap
.
get
(
UNIVERSAL_PAY
+
"_"
+
PAY_DEMOTION
).
getDetail
());
amount
=
amount
/
demotion
;
amount
=
amount
/
demotion
;
if
(
amount
<=
0
)
{
if
(
amount
<=
0
)
{
amount
=
1
;
amount
=
1
;
}
}
Integer
type
=
orderPayVo
.
getType
()
==
null
?
1
:
orderPayVo
.
getType
();
Integer
type
=
orderPayVo
.
getType
()
==
null
?
1
:
orderPayVo
.
getType
();
String
jsParam
=
""
;
String
jsParam
=
""
;
String
notify_url
=
weixinHost
+
"/api/universal/pay/app/unauth/notify"
;
String
notify_url
=
weixinHost
+
"/api/universal/pay/app/unauth/notify"
;
String
notifyUrl
=
weixinHost
+
"/api/universal/pay/app/unauth/notify/alipay"
;
String
notifyUrl
=
weixinHost
+
"/api/universal/pay/app/unauth/notify/alipay"
;
log
.
info
(
"报名费回调路径notify_url:"
+
notify_url
);
log
.
info
(
"报名费回调路径notify_url:"
+
notify_url
);
Integer
payWay
=
orderPayVo
.
getPayWay
()
==
null
?
1
:
orderPayVo
.
getPayWay
();
Integer
payWay
=
orderPayVo
.
getPayWay
()
==
null
?
1
:
orderPayVo
.
getPayWay
();
String
sellerAccount
=
null
;
String
sellerAccount
=
null
;
if
(
type
==
2
&&
payWay
==
1
)
{
if
(
type
==
2
&&
payWay
==
1
)
{
sellerAccount
=
SystemConfig
.
APP_PARTNER
;
sellerAccount
=
SystemConfig
.
APP_PARTNER
;
jsParam
=
WXPay
.
webPay
(
amount
+
""
,
orderPayVo
.
getBody
(),
notify_url
,
trade_no
,
orderPayVo
.
getBuyerIp
(),
orderPayVo
.
getBuyerAccount
(),
null
);
jsParam
=
WXPay
.
webPay
(
amount
+
""
,
orderPayVo
.
getBody
(),
notify_url
,
trade_no
,
orderPayVo
.
getBuyerIp
(),
orderPayVo
.
getBuyerAccount
(),
null
);
}
else
if
(
type
==
1
&&
payWay
==
1
)
{
}
else
if
(
type
==
1
&&
payWay
==
1
)
{
sellerAccount
=
SystemConfig
.
APP_PARTNER
;
sellerAccount
=
SystemConfig
.
APP_PARTNER
;
jsParam
=
WXPay
.
apppay
(
amount
+
""
,
orderPayVo
.
getBody
(),
notify_url
,
trade_no
,
orderPayVo
.
getBuyerIp
(),
0
);
jsParam
=
WXPay
.
apppay
(
amount
+
""
,
orderPayVo
.
getBody
(),
notify_url
,
trade_no
,
orderPayVo
.
getBuyerIp
(),
0
);
}
else
if
(
type
==
1
&&
payWay
==
2
)
{
}
else
if
(
type
==
1
&&
payWay
==
2
)
{
sellerAccount
=
SystemConfig
.
ALIPAY_PID
;
sellerAccount
=
SystemConfig
.
ALIPAY_PID
;
orderPayVo
.
setPayType
(
2
);
orderPayVo
.
setPayType
(
2
);
jsParam
=
generateAliPayment
(
orderPayVo
,
notifyUrl
);
jsParam
=
generateAliPayment
(
orderPayVo
,
notifyUrl
);
}
else
if
(
type
==
3
&&
payWay
==
1
)
{
}
else
if
(
type
==
3
&&
payWay
==
1
)
{
sellerAccount
=
SystemConfig
.
APP_PARTNER
;
sellerAccount
=
SystemConfig
.
APP_PARTNER
;
jsParam
=
WXPay
.
webPay
(
amount
+
""
,
orderPayVo
.
getBody
(),
notify_url
,
trade_no
,
orderPayVo
.
getBuyerIp
(),
orderPayVo
.
getBuyerAccount
(),
wy_appid
);
jsParam
=
WXPay
.
webPay
(
amount
+
""
,
orderPayVo
.
getBody
(),
notify_url
,
trade_no
,
orderPayVo
.
getBuyerIp
(),
orderPayVo
.
getBuyerAccount
(),
wy_appid
);
}
}
log
.
info
(
"报名费回调路径jsParam:"
+
jsParam
);
log
.
info
(
"报名费回调路径jsParam:"
+
jsParam
);
if
(!
StringUtils
.
isBlank
(
jsParam
))
{
if
(!
StringUtils
.
isBlank
(
jsParam
))
{
try
{
try
{
OrderPay
orderPay
=
new
OrderPay
();
OrderPay
orderPay
=
new
OrderPay
();
BeanUtils
.
copyProperties
(
orderPay
,
orderPayVo
);
BeanUtils
.
copyProperties
(
orderPay
,
orderPayVo
);
orderPay
.
setSellerAccount
(
sellerAccount
);
orderPay
.
setSellerAccount
(
sellerAccount
);
insertSelective
(
orderPay
);
insertSelective
(
orderPay
);
log
.
error
(
"---下单---order_no====="
+
order_no
+
"----成功"
);
log
.
error
(
"---下单---order_no====="
+
order_no
+
"----成功"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);;
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
"---下单---order_no====="
+
order_no
+
"----异常---msg==="
+
e
.
getMessage
());
;
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXCEPTION_CODE
,
"出现异常"
);
log
.
error
(
"---下单---order_no====="
+
order_no
+
"----异常---msg==="
+
e
.
getMessage
());
}
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXCEPTION_CODE
,
"出现异常"
);
if
(
payWay
==
1
)
{
}
JSONObject
temp
=
JSON
.
parseObject
(
jsParam
);
if
(
payWay
==
1
)
{
return
JsonResultUtil
.
createSuccessResultWithObj
(
temp
);
JSONObject
temp
=
JSON
.
parseObject
(
jsParam
);
}
else
{
return
JsonResultUtil
.
createSuccessResultWithObj
(
temp
);
return
JsonResultUtil
.
createSuccessResultWithObj
(
jsParam
);
}
else
{
}
return
JsonResultUtil
.
createSuccessResultWithObj
(
jsParam
);
}
else
{
}
return
JsonResultUtil
.
createDefaultFail
();
}
else
{
}
return
JsonResultUtil
.
createDefaultFail
();
}
}
}
//支付回调
public
void
notice
(
String
orderNo
,
String
serialNumber
)
{
//支付回调
log
.
error
(
"---支付回调---trade_no====="
+
orderNo
+
"----开始处理"
);
public
void
notice
(
String
orderNo
,
String
serialNumber
)
{
Example
example
=
new
Example
(
OrderPay
.
class
);
log
.
error
(
"---支付回调---trade_no====="
+
orderNo
+
"----开始处理"
);
example
.
createCriteria
().
andEqualTo
(
"tradeNo"
,
orderNo
).
andEqualTo
(
"isDel"
,
0
).
andEqualTo
(
"status"
,
0
);
Example
example
=
new
Example
(
OrderPay
.
class
);
List
<
OrderPay
>
list
=
mapper
.
selectByExample
(
example
);
example
.
createCriteria
().
andEqualTo
(
"tradeNo"
,
orderNo
).
andEqualTo
(
"isDel"
,
0
).
andEqualTo
(
"status"
,
0
);
if
(
list
.
size
()
==
0
)
{
List
<
OrderPay
>
list
=
mapper
.
selectByExample
(
example
);
log
.
error
(
"---支付回调---trade_no====="
+
orderNo
+
"----订单不存在或已处理"
);
if
(
list
.
size
()
==
0
)
{
return
;
log
.
error
(
"---支付回调---trade_no====="
+
orderNo
+
"----订单不存在或已处理"
);
}
return
;
example
.
clear
();
}
example
.
createCriteria
().
andEqualTo
(
"tradeNo"
,
orderNo
);
example
.
clear
();
OrderPay
orderPay
=
new
OrderPay
();
example
.
createCriteria
().
andEqualTo
(
"tradeNo"
,
orderNo
);
orderPay
.
setFinishTime
(
System
.
currentTimeMillis
());
OrderPay
orderPay
=
new
OrderPay
();
orderPay
.
setStatus
(
1
);
orderPay
.
setFinishTime
(
System
.
currentTimeMillis
());
orderPay
.
setSerialNumber
(
serialNumber
);
orderPay
.
setStatus
(
1
);
int
num
=
mapper
.
updateByExampleSelective
(
orderPay
,
example
);
orderPay
.
setSerialNumber
(
serialNumber
);
int
num
=
mapper
.
updateByExampleSelective
(
orderPay
,
example
);
log
.
error
(
"---支付回调处理---num====="
+
num
+
"----orderNo======="
+
orderNo
);
if
(
num
>
0
)
{
log
.
error
(
"---支付回调处理---num====="
+
num
+
"----orderNo======="
+
orderNo
);
//支付成功,添加积分
if
(
num
>
0
)
{
OrderPay
pay
=
list
.
get
(
0
);
//支付成功,添加积分
OrderPay
newValue
=
mapper
.
selectOne
(
orderPay
);
OrderPay
pay
=
list
.
get
(
0
);
log
.
info
(
"支付回调信息:newValue = {}"
,
newValue
);
OrderPay
newValue
=
mapper
.
selectOne
(
orderPay
);
if
(
newValue
.
getStatus
()
==
1
)
{
log
.
info
(
"支付回调信息:newValue = {}"
,
newValue
);
JSONObject
jsonObject
=
new
JSONObject
();
if
(
newValue
.
getStatus
()
==
1
)
{
jsonObject
.
put
(
"userId"
,
newValue
.
getUserId
());
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"amount"
,
newValue
.
getAmount
());
jsonObject
.
put
(
"userId"
,
newValue
.
getUserId
());
jsonObject
.
put
(
"channelId"
,
newValue
.
getOrderNo
());
jsonObject
.
put
(
"amount"
,
newValue
.
getAmount
());
if
(
newValue
.
getChannel
()
==
1
)
{
//租车
jsonObject
.
put
(
"channelId"
,
newValue
.
getOrderNo
());
jsonObject
.
put
(
"integralRuleCode"
,
"RENTRV"
);
if
(
newValue
.
getChannel
()
==
1
)
{
//租车
}
else
if
(
newValue
.
getChannel
()
==
2
)
{
//旅游
jsonObject
.
put
(
"integralRuleCode"
,
"RENTRV"
);
jsonObject
.
put
(
"integralRuleCode"
,
"BUYROUT"
);
}
else
if
(
newValue
.
getChannel
()
==
2
)
{
//旅游
}
else
if
(
newValue
.
getChannel
()
==
3
)
{
//会员
jsonObject
.
put
(
"integralRuleCode"
,
"BUYROUT"
);
jsonObject
.
put
(
"integralRuleCode"
,
"BUYMEMBER"
);
}
else
if
(
newValue
.
getChannel
()
==
3
)
{
//会员
}
jsonObject
.
put
(
"integralRuleCode"
,
"BUYMEMBER"
);
log
.
info
(
"支付订单号:orderNo = {}, orderType = {}"
,
newValue
.
getOrderNo
(),
newValue
.
getChannel
());
}
log
.
info
(
"支付成功获取积分:发送消息 exchange = {}, routingKey = {}, json = {}"
,
RabbitConstant
.
INTEGRAL_TOPIC
,
RabbitConstant
.
INTEGRAL_ROUTING_KEY
,
jsonObject
.
toJSONString
());
log
.
info
(
"支付订单号:orderNo = {}, orderType = {}"
,
newValue
.
getOrderNo
(),
newValue
.
getChannel
());
mqServiceBiZ
.
sendMessage
(
RabbitConstant
.
INTEGRAL_TOPIC
,
RabbitConstant
.
INTEGRAL_ROUTING_KEY
,
jsonObject
.
toJSONString
());
log
.
info
(
"支付成功获取积分:发送消息 exchange = {}, routingKey = {}, json = {}"
,
RabbitConstant
.
INTEGRAL_TOPIC
,
RabbitConstant
.
INTEGRAL_ROUTING_KEY
,
jsonObject
.
toJSONString
());
}
mqServiceBiZ
.
sendMessage
(
RabbitConstant
.
INTEGRAL_TOPIC
,
RabbitConstant
.
INTEGRAL_ROUTING_KEY
,
jsonObject
.
toJSONString
());
if
(
StringUtils
.
isNotBlank
(
pay
.
getNotifyUrl
()))
{
}
String
url
=
pay
.
getNotifyUrl
();
if
(
StringUtils
.
isNotBlank
(
pay
.
getNotifyUrl
()))
{
Integer
type
=
pay
.
getType
()
==
null
?
1
:
pay
.
getType
();
String
url
=
pay
.
getNotifyUrl
();
Integer
payWay
=
pay
.
getPayWay
();
Integer
type
=
pay
.
getType
()
==
null
?
1
:
pay
.
getType
();
url
+=
"&tradeNo="
+
orderNo
+
"&type="
+
type
+
"&payWay="
+
payWay
;
Integer
payWay
=
pay
.
getPayWay
();
log
.
error
(
"---支付回调处理---orderNo======="
+
orderNo
+
"----notifyUrl===="
+
url
);
url
+=
"&tradeNo="
+
orderNo
+
"&type="
+
type
+
"&payWay="
+
payWay
;
String
result
=
""
;
log
.
error
(
"---支付回调处理---orderNo======="
+
orderNo
+
"----notifyUrl===="
+
url
);
if
(
url
.
contains
(
"https"
)
||
url
.
contains
(
"HTTPS"
))
{
String
result
=
""
;
result
=
HTTPSUtils
.
httpRequest
(
url
,
"GET"
,
null
);
if
(
url
.
contains
(
"https"
)
||
url
.
contains
(
"HTTPS"
))
{
}
else
{
result
=
HTTPSUtils
.
httpRequest
(
url
,
"GET"
,
null
);
result
=
HTTPUtils
.
doGet
(
url
);
}
else
{
}
result
=
HTTPUtils
.
doGet
(
url
);
log
.
error
(
"---支付回调处理---orderNo======="
+
orderNo
+
"---result==="
+
result
);
}
log
.
error
(
"---支付回调处理---orderNo======="
+
orderNo
+
"---result==="
+
result
);
}
}
}
/**
}
* 支付宝回调接口
}
*
}
* @return
*/
/**
public
String
alipayNotify
()
{
* 支付宝回调接口
//获取支付宝POST过来反馈信息
*
Map
<
String
,
String
>
params
=
new
HashMap
<>();
* @return
Map
requestParams
=
request
.
getParameterMap
();
*/
for
(
Iterator
iter
=
requestParams
.
keySet
().
iterator
();
iter
.
hasNext
();
)
{
public
String
alipayNotify
()
{
String
name
=
(
String
)
iter
.
next
();
//获取支付宝POST过来反馈信息
String
[]
values
=
(
String
[])
requestParams
.
get
(
name
);
Map
<
String
,
String
>
params
=
new
HashMap
<>();
String
valueStr
=
""
;
Map
requestParams
=
request
.
getParameterMap
();
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
for
(
Iterator
iter
=
requestParams
.
keySet
().
iterator
();
iter
.
hasNext
();
)
{
valueStr
=
(
i
==
values
.
length
-
1
)
?
valueStr
+
values
[
i
]
String
name
=
(
String
)
iter
.
next
();
:
valueStr
+
values
[
i
]
+
","
;
String
[]
values
=
(
String
[])
requestParams
.
get
(
name
);
}
String
valueStr
=
""
;
params
.
put
(
name
,
valueStr
);
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
}
valueStr
=
(
i
==
values
.
length
-
1
)
?
valueStr
+
values
[
i
]
String
msg
=
JSONObject
.
toJSONString
(
params
);
:
valueStr
+
values
[
i
]
+
","
;
log
.
info
(
"alipay notify message={}"
,
msg
);
}
//支付宝回调验签
params
.
put
(
name
,
valueStr
);
try
{
}
boolean
flag
=
AlipaySignature
.
rsaCheckV1
(
params
,
SystemConfig
.
ALIPAY_PUBLIC_KEY
,
AlipayConstants
.
CHARSET_UTF8
,
AlipayConstants
.
SIGN_TYPE_RSA2
);
String
msg
=
JSONObject
.
toJSONString
(
params
);
if
(!
flag
)
{
log
.
info
(
"alipay notify message={}"
,
msg
);
log
.
info
(
"alipay order rsaCheckV1 fail, result={}"
,
msg
);
//支付宝回调验签
return
ObjectRestResponse
.
createDefaultFail
().
getMessage
();
try
{
}
boolean
flag
=
AlipaySignature
.
rsaCheckV1
(
params
,
SystemConfig
.
ALIPAY_PUBLIC_KEY
,
AlipayConstants
.
CHARSET_UTF8
,
AlipayConstants
.
SIGN_TYPE_RSA2
);
String
rsTradeStatus
=
params
.
get
(
"trade_status"
);
if
(!
flag
)
{
if
(
StringUtils
.
isBlank
(
rsTradeStatus
))
{
//订单预授权支付回调
log
.
info
(
"alipay order rsaCheckV1 fail, result={}"
,
msg
);
return
ObjectRestResponse
.
createDefaultFail
().
getMessage
();
}
String
rsTradeStatus
=
params
.
get
(
"trade_status"
);
if
(
StringUtils
.
isBlank
(
rsTradeStatus
))
{
//订单预授权支付回调
String
status
=
params
.
get
(
"status"
);
String
status
=
params
.
get
(
"status"
);
if
(!
status
.
equals
(
"SUCCESS"
))
{
if
(!
status
.
equals
(
"SUCCESS"
))
{
log
.
info
(
"alipay order trade_status has problem, result={}"
,
msg
);
log
.
info
(
"alipay order trade_status has problem, result={}"
,
msg
);
return
ObjectRestResponse
.
createDefaultFail
().
getMessage
();
return
ObjectRestResponse
.
createDefaultFail
().
getMessage
();
}
}
//订单APP支付回调
//订单APP支付回调
}
else
if
(!
SystemConfig
.
ALIPAY_TRADE_FINISHED
.
equals
(
rsTradeStatus
)
&&
!
SystemConfig
.
ALIPAY_TRADE_SUCCESS
.
equals
(
rsTradeStatus
))
{
}
else
if
(!
SystemConfig
.
ALIPAY_TRADE_FINISHED
.
equals
(
rsTradeStatus
)
&&
!
SystemConfig
.
ALIPAY_TRADE_SUCCESS
.
equals
(
rsTradeStatus
))
{
log
.
info
(
"alipay order trade_status has problem, result={}"
,
msg
);
log
.
info
(
"alipay order trade_status has problem, result={}"
,
msg
);
return
ObjectRestResponse
.
createDefaultFail
().
getMessage
();
return
ObjectRestResponse
.
createDefaultFail
().
getMessage
();
}
}
String
tradeNo
=
params
.
get
(
"out_trade_no"
);
String
tradeNo
=
params
.
get
(
"out_trade_no"
);
if
(
StringUtils
.
isBlank
(
tradeNo
))
{
if
(
StringUtils
.
isBlank
(
tradeNo
))
{
tradeNo
=
params
.
get
(
"out_request_no"
);
tradeNo
=
params
.
get
(
"out_request_no"
);
}
}
String
operationId
=
params
.
get
(
"trade_no"
);
String
operationId
=
params
.
get
(
"trade_no"
);
if
(
StringUtils
.
isBlank
(
operationId
))
{
if
(
StringUtils
.
isBlank
(
operationId
))
{
operationId
=
params
.
get
(
"auth_no"
);
operationId
=
params
.
get
(
"auth_no"
);
}
}
notice
(
tradeNo
,
operationId
);
notice
(
tradeNo
,
operationId
);
return
ObjectRestResponse
.
succ
().
getMessage
();
return
ObjectRestResponse
.
succ
().
getMessage
();
}
catch
(
AlipayApiException
e
)
{
}
catch
(
AlipayApiException
e
)
{
log
.
error
(
""
,
e
);
log
.
error
(
""
,
e
);
}
}
return
ObjectRestResponse
.
createDefaultFail
().
getMessage
();
return
ObjectRestResponse
.
createDefaultFail
().
getMessage
();
}
}
/**
* 支付宝生成支付信息
/**
*
* 支付宝生成支付信息
* @return
*
*/
* @return
@SuppressWarnings
(
"rawtypes"
)
*/
private
String
generateAliPayment
(
OrderPayVo
orderPayVo
,
String
notifyUrl
)
{
@SuppressWarnings
(
"rawtypes"
)
//实例化客户端
private
String
generateAliPayment
(
OrderPayVo
orderPayVo
,
String
notifyUrl
)
{
AlipayClient
alipayClient
=
getAlipayClient
();
//实例化客户端
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
AlipayClient
alipayClient
=
getAlipayClient
();
try
{
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
return
fundAuthOrderAppFreeze
(
alipayClient
,
orderPayVo
,
notifyUrl
);
try
{
}
catch
(
Exception
e
)
{
return
preCreate
(
alipayClient
,
orderPayVo
,
notifyUrl
);
log
.
error
(
e
.
getMessage
(),
e
);;
}
catch
(
Exception
e
)
{
}
log
.
error
(
e
.
getMessage
(),
e
);
return
null
;
;
}
}
return
null
;
private
AlipayClient
getAlipayClient
()
{
}
AlipayClient
alipayClient
=
new
DefaultAlipayClient
(
SystemConfig
.
ALIPAY_PAY_BASE_URL
+
"/gateway.do"
,
SystemConfig
.
ALIPAY_APPID
,
SystemConfig
.
ALIPAY_PRIVATE_KEY
,
AlipayConstants
.
FORMAT_JSON
,
"utf-8"
,
SystemConfig
.
ALIPAY_PUBLIC_KEY
,
AlipayConstants
.
SIGN_TYPE_RSA2
);
private
AlipayClient
getAlipayClient
()
{
return
alipayClient
;
AlipayClient
alipayClient
=
new
DefaultAlipayClient
(
SystemConfig
.
ALIPAY_PAY_BASE_URL
+
"/gateway.do"
,
}
SystemConfig
.
ALIPAY_APPID
,
SystemConfig
.
ALIPAY_PRIVATE_KEY
,
AlipayConstants
.
FORMAT_JSON
,
"utf-8"
,
SystemConfig
.
ALIPAY_PUBLIC_KEY
,
AlipayConstants
.
SIGN_TYPE_RSA2
);
//balance 余额
return
alipayClient
;
//moneyFund 余额宝
}
//coupon 红包
//pcredit 花呗
//balance 余额
//pcreditpayInstallment 花呗分期
//moneyFund 余额宝
//creditCard 信用卡
//coupon 红包
//creditCardExpress 信用卡快捷
//pcredit 花呗
//creditCardCartoon 信用卡卡通
//pcreditpayInstallment 花呗分期
//credit_group 信用支付类型(包含信用卡卡通、信用卡快捷、花呗、花呗分期)
//creditCard 信用卡
//debitCardExpress 借记卡快捷
//creditCardExpress 信用卡快捷
//mcard 商户预存卡
//creditCardCartoon 信用卡卡通
//pcard 个人预存卡
//credit_group 信用支付类型(包含信用卡卡通、信用卡快捷、花呗、花呗分期)
//promotion 优惠(包含实时优惠+商户优惠)
//debitCardExpress 借记卡快捷
//voucher 营销券
//mcard 商户预存卡
//point 积分
//pcard 个人预存卡
//mdiscount 商户优惠
//promotion 优惠(包含实时优惠+商户优惠)
//bankPay
//voucher 营销券
//支付宝APP支付方法
//point 积分
private
String
appOrderPay
(
AlipayClient
alipayClient
,
OrderPayVo
orderPayVo
,
String
notifyUrl
)
{
//mdiscount 商户优惠
//bankPay
//支付宝APP支付方法
private
String
appOrderPay
(
AlipayClient
alipayClient
,
OrderPayVo
orderPayVo
,
String
notifyUrl
)
{
BigDecimal
realAmount
=
new
BigDecimal
(
orderPayVo
.
getAmount
().
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
AlipayTradeAppPayRequest
request
=
new
AlipayTradeAppPayRequest
();
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
request
.
setBizContent
(
"{"
+
"\"total_amount\":\""
+
realAmount
+
"\","
+
"\"subject\":\""
+
orderPayVo
.
getSubject
()
+
"\","
+
"\"enable_pay_channels\":\"balance,coupon,creditCard,creditCardExpress,creditCardCartoon,pcredit,credit_group,moneyFund,debitCardExpress\","
+
"\"out_trade_no\":\""
+
orderPayVo
.
getTradeNo
()
+
"\""
+
" }"
);
request
.
setNotifyUrl
(
notifyUrl
);
try
{
//这里和普通的接口调用不同,使用的是sdkExecute
AlipayTradeAppPayResponse
response
=
alipayClient
.
sdkExecute
(
request
);
log
.
info
(
response
.
getBody
());
//就是orderString 可以直接给客户端请求,无需再做处理。
return
response
.
getBody
();
}
catch
(
AlipayApiException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
return
null
;
}
/**
* 扫码支付
*
* @return
*/
private
String
preCreate
(
AlipayClient
alipayClient
,
OrderPayVo
orderPayVo
,
String
notifyUrl
)
{
BigDecimal
realAmount
=
new
BigDecimal
(
orderPayVo
.
getAmount
().
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
BigDecimal
realAmount
=
new
BigDecimal
(
orderPayVo
.
getAmount
().
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
AlipayTradeAppPayRequest
request
=
new
AlipayTradeAppPayRequest
();
AlipayTradePrecreateRequest
request
=
new
AlipayTradePrecreateRequest
();
//创建API对应的request类
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
request
.
setBizContent
(
"{"
+
request
.
setBizContent
(
"{"
+
"\"out_trade_no\":\""
+
orderPayVo
.
getTradeNo
()
+
"\","
+
//商户订单号
"\"total_amount\":\""
+
realAmount
+
"\","
+
"\"total_amount\":\""
+
realAmount
+
"\","
+
"\"subject\":\""
+
orderPayVo
.
getSubject
()
+
"\","
+
"\"subject\":\""
+
orderPayVo
.
getSubject
()
+
"\","
+
"\"enable_pay_channels\":\"balance,coupon,creditCard,creditCardExpress,creditCardCartoon,pcredit,credit_group,moneyFund,debitCardExpress\","
+
"\"timeout_express\":\"30m\"}"
);
//订单允许的最晚付款时间
"\"out_trade_no\":\""
+
orderPayVo
.
getTradeNo
()
+
"\""
+
" }"
);
request
.
setNotifyUrl
(
notifyUrl
);
try
{
try
{
//这里和普通的接口调用不同,使用的是sdkExecute
AlipayTradePrecreateResponse
response
=
alipayClient
.
execute
(
request
);
AlipayTradeAppPayResponse
response
=
alipayClient
.
sdkExecute
(
request
);
log
.
info
(
response
.
getBody
());
//就是orderString 可以直接给客户端请求,无需再做处理。
log
.
info
(
response
.
getBody
());
//就是orderString 可以直接给客户端请求,无需再做处理。
return
response
.
getBody
();
return
response
.
getBody
();
}
catch
(
AlipayApiException
e
)
{
}
catch
(
AlipayApiException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
;
log
.
error
(
e
.
getMessage
(),
e
);
}
}
return
null
;
return
null
;
}
}
//预授权冻结
//预授权冻结
public
String
fundAuthOrderAppFreeze
(
AlipayClient
alipayClient
,
OrderPayVo
orderPayVo
,
String
notifyUrl
)
throws
AlipayApiException
{
public
String
fundAuthOrderAppFreeze
(
AlipayClient
alipayClient
,
OrderPayVo
orderPayVo
,
String
notifyUrl
)
throws
AlipayApiException
{
AlipayFundAuthOrderAppFreezeRequest
request
=
new
AlipayFundAuthOrderAppFreezeRequest
();
AlipayFundAuthOrderAppFreezeRequest
request
=
new
AlipayFundAuthOrderAppFreezeRequest
();
BigDecimal
realAmount
=
new
BigDecimal
(
orderPayVo
.
getAmount
().
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
BigDecimal
realAmount
=
new
BigDecimal
(
orderPayVo
.
getAmount
().
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
request
.
setBizContent
(
"{"
+
request
.
setBizContent
(
"{"
+
"\"out_order_no\":\""
+
orderPayVo
.
getTradeNo
()
+
"\","
+
"\"out_order_no\":\""
+
orderPayVo
.
getTradeNo
()
+
"\","
+
"\"out_request_no\":\""
+
orderPayVo
.
getTradeNo
()
+
"\","
+
"\"out_request_no\":\""
+
orderPayVo
.
getTradeNo
()
+
"\","
+
"\"order_title\":\""
+
orderPayVo
.
getSubject
()
+
"\","
+
"\"order_title\":\""
+
orderPayVo
.
getSubject
()
+
"\","
+
"\"product_code\":\"PRE_AUTH_ONLINE\","
+
"\"product_code\":\"PRE_AUTH_ONLINE\","
+
"\"pay_timeout\":\"1d\","
+
"\"pay_timeout\":\"1d\","
+
"\"amount\": \""
+
realAmount
.
toString
()
+
"\" }"
);
"\"amount\": \""
+
realAmount
.
toString
()
+
"\" }"
);
request
.
setNotifyUrl
(
notifyUrl
);
//异步通知地址,必填,该接口只通过该参数进行异步通知
request
.
setNotifyUrl
(
notifyUrl
);
//异步通知地址,必填,该接口只通过该参数进行异步通知
AlipayFundAuthOrderAppFreezeResponse
response
=
alipayClient
.
sdkExecute
(
request
);
//注意这里是sdkExecute,可以获取签名参数
AlipayFundAuthOrderAppFreezeResponse
response
=
alipayClient
.
sdkExecute
(
request
);
//注意这里是sdkExecute,可以获取签名参数
log
.
info
(
"response: {}"
+
response
.
getBody
());
//签名后的参数,直接入参到
log
.
info
(
"response: {}"
+
response
.
getBody
());
//签名后的参数,直接入参到
if
(
response
.
isSuccess
())
{
if
(
response
.
isSuccess
())
{
log
.
info
(
"预授权冻结调用成功"
);
log
.
info
(
"预授权冻结调用成功"
);
return
response
.
getBody
();
return
response
.
getBody
();
}
else
{
}
else
{
log
.
info
(
"预授权冻结调用失败"
);
log
.
info
(
"预授权冻结调用失败"
);
return
null
;
return
null
;
}
}
}
}
/**
/**
* 转账功能 微信 | 支付宝
* 转账功能 微信 | 支付宝
*
*
* @param fundPayVo
* @param fundPayVo
* @return
* @return
* @throws Exception
* @throws Exception
*/
*/
public
String
fundTrans
(
FundPayVo
fundPayVo
)
throws
BaseException
{
public
String
fundTrans
(
FundPayVo
fundPayVo
)
throws
BaseException
{
String
cono
=
OrderUtil
.
GetOrderNumber
(
""
);
String
cono
=
OrderUtil
.
GetOrderNumber
(
""
);
fundPayVo
.
setOutBizNo
(
cono
);
fundPayVo
.
setOutBizNo
(
cono
);
if
(
fundPayVo
.
getType
()
==
PayWay
.
WX_PAY
.
getCode
())
{
if
(
fundPayVo
.
getType
()
==
PayWay
.
WX_PAY
.
getCode
())
{
//微信
//微信
fundPayVo
.
setCheckName
(
"NO_CHECK"
);
fundPayVo
.
setCheckName
(
"NO_CHECK"
);
return
wxpayfundTrans
(
fundPayVo
);
return
wxpayfundTrans
(
fundPayVo
);
}
}
if
(
fundPayVo
.
getType
()
==
PayWay
.
ALI_PAY
.
getCode
())
{
if
(
fundPayVo
.
getType
()
==
PayWay
.
ALI_PAY
.
getCode
())
{
//支付宝
//支付宝
return
alipayfundTrans
(
getAlipayClient
(),
fundPayVo
);
return
alipayfundTrans
(
getAlipayClient
(),
fundPayVo
);
}
}
throw
new
BaseException
(
"提现方式不对"
);
throw
new
BaseException
(
"提现方式不对"
);
}
}
/**
/**
* 支付宝转账功能 单笔最小转账0.1 最大小数点位数前支持13位,实际限额和签约一致
* 支付宝转账功能 单笔最小转账0.1 最大小数点位数前支持13位,实际限额和签约一致
*
*
* @param alipayClient
* @param alipayClient
* @throws AlipayApiException
* @throws AlipayApiException
*/
*/
public
String
alipayfundTrans
(
AlipayClient
alipayClient
,
FundPayVo
fundPayVo
){
public
String
alipayfundTrans
(
AlipayClient
alipayClient
,
FundPayVo
fundPayVo
)
{
AlipayFundTransToaccountTransferRequest
request
=
new
AlipayFundTransToaccountTransferRequest
();
AlipayFundTransToaccountTransferRequest
request
=
new
AlipayFundTransToaccountTransferRequest
();
request
.
setBizContent
(
"{"
+
request
.
setBizContent
(
"{"
+
"\"out_biz_no\":\""
+
fundPayVo
.
getOutBizNo
()
+
"\","
+
"\"out_biz_no\":\""
+
fundPayVo
.
getOutBizNo
()
+
"\","
+
"\"payee_type\":\"ALIPAY_USERID\","
+
"\"payee_type\":\"ALIPAY_USERID\","
+
"\"payee_account\":\""
+
fundPayVo
.
getPayeeAccount
()
+
"\","
+
"\"payee_account\":\""
+
fundPayVo
.
getPayeeAccount
()
+
"\","
+
"\"amount\":\""
+
fundPayVo
.
getAmount
()
+
"\","
+
"\"amount\":\""
+
fundPayVo
.
getAmount
()
+
"\","
+
"\"payer_show_name\":\""
+
fundPayVo
.
getPayerShowName
()
+
"\","
+
"\"payer_show_name\":\""
+
fundPayVo
.
getPayerShowName
()
+
"\","
+
"\"remark\":\""
+
fundPayVo
.
getRemark
()
+
"\""
+
"\"remark\":\""
+
fundPayVo
.
getRemark
()
+
"\""
+
" }"
);
" }"
);
AlipayFundTransToaccountTransferResponse
response
=
null
;
AlipayFundTransToaccountTransferResponse
response
=
null
;
try
{
try
{
response
=
alipayClient
.
execute
(
request
);
response
=
alipayClient
.
execute
(
request
);
}
catch
(
AlipayApiException
e
)
{
}
catch
(
AlipayApiException
e
)
{
throw
new
BaseException
(
"支付宝转账api调用错误"
,
e
);
throw
new
BaseException
(
"支付宝转账api调用错误"
,
e
);
}
}
if
(
response
.
isSuccess
())
{
if
(
response
.
isSuccess
())
{
return
fundPayVo
.
getOutBizNo
();
return
fundPayVo
.
getOutBizNo
();
}
else
{
}
else
{
throw
new
BaseException
(
response
.
getSubMsg
(),
response
.
getSubCode
());
throw
new
BaseException
(
response
.
getSubMsg
(),
response
.
getSubCode
());
}
}
}
}
public
String
wxpayfundTrans
(
FundPayVo
fundPayVo
)
{
public
String
wxpayfundTrans
(
FundPayVo
fundPayVo
)
{
Map
<
String
,
String
>
map
=
WXSuppToUserPay
.
WeiXinTiXian
(
fundPayVo
.
getPayeeAccount
(),
fundPayVo
.
getOutBizNo
(),
fundPayVo
.
getCheckName
(),
fundPayVo
.
getAmount
(),
fundPayVo
.
getRemark
(),
fundPayVo
.
getCreatIp
());
Map
<
String
,
String
>
map
=
WXSuppToUserPay
.
WeiXinTiXian
(
fundPayVo
.
getPayeeAccount
(),
fundPayVo
.
getOutBizNo
(),
fundPayVo
.
getCheckName
(),
fundPayVo
.
getAmount
(),
fundPayVo
.
getRemark
(),
fundPayVo
.
getCreatIp
());
if
(
SUCCESS
.
equals
(
map
.
get
(
WxResponseProperties
.
RETURN_CODE
))
&&
SUCCESS
.
equals
(
map
.
get
(
WxResponseProperties
.
RESULT_CODE
)))
{
if
(
SUCCESS
.
equals
(
map
.
get
(
WxResponseProperties
.
RETURN_CODE
))
&&
SUCCESS
.
equals
(
map
.
get
(
WxResponseProperties
.
RESULT_CODE
)))
{
return
map
.
get
(
WxResponseProperties
.
PARTNER_TRADE_NO
);
return
map
.
get
(
WxResponseProperties
.
PARTNER_TRADE_NO
);
}
}
throw
new
BaseException
(
map
.
get
(
WxResponseProperties
.
ERR_CODE_DES
),
map
.
get
(
WxResponseProperties
.
ERROR_CODE
));
throw
new
BaseException
(
map
.
get
(
WxResponseProperties
.
ERR_CODE_DES
),
map
.
get
(
WxResponseProperties
.
ERROR_CODE
));
}
}
/**
/**
* 支付宝授权获取用户信息
* 支付宝授权获取用户信息
* @param code
*
* @return
* @param code
* @throws AlipayApiException
* @return
*/
* @throws AlipayApiException
public
String
getAlipayToken
(
String
code
)
throws
AlipayApiException
{
*/
AlipayClient
alipayClient
=
getAlipayClient
();
public
String
getAlipayToken
(
String
code
)
throws
AlipayApiException
{
AlipaySystemOauthTokenRequest
request
=
new
AlipaySystemOauthTokenRequest
();
AlipayClient
alipayClient
=
getAlipayClient
();
request
.
setGrantType
(
"authorization_code"
);
AlipaySystemOauthTokenRequest
request
=
new
AlipaySystemOauthTokenRequest
();
request
.
setCode
(
code
);
request
.
setGrantType
(
"authorization_code"
);
AlipaySystemOauthTokenResponse
response
=
alipayClient
.
execute
(
request
);
request
.
setCode
(
code
);
log
.
info
(
"获取用户token调用成功,获取用户信息 {}"
,
response
.
getBody
());
AlipaySystemOauthTokenResponse
response
=
alipayClient
.
execute
(
request
);
if
(
response
.
isSuccess
()){
log
.
info
(
"获取用户token调用成功,获取用户信息 {}"
,
response
.
getBody
());
log
.
info
(
"获取用户token调用成功,获取用户信息 {}"
,
response
.
getBody
());
if
(
response
.
isSuccess
())
{
if
(
response
.
getAccessToken
()
!=
null
)
{
log
.
info
(
"获取用户token调用成功,获取用户信息 {}"
,
response
.
getBody
());
AlipayUserInfoShareRequest
alipayUserInfoShareRequest
=
new
AlipayUserInfoShareRequest
();
if
(
response
.
getAccessToken
()
!=
null
)
{
AlipayUserInfoShareResponse
alipayUserInfoShareResponse
=
alipayClient
.
execute
(
alipayUserInfoShareRequest
,
response
.
getAccessToken
());
AlipayUserInfoShareRequest
alipayUserInfoShareRequest
=
new
AlipayUserInfoShareRequest
();
if
(
alipayUserInfoShareResponse
.
isSuccess
()){
AlipayUserInfoShareResponse
alipayUserInfoShareResponse
=
alipayClient
.
execute
(
alipayUserInfoShareRequest
,
response
.
getAccessToken
());
log
.
info
(
"获取用户支付宝信息调用成功, {}"
,
alipayUserInfoShareResponse
.
getBody
());
if
(
alipayUserInfoShareResponse
.
isSuccess
())
{
return
alipayUserInfoShareResponse
.
getBody
();
log
.
info
(
"获取用户支付宝信息调用成功, {}"
,
alipayUserInfoShareResponse
.
getBody
());
}
else
{
return
alipayUserInfoShareResponse
.
getBody
();
log
.
info
(
"获取用户支付宝信息调用失败, {}"
,
alipayUserInfoShareResponse
.
getBody
());
}
else
{
}
log
.
info
(
"获取用户支付宝信息调用失败, {}"
,
alipayUserInfoShareResponse
.
getBody
());
}
}
}
else
{
}
log
.
info
(
"获取用户token调用失败, {}"
,
response
.
getBody
());
}
else
{
}
log
.
info
(
"获取用户token调用失败, {}"
,
response
.
getBody
());
return
response
.
getBody
();
}
}
return
response
.
getBody
();
}
public
String
generateAliPayInfo
(
String
apiName
,
String
appName
)
{
//apiname=com.alipay.account.auth&app_id=xxxxx&app_name=mc&auth_type=AUTHACCOUNT&biz_type=openservice&method=alipay.open.auth.sdk.code.get&pid=xxxxx&product_id=APP_FAST_LOGIN&scope=kuaijie&sign_type=RSA2&target_id=20141225xxxx&sign=fMcp4GtiM6rxSIeFnJCVePJKV43eXrUP86CQgiLhDHH2u%2FdN75eEvmywc2ulkm7qKRetkU9fbVZtJIqFdMJcJ9Yp%2BJI%2FF%2FpESafFR6rB2fRjiQQLGXvxmDGVMjPSxHxVtIqpZy5FDoKUSjQ2%2FILDKpu3%2F%2BtAtm2jRw1rUoMhgt0%3D
public
String
generateAliPayInfo
(
String
apiName
,
String
appName
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
//apiname=com.alipay.account.auth&app_id=xxxxx&app_name=mc&auth_type=AUTHACCOUNT&biz_type=openservice&method=alipay.open.auth.sdk.code.get&pid=xxxxx&product_id=APP_FAST_LOGIN&scope=kuaijie&sign_type=RSA2&target_id=20141225xxxx&sign=fMcp4GtiM6rxSIeFnJCVePJKV43eXrUP86CQgiLhDHH2u%2FdN75eEvmywc2ulkm7qKRetkU9fbVZtJIqFdMJcJ9Yp%2BJI%2FF%2FpESafFR6rB2fRjiQQLGXvxmDGVMjPSxHxVtIqpZy5FDoKUSjQ2%2FILDKpu3%2F%2BtAtm2jRw1rUoMhgt0%3D
stringBuilder
.
append
(
"apiname="
);
StringBuilder
stringBuilder
=
new
StringBuilder
();
stringBuilder
.
append
(
"com.alipay.account.auth"
);
stringBuilder
.
append
(
"apiname="
);
stringBuilder
.
append
(
"&app_id="
);
stringBuilder
.
append
(
"com.alipay.account.auth"
);
stringBuilder
.
append
(
SystemConfig
.
ALIPAY_APPID
);
stringBuilder
.
append
(
"&app_id="
);
stringBuilder
.
append
(
"&app_name="
);
stringBuilder
.
append
(
SystemConfig
.
ALIPAY_APPID
);
stringBuilder
.
append
(
"mc"
);
stringBuilder
.
append
(
"&app_name="
);
stringBuilder
.
append
(
"&auth_type=AUTHACCOUNT"
);
stringBuilder
.
append
(
"mc"
);
stringBuilder
.
append
(
"&biz_type=openservice"
);
stringBuilder
.
append
(
"&auth_type=AUTHACCOUNT"
);
stringBuilder
.
append
(
"&method=alipay.open.auth.sdk.code.get"
);
stringBuilder
.
append
(
"&biz_type=openservice"
);
stringBuilder
.
append
(
"&pid="
);
stringBuilder
.
append
(
"&method=alipay.open.auth.sdk.code.get"
);
stringBuilder
.
append
(
SystemConfig
.
ALIPAY_PID
);
stringBuilder
.
append
(
"&pid="
);
stringBuilder
.
append
(
"&product_id=APP_FAST_LOGIN"
);
stringBuilder
.
append
(
SystemConfig
.
ALIPAY_PID
);
stringBuilder
.
append
(
"&scope=kuaijie"
);
stringBuilder
.
append
(
"&product_id=APP_FAST_LOGIN"
);
stringBuilder
.
append
(
"&sign_type=RSA2"
);
stringBuilder
.
append
(
"&scope=kuaijie"
);
stringBuilder
.
append
(
"&target_id="
);
stringBuilder
.
append
(
"&sign_type=RSA2"
);
stringBuilder
.
append
(
UUIDUtils
.
generateShortUuid
());
stringBuilder
.
append
(
"&target_id="
);
String
sign
=
SignUtils
.
sign
(
stringBuilder
.
toString
(),
SystemConfig
.
ALIPAY_PRIVATE_KEY
,
true
);
stringBuilder
.
append
(
UUIDUtils
.
generateShortUuid
());
stringBuilder
.
append
(
"&sign="
);
String
sign
=
SignUtils
.
sign
(
stringBuilder
.
toString
(),
SystemConfig
.
ALIPAY_PRIVATE_KEY
,
true
);
stringBuilder
.
append
(
sign
);
stringBuilder
.
append
(
"&sign="
);
return
stringBuilder
.
toString
();
stringBuilder
.
append
(
sign
);
}
return
stringBuilder
.
toString
();
}
public
String
alipayUserAuth
()
throws
AlipayApiException
{
AlipayClient
alipayClient
=
getAlipayClient
();
public
String
alipayUserAuth
()
throws
AlipayApiException
{
AlipayUserInfoAuthRequest
request
=
new
AlipayUserInfoAuthRequest
();
AlipayClient
alipayClient
=
getAlipayClient
();
request
.
setBizContent
(
"{"
+
AlipayUserInfoAuthRequest
request
=
new
AlipayUserInfoAuthRequest
();
" \"scopes\":["
+
request
.
setBizContent
(
"{"
+
" \"auth_base\""
+
" \"scopes\":["
+
" ],"
+
" \"auth_base\""
+
"\"state\":\"init\","
+
" ],"
+
"\"is_mobile\":\"true\""
+
"\"state\":\"init\","
+
" }"
);
"\"is_mobile\":\"true\""
+
AlipayUserInfoAuthResponse
response
=
alipayClient
.
execute
(
request
);
" }"
);
log
.
info
(
"解冻预授权response: {}"
+
response
.
getBody
());
AlipayUserInfoAuthResponse
response
=
alipayClient
.
execute
(
request
);
log
.
info
(
response
.
toString
());
log
.
info
(
"解冻预授权response: {}"
+
response
.
getBody
());
if
(
response
.
isSuccess
()){
log
.
info
(
response
.
toString
());
log
.
info
(
"用户授权调用成功"
);
if
(
response
.
isSuccess
())
{
}
else
{
log
.
info
(
"用户授权调用成功"
);
log
.
info
(
"用户授权调用失败"
);
}
else
{
}
log
.
info
(
"用户授权调用失败"
);
return
response
.
getBody
();
}
}
return
response
.
getBody
();
}
//解冻预授权
public
boolean
fundAuthOrderUnFreeze
(
String
outTradeNo
,
String
serialNumber
,
Integer
refundAmount
,
String
refundReason
)
throws
AlipayApiException
{
//解冻预授权
String
notifyUrl
=
weixinHost
+
"/api/universal/pay/app/unauth/notify/alipay"
;
public
boolean
fundAuthOrderUnFreeze
(
String
outTradeNo
,
String
serialNumber
,
Integer
refundAmount
,
String
refundReason
)
throws
AlipayApiException
{
AlipayClient
alipayClient
=
getAlipayClient
();
String
notifyUrl
=
weixinHost
+
"/api/universal/pay/app/unauth/notify/alipay"
;
BigDecimal
realAmount
=
new
BigDecimal
(
refundAmount
.
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
AlipayClient
alipayClient
=
getAlipayClient
();
AlipayFundAuthOrderUnfreezeRequest
request
=
new
AlipayFundAuthOrderUnfreezeRequest
();
BigDecimal
realAmount
=
new
BigDecimal
(
refundAmount
.
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
AlipayFundAuthOrderUnfreezeModel
model
=
new
AlipayFundAuthOrderUnfreezeModel
();
AlipayFundAuthOrderUnfreezeRequest
request
=
new
AlipayFundAuthOrderUnfreezeRequest
();
model
.
setAuthNo
(
serialNumber
);
// 支付宝资金授权订单号,在授权冻结成功时返回需要入库保存
AlipayFundAuthOrderUnfreezeModel
model
=
new
AlipayFundAuthOrderUnfreezeModel
();
model
.
setOutRequestNo
(
outTradeNo
);
//同一商户每次不同的资金操作请求,商户请求流水号不能重复,且与冻结流水号不同
model
.
setAuthNo
(
serialNumber
);
// 支付宝资金授权订单号,在授权冻结成功时返回需要入库保存
model
.
setAmount
(
realAmount
.
toString
());
// 本次操作解冻的金额,单位为:元(人民币),精确到小数点后两位
model
.
setOutRequestNo
(
outTradeNo
);
//同一商户每次不同的资金操作请求,商户请求流水号不能重复,且与冻结流水号不同
model
.
setRemark
(
refundReason
);
// 商户对本次解冻操作的附言描述,长度不超过100个字母或50个汉字
model
.
setAmount
(
realAmount
.
toString
());
// 本次操作解冻的金额,单位为:元(人民币),精确到小数点后两位
//选填字段,信用授权订单,针对信用全免订单,传入该值完结信用订单,形成芝麻履约记录
model
.
setRemark
(
refundReason
);
// 商户对本次解冻操作的附言描述,长度不超过100个字母或50个汉字
// model.setExtraParam("{\"unfreezeBizInfo\":\"{\\\"bizComplete\\\":\\\"true\\\"}\"}");
//选填字段,信用授权订单,针对信用全免订单,传入该值完结信用订单,形成芝麻履约记录
request
.
setBizModel
(
model
);
// model.setExtraParam("{\"unfreezeBizInfo\":\"{\\\"bizComplete\\\":\\\"true\\\"}\"}");
request
.
setBizModel
(
model
);
// request.setNotifyUrl(notifyUrl);//异步通知地址,必填,该接口只通过该参数进行异步通知
// request.setNotifyUrl(notifyUrl);//异步通知地址,必填,该接口只通过该参数进行异步通知
AlipayFundAuthOrderUnfreezeResponse
response
=
alipayClient
.
execute
(
request
);
AlipayFundAuthOrderUnfreezeResponse
response
=
alipayClient
.
execute
(
request
);
log
.
info
(
"解冻预授权response: {}"
+
response
.
getBody
());
log
.
info
(
"解冻预授权response: {}"
+
response
.
getBody
());
if
(
response
.
isSuccess
())
{
if
(
response
.
isSuccess
())
{
log
.
info
(
"解冻预授权调用成功"
);
log
.
info
(
"解冻预授权调用成功"
);
return
true
;
return
true
;
}
else
{
}
else
{
log
.
info
(
"解冻预授权调用失败"
);
log
.
info
(
"解冻预授权调用失败"
);
return
false
;
return
false
;
}
}
}
}
//取消预授权
//取消预授权
public
String
fundAuthCancel
(
String
outTradeNo
,
String
serialNumber
,
String
refundReason
)
throws
AlipayApiException
{
public
String
fundAuthCancel
(
String
outTradeNo
,
String
serialNumber
,
String
refundReason
)
throws
AlipayApiException
{
AlipayClient
alipayClient
=
getAlipayClient
();
AlipayClient
alipayClient
=
getAlipayClient
();
String
notifyUrl
=
weixinHost
+
"/api/universal/pay/app/unauth/notify/alipay"
;
String
notifyUrl
=
weixinHost
+
"/api/universal/pay/app/unauth/notify/alipay"
;
AlipayFundAuthOperationCancelRequest
request
=
new
AlipayFundAuthOperationCancelRequest
();
AlipayFundAuthOperationCancelRequest
request
=
new
AlipayFundAuthOperationCancelRequest
();
AlipayFundAuthOperationCancelModel
model
=
new
AlipayFundAuthOperationCancelModel
();
AlipayFundAuthOperationCancelModel
model
=
new
AlipayFundAuthOperationCancelModel
();
model
.
setAuthNo
(
outTradeNo
);
// 支付宝资金授权订单号,在授权冻结成功时返回参数中获得
model
.
setAuthNo
(
outTradeNo
);
// 支付宝资金授权订单号,在授权冻结成功时返回参数中获得
//model.setOutOrderNo(orderPayVo.getOrderNo()); //商户的授权资金订单号,与支付宝的授权资金订单号不能同时为空
//model.setOutOrderNo(orderPayVo.getOrderNo()); //商户的授权资金订单号,与支付宝的授权资金订单号不能同时为空
//model.setOperationId("20171201317348823902"); //支付宝的授权资金操作流水号
//model.setOperationId("20171201317348823902"); //支付宝的授权资金操作流水号
model
.
setOutRequestNo
(
serialNumber
);
//与支付宝的授权资金操作流水号不能同时为空,与冻结流水号相同
model
.
setOutRequestNo
(
serialNumber
);
//与支付宝的授权资金操作流水号不能同时为空,与冻结流水号相同
model
.
setRemark
(
refundReason
);
// 商户对本次撤销操作的附言描述,长度不超过100个字母或50个汉字
model
.
setRemark
(
refundReason
);
// 商户对本次撤销操作的附言描述,长度不超过100个字母或50个汉字
request
.
setBizModel
(
model
);
request
.
setBizModel
(
model
);
// request.setNotifyUrl(notifyUrl);//异步通知地址,必填,该接口只通过该参数进行异步通知
// request.setNotifyUrl(notifyUrl);//异步通知地址,必填,该接口只通过该参数进行异步通知
AlipayFundAuthOperationCancelResponse
response
=
alipayClient
.
execute
(
request
);
AlipayFundAuthOperationCancelResponse
response
=
alipayClient
.
execute
(
request
);
log
.
info
(
"取消预授权response: {}"
+
response
.
getBody
());
log
.
info
(
"取消预授权response: {}"
+
response
.
getBody
());
if
(
response
.
isSuccess
())
{
if
(
response
.
isSuccess
())
{
log
.
info
(
"取消预授权调用成功"
);
log
.
info
(
"取消预授权调用成功"
);
return
response
.
getBody
();
return
response
.
getBody
();
}
else
{
}
else
{
log
.
info
(
"取消预授权调用失败"
);
log
.
info
(
"取消预授权调用失败"
);
return
null
;
return
null
;
}
}
}
}
//预授权转支付
//预授权转支付
public
boolean
tradePay
(
String
outTradeNo
,
String
serialNumber
,
Integer
refundAmount
,
String
refundReason
,
String
subject
)
throws
AlipayApiException
{
public
boolean
tradePay
(
String
outTradeNo
,
String
serialNumber
,
Integer
refundAmount
,
String
refundReason
,
String
subject
)
throws
AlipayApiException
{
String
notifyUrl
=
weixinHost
+
"/api/universal/pay/app/unauth/notify/alipay"
;
String
notifyUrl
=
weixinHost
+
"/api/universal/pay/app/unauth/notify/alipay"
;
AlipayClient
alipayClient
=
getAlipayClient
();
AlipayClient
alipayClient
=
getAlipayClient
();
BigDecimal
realAmount
=
new
BigDecimal
(
refundAmount
.
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
BigDecimal
realAmount
=
new
BigDecimal
(
refundAmount
.
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
AlipayTradePayRequest
request
=
new
AlipayTradePayRequest
();
AlipayTradePayRequest
request
=
new
AlipayTradePayRequest
();
AlipayTradePayModel
model
=
new
AlipayTradePayModel
();
AlipayTradePayModel
model
=
new
AlipayTradePayModel
();
model
.
setOutTradeNo
(
outTradeNo
);
// 预授权转支付商户订单号,为新的商户交易流水号;如果重试发起扣款,商户订单号不要变;
model
.
setOutTradeNo
(
outTradeNo
);
// 预授权转支付商户订单号,为新的商户交易流水号;如果重试发起扣款,商户订单号不要变;
model
.
setProductCode
(
"PRE_AUTH_ONLINE"
);
// 固定值PRE_AUTH_ONLINE
model
.
setProductCode
(
"PRE_AUTH_ONLINE"
);
// 固定值PRE_AUTH_ONLINE
model
.
setAuthNo
(
serialNumber
);
// 填写预授权冻结交易号
model
.
setAuthNo
(
serialNumber
);
// 填写预授权冻结交易号
if
(
StringUtils
.
isNotBlank
(
subject
))
{
if
(
StringUtils
.
isNotBlank
(
subject
))
{
model
.
setSubject
(
subject
);
// 解冻转支付标题,用于展示在支付宝账单中
model
.
setSubject
(
subject
);
// 解冻转支付标题,用于展示在支付宝账单中
}
else
{
}
else
{
model
.
setSubject
(
"订单费用"
);
model
.
setSubject
(
"订单费用"
);
}
}
model
.
setTotalAmount
(
realAmount
.
toString
());
// 结算支付金额
model
.
setTotalAmount
(
realAmount
.
toString
());
// 结算支付金额
model
.
setSellerId
(
SystemConfig
.
ALIPAY_PID
);
// 填写卖家支付宝账户pid
model
.
setSellerId
(
SystemConfig
.
ALIPAY_PID
);
// 填写卖家支付宝账户pid
model
.
setBuyerId
(
SystemConfig
.
ALIPAY_APPID
);
// 填写预授权用户uid,通过预授权冻结接口返回的payer_user_id字段获取
model
.
setBuyerId
(
SystemConfig
.
ALIPAY_APPID
);
// 填写预授权用户uid,通过预授权冻结接口返回的payer_user_id字段获取
if
(
StringUtils
.
isNotBlank
(
refundReason
))
{
if
(
StringUtils
.
isNotBlank
(
refundReason
))
{
model
.
setBody
(
refundReason
);
// 可填写备注信息
model
.
setBody
(
refundReason
);
// 可填写备注信息
}
else
{
}
else
{
model
.
setBody
(
"订单费用"
);
model
.
setBody
(
"订单费用"
);
}
}
//如果需要从一笔授权中完成多笔订单支付,保持auth_no不变,不同订单根据outTradeNo进行标识,此时auth_confirm_mode不传或者传入NOT_COMPLETE;进行到最后一笔转支付时,auth_confirm_mode传入COMPLETE由支付宝完成剩余金额自动解冻,或者商户自行调用解冻接口将剩余金额解冻。
//如果需要从一笔授权中完成多笔订单支付,保持auth_no不变,不同订单根据outTradeNo进行标识,此时auth_confirm_mode不传或者传入NOT_COMPLETE;进行到最后一笔转支付时,auth_confirm_mode传入COMPLETE由支付宝完成剩余金额自动解冻,或者商户自行调用解冻接口将剩余金额解冻。
model
.
setAuthConfirmMode
(
"NOT_COMPLETE"
);
//传入该值用户剩余金额不会自动解冻
model
.
setAuthConfirmMode
(
"NOT_COMPLETE"
);
//传入该值用户剩余金额不会自动解冻
request
.
setBizModel
(
model
);
request
.
setBizModel
(
model
);
// request.setNotifyUrl(notifyUrl);//异步通知地址,必填,该接口只通过该参数进行异步通知
// request.setNotifyUrl(notifyUrl);//异步通知地址,必填,该接口只通过该参数进行异步通知
AlipayTradePayResponse
response
=
alipayClient
.
execute
(
request
);
AlipayTradePayResponse
response
=
alipayClient
.
execute
(
request
);
log
.
info
(
"预授权转支付response: {}"
+
response
.
getBody
());
log
.
info
(
"预授权转支付response: {}"
+
response
.
getBody
());
if
(
response
.
isSuccess
())
{
if
(
response
.
isSuccess
())
{
return
true
;
return
true
;
}
else
{
}
else
{
log
.
info
(
"预授权转支付调用失败"
);
log
.
info
(
"预授权转支付调用失败"
);
return
false
;
return
false
;
}
}
}
}
/**
/**
* APP支付退款
* APP支付退款
*
*
* @param
* @param
* @param outTradeNo 订单号
* @param outTradeNo 订单号
* @param tradNo 流水号
* @param tradNo 流水号
* @param refundAmount 退款金额
* @param refundAmount 退款金额
* @param refundReason 退款原因
* @param refundReason 退款原因
* outRequestNo 退款请求标示 用于分批退款,每笔退款标示不一样,同样标示不会重复退款
* outRequestNo 退款请求标示 用于分批退款,每笔退款标示不一样,同样标示不会重复退款
* @return
* @return
*/
*/
public
boolean
alipayOrderRefund
(
String
outTradeNo
,
String
tradNo
,
Integer
refundAmount
,
String
public
boolean
alipayOrderRefund
(
String
outTradeNo
,
String
tradNo
,
Integer
refundAmount
,
String
refundReason
,
String
outRequestNo
)
{
refundReason
,
String
outRequestNo
)
{
AlipayClient
alipayClient
=
getAlipayClient
();
AlipayClient
alipayClient
=
getAlipayClient
();
AlipayTradeRefundRequest
request
=
new
AlipayTradeRefundRequest
();
AlipayTradeRefundRequest
request
=
new
AlipayTradeRefundRequest
();
BigDecimal
realAmount
=
new
BigDecimal
(
refundAmount
.
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
BigDecimal
realAmount
=
new
BigDecimal
(
refundAmount
.
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
request
.
setBizContent
(
"{"
+
request
.
setBizContent
(
"{"
+
"\"out_trade_no\":\""
+
outTradeNo
+
"\","
+
"\"out_trade_no\":\""
+
outTradeNo
+
"\","
+
"\"trade_no\":\""
+
tradNo
+
"\","
+
"\"trade_no\":\""
+
tradNo
+
"\","
+
"\"refund_amount\":"
+
realAmount
+
","
+
"\"refund_amount\":"
+
realAmount
+
","
+
"\"refund_reason\":\""
+
refundReason
+
"\","
+
"\"refund_reason\":\""
+
refundReason
+
"\","
+
"\"out_request_no\":\""
+
outRequestNo
+
"\""
+
"\"out_request_no\":\""
+
outRequestNo
+
"\""
+
" }"
);
" }"
);
try
{
try
{
log
.
info
(
"支付宝退款中:outTradeNo = {}, tradNo = {}, refundAmount = {}, refundReason = {}"
,
outTradeNo
,
tradNo
,
refundAmount
,
refundReason
);
log
.
info
(
"支付宝退款中:outTradeNo = {}, tradNo = {}, refundAmount = {}, refundReason = {}"
,
outTradeNo
,
tradNo
,
refundAmount
,
refundReason
);
AlipayTradeRefundResponse
response
=
alipayClient
.
execute
(
request
);
AlipayTradeRefundResponse
response
=
alipayClient
.
execute
(
request
);
if
(
response
.
isSuccess
())
{
if
(
response
.
isSuccess
())
{
return
true
;
return
true
;
}
else
{
}
else
{
log
.
info
(
response
.
getBody
());
log
.
info
(
response
.
getBody
());
return
false
;
return
false
;
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);;
log
.
error
(
e
.
getMessage
(),
e
);
log
.
info
(
"退款失败请重试"
);
;
}
log
.
info
(
"退款失败请重试"
);
return
false
;
}
}
return
false
;
}
/**
* 查询预授权订单
/**
* @param tradNo
* 查询预授权订单
* @throws AlipayApiException
*
*/
* @param tradNo
public
ObjectRestResponse
fundAuthQuery
(
String
tradNo
){
* @throws AlipayApiException
AlipayClient
alipayClient
=
getAlipayClient
();
*/
AlipayFundAuthOperationDetailQueryRequest
request
=
new
AlipayFundAuthOperationDetailQueryRequest
();
public
ObjectRestResponse
fundAuthQuery
(
String
tradNo
)
{
AlipayFundAuthOperationDetailQueryModel
model
=
new
AlipayFundAuthOperationDetailQueryModel
();
AlipayClient
alipayClient
=
getAlipayClient
();
//model.setAuthNo("2017120110002001390206804295"); // 支付宝资金授权订单号,在授权冻结成功时返回参数中获得
AlipayFundAuthOperationDetailQueryRequest
request
=
new
AlipayFundAuthOperationDetailQueryRequest
();
model
.
setOutOrderNo
(
tradNo
);
//商户的授权资金订单号,与支付宝的授权资金订单号不能同时为空
AlipayFundAuthOperationDetailQueryModel
model
=
new
AlipayFundAuthOperationDetailQueryModel
();
//model.setOperationId("20171201317348823902"); //支付宝的授权资金操作流水号,冻结成功同步返回
//model.setAuthNo("2017120110002001390206804295"); // 支付宝资金授权订单号,在授权冻结成功时返回参数中获得
model
.
setOutRequestNo
(
tradNo
);
//商户的授权资金操作流水号,与支付宝的授权资金操作流水号不能同时为空,该值为冻结或解冻是的outRequestNo
model
.
setOutOrderNo
(
tradNo
);
//商户的授权资金订单号,与支付宝的授权资金订单号不能同时为空
request
.
setBizModel
(
model
);
//model.setOperationId("20171201317348823902"); //支付宝的授权资金操作流水号,冻结成功同步返回
AlipayFundAuthOperationDetailQueryResponse
response
=
null
;
model
.
setOutRequestNo
(
tradNo
);
//商户的授权资金操作流水号,与支付宝的授权资金操作流水号不能同时为空,该值为冻结或解冻是的outRequestNo
try
{
request
.
setBizModel
(
model
);
response
=
alipayClient
.
execute
(
request
);
AlipayFundAuthOperationDetailQueryResponse
response
=
null
;
log
.
info
(
"response: {}"
+
response
.
getBody
());
try
{
}
catch
(
AlipayApiException
e
)
{
response
=
alipayClient
.
execute
(
request
);
e
.
printStackTrace
();
log
.
info
(
"response: {}"
+
response
.
getBody
());
}
}
catch
(
AlipayApiException
e
)
{
return
ObjectRestResponse
.
succ
(
response
.
getBody
());
e
.
printStackTrace
();
}
}
return
ObjectRestResponse
.
succ
(
response
.
getBody
());
/**
}
* 预授权转支付退款
* @param tradNo 预授权转支付商户订单号
/**
* @param refundAmount 退款金额
* 预授权转支付退款
* @param refundReason 退款原因
*
* @param outRequestNo 退款标志号
* @param tradNo 预授权转支付商户订单号
*/
* @param refundAmount 退款金额
public
AlipayTradeRefundResponse
testTradeRefund
(
String
tradNo
,
Integer
refundAmount
,
String
refundReason
,
String
outRequestNo
)
{
* @param refundReason 退款原因
AlipayClient
alipayClient
=
getAlipayClient
();
* @param outRequestNo 退款标志号
AlipayTradeRefundModel
model
=
new
AlipayTradeRefundModel
();
*/
BigDecimal
realAmount
=
new
BigDecimal
(
refundAmount
.
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
public
AlipayTradeRefundResponse
testTradeRefund
(
String
tradNo
,
Integer
refundAmount
,
String
refundReason
,
String
outRequestNo
)
{
model
.
setOutTradeNo
(
tradNo
);
//与预授权转支付商户订单号相同,代表对该笔交易退款
AlipayClient
alipayClient
=
getAlipayClient
();
model
.
setRefundAmount
(
realAmount
.
toString
());
AlipayTradeRefundModel
model
=
new
AlipayTradeRefundModel
();
model
.
setRefundReason
(
refundReason
);
BigDecimal
realAmount
=
new
BigDecimal
(
refundAmount
.
toString
()).
divide
(
new
BigDecimal
(
"100"
),
2
,
BigDecimal
.
ROUND_UP
);
model
.
setOutRequestNo
(
outRequestNo
);
//标识一次退款请求,同一笔交易多次退款需要保证唯一,如部分退款则此参数必传。
model
.
setOutTradeNo
(
tradNo
);
//与预授权转支付商户订单号相同,代表对该笔交易退款
AlipayTradeRefundRequest
request
=
new
AlipayTradeRefundRequest
();
model
.
setRefundAmount
(
realAmount
.
toString
());
request
.
setBizModel
(
model
);
model
.
setRefundReason
(
refundReason
);
AlipayTradeRefundResponse
response
=
null
;
model
.
setOutRequestNo
(
outRequestNo
);
//标识一次退款请求,同一笔交易多次退款需要保证唯一,如部分退款则此参数必传。
try
{
AlipayTradeRefundRequest
request
=
new
AlipayTradeRefundRequest
();
response
=
alipayClient
.
execute
(
request
);
request
.
setBizModel
(
model
);
}
catch
(
AlipayApiException
e
)
{
AlipayTradeRefundResponse
response
=
null
;
e
.
printStackTrace
();
try
{
}
response
=
alipayClient
.
execute
(
request
);
log
.
info
(
"response: {}"
+
response
.
getBody
());
}
catch
(
AlipayApiException
e
)
{
return
response
;
e
.
printStackTrace
();
}
}
log
.
info
(
"response: {}"
+
response
.
getBody
());
public
static
void
main
(
String
[]
args
)
throws
AlipayApiException
{
return
response
;
OrderPayBiz
orderPayBiz
=
new
OrderPayBiz
();
}
OrderPayVo
orderPayVo
=
new
OrderPayVo
();
orderPayVo
.
setOrderNo
(
"20191024153859000003"
);
public
static
void
main
(
String
[]
args
)
throws
AlipayApiException
{
orderPayVo
.
setTradeNo
(
"2019102410002001530572359246"
);
OrderPayBiz
orderPayBiz
=
new
OrderPayBiz
();
orderPayVo
.
setSerialNumber
(
"2019102410002001530572351411"
);
OrderPayVo
orderPayVo
=
new
OrderPayVo
();
orderPayVo
.
setAmount
(
3
);
orderPayVo
.
setOrderNo
(
"20191024153859000003"
);
orderPayVo
.
setBody
(
"扣除租车订单费用"
);
orderPayVo
.
setTradeNo
(
"2019102410002001530572359246"
);
orderPayVo
.
setSubject
(
"租车订单交易费用"
);
orderPayVo
.
setSerialNumber
(
"2019102410002001530572351411"
);
//orderPayBiz.testTradeRefund("222522054304468992", 180000, "退还违约金1800元", "222522054304461800");
orderPayVo
.
setAmount
(
3
);
//orderPayBiz.fundAuthOrderUnFreeze(orderPayVo, "");
orderPayVo
.
setBody
(
"扣除租车订单费用"
);
//orderPayBiz.alipayOrderRefund("20191024153859000003","2019102422001421530513773694", 2, "xxxx", "");
orderPayVo
.
setSubject
(
"租车订单交易费用"
);
//orderPayBiz.tradePay(orderPayVo, "");
//orderPayBiz.testTradeRefund("222522054304468992", 180000, "退还违约金1800元", "222522054304461800");
//orderPayBiz.fundAuthCancel(orderPayVo, "");
//orderPayBiz.fundAuthOrderUnFreeze(orderPayVo, "");
//orderPayBiz.tradePay("20191114182254000019", "2019111410002001530505959461", 1,"扣除违约金", "扣除违约金");
//orderPayBiz.alipayOrderRefund("20191024153859000003","2019102422001421530513773694", 2, "xxxx", "");
//orderPayBiz.fundAuthQuery("20191031172653000026");
//orderPayBiz.tradePay(orderPayVo, "");
}
//orderPayBiz.fundAuthCancel(orderPayVo, "");
//orderPayBiz.tradePay("20191114182254000019", "2019111410002001530505959461", 1,"扣除违约金", "扣除违约金");
//orderPayBiz.fundAuthQuery("20191031172653000026");
}
}
}
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