记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
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
董敬伟
liquidnet-bus-v1
Commits
a3ef7eb2
Commit
a3ef7eb2
authored
Nov 08, 2021
by
anjiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交unionpay代码
parent
66cd5672
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
764 additions
and
1 deletion
+764
-1
DragonConstant.java
...com/liquidnet/service/dragon/constant/DragonConstant.java
+1
-1
PayChannelStrategyUnionpayImpl.java
...channel/strategy/impl/PayChannelStrategyUnionpayImpl.java
+168
-0
UnionpayBiz.java
...dnet/service/dragon/channel/unionpay/biz/UnionpayBiz.java
+191
-0
UnionpayConstant.java
...ce/dragon/channel/unionpay/constant/UnionpayConstant.java
+33
-0
UnionpayTradePayReq.java
...vice/dragon/channel/unionpay/req/UnionpayTradePayReq.java
+42
-0
IUnionpayStrategy.java
...e/dragon/channel/unionpay/strategy/IUnionpayStrategy.java
+19
-0
UnionpayStrategyContext.java
...on/channel/unionpay/strategy/UnionpayStrategyContext.java
+28
-0
UnionpayStrategyListener.java
...n/channel/unionpay/strategy/UnionpayStrategyListener.java
+32
-0
StrategyUnionpayHandler.java
...unionpay/strategy/annotation/StrategyUnionpayHandler.java
+22
-0
AbstractUnionPayStrategy.java
...nnel/unionpay/strategy/impl/AbstractUnionPayStrategy.java
+106
-0
UnionpayStrategyAppImpl.java
...annel/unionpay/strategy/impl/UnionpayStrategyAppImpl.java
+61
-0
UnionpayStrategyWapImpl.java
...annel/unionpay/strategy/impl/UnionpayStrategyWapImpl.java
+61
-0
No files found.
liquidnet-bus-api/liquidnet-service-dragon-api/src/main/java/com/liquidnet/service/dragon/constant/DragonConstant.java
View file @
a3ef7eb2
...
@@ -23,7 +23,7 @@ public class DragonConstant {
...
@@ -23,7 +23,7 @@ public class DragonConstant {
ALIPAY
(
"alipay"
,
"支付宝"
),
ALIPAY
(
"alipay"
,
"支付宝"
),
WEPAY
(
"wepay"
,
"微信"
),
WEPAY
(
"wepay"
,
"微信"
),
APPLEPAY
(
"applepay"
,
"applepay"
),
APPLEPAY
(
"applepay"
,
"applepay"
),
CLOUDPAY
(
"cloud
pay"
,
"云闪付"
);
UNIONPAY
(
"union
pay"
,
"云闪付"
);
private
String
code
;
private
String
code
;
private
String
message
;
private
String
message
;
PayChannelEnum
(
String
code
,
String
message
)
{
PayChannelEnum
(
String
code
,
String
message
)
{
...
...
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/strategy/impl/PayChannelStrategyUnionpayImpl.java
0 → 100644
View file @
a3ef7eb2
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
strategy
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alipay.api.AlipayApiException
;
import
com.alipay.api.internal.util.AlipaySignature
;
import
com.liquidnet.common.exception.LiquidnetServiceException
;
import
com.liquidnet.commons.lang.util.DateUtil
;
import
com.liquidnet.commons.lang.util.StringUtil
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.dragon.biz.DragonServiceCommonBiz
;
import
com.liquidnet.service.dragon.channel.alipay.biz.AlipayBiz
;
import
com.liquidnet.service.dragon.channel.alipay.constant.AlipayConstant
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.AlipayStrategyContext
;
import
com.liquidnet.service.dragon.channel.strategy.annotation.StrategyPayChannelHandler
;
import
com.liquidnet.service.dragon.channel.strategy.biz.DragonPayBiz
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.constant.DragonErrorCodeEnum
;
import
com.liquidnet.service.dragon.dto.DragonOrdersDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
com.liquidnet.service.dragon.dto.DragonPayOrderQueryRespDto
;
import
com.liquidnet.service.dragon.service.impl.DragonOrderRefundsServiceImpl
;
import
com.liquidnet.service.dragon.utils.DataUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.http.HttpServletRequest
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: PayChannelStrategyUnionpayImpl
* @Package com.liquidnet.service.dragon.channel.strategy.impl
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/11/08 18:06
*/
@Slf4j
@Component
@StrategyPayChannelHandler
(
DragonConstant
.
PayChannelEnum
.
UNIONPAY
)
public
class
PayChannelStrategyUnionpayImpl
extends
AbstractPayChannelStrategyImpl
{
@Autowired
private
AlipayStrategyContext
alipayStrategyContext
;
@Autowired
private
DataUtils
dataUtils
;
@Autowired
private
AlipayBiz
alipayBiz
;
@Autowired
private
DragonPayBiz
dragonPayBiz
;
@Autowired
private
DragonServiceCommonBiz
dragonServiceCommonBiz
;
@Autowired
private
DragonOrderRefundsServiceImpl
dragonOrderRefundsService
;
@Value
(
"${liquidnet.dragon.alipay.appId}"
)
private
String
appId
;
@Value
(
"${liquidnet.dragon.alipay.merchantPubKey}"
)
private
String
merchantPubKey
;
@Value
(
"${liquidnet.dragon.alipay.merchantPrivateKey}"
)
private
String
merchantPrivateKey
;
@Value
(
"${liquidnet.dragon.alipay.signtType}"
)
private
String
signtType
;
@Value
(
"${liquidnet.dragon.alipay.charset}"
)
private
String
charset
;
@Override
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
return
alipayStrategyContext
.
getStrategy
(
dragonPayBaseReqDto
.
getDeviceFrom
()).
dragonPay
(
dragonPayBaseReqDto
);
}
@Override
public
String
dragonNotify
(
HttpServletRequest
request
,
String
payType
,
String
deviceFrom
)
{
log
.
info
(
"alipay-->notify-->begin payType:{} deviceFrom:{}"
,
payType
,
deviceFrom
);
Map
<
String
,
String
[]>
requestParams
=
request
.
getParameterMap
();
Map
<
String
,
String
>
notifyMap
=
new
HashMap
<
String
,
String
>();
notifyMap
=
alipayBiz
.
parseNotifyMsg
(
requestParams
);
log
.
info
(
"dragonNotify-->alipay json : {}"
,
JSON
.
toJSONString
(
notifyMap
));
log
.
info
(
"接收到{}支付结果{}"
,
payType
,
notifyMap
);
String
returnStr
=
"fail"
;
String
code
=
notifyMap
.
get
(
"out_trade_no"
);
//持久化通知记录
dragonServiceCommonBiz
.
createDragonOrderLogs
(
code
,
dragonPayBiz
.
getPaymentType
(
payType
,
deviceFrom
),
JSON
.
toJSONString
(
notifyMap
));
//退款
if
(
notifyMap
.
containsKey
(
"refund_fee"
)
||
notifyMap
.
containsKey
(
"gmt_refund"
)
||
notifyMap
.
containsKey
(
"out_biz_no"
))
{
returnStr
=
dragonOrderRefundsService
.
aliPayRefundCallBack
(
JSON
.
toJSONString
(
notifyMap
));
return
returnStr
;
}
// 根据银行订单号获取支付信息
DragonOrdersDto
dragonOrdersDto
=
dataUtils
.
getPayOrderByCode
(
code
);
if
(
dragonOrdersDto
==
null
)
{
throw
new
LiquidnetServiceException
(
DragonErrorCodeEnum
.
TRADE_ERROR_NOT_EXISTS
.
getCode
(),
DragonErrorCodeEnum
.
TRADE_ERROR_NOT_EXISTS
.
getMessage
());
}
if
(
DragonConstant
.
PayStatusEnum
.
STATUS_PAID
.
getCode
().
equals
(
dragonOrdersDto
.
getStatus
()))
{
throw
new
LiquidnetServiceException
(
DragonErrorCodeEnum
.
TRADE_ERROR_HAS_PAID
.
getCode
(),
DragonErrorCodeEnum
.
TRADE_ERROR_HAS_PAID
.
getMessage
());
}
try
{
if
(
AlipaySignature
.
rsaCheckV1
(
notifyMap
,
merchantPubKey
,
"UTF-8"
,
"RSA2"
)){
String
tradeStatus
=
notifyMap
.
get
(
"trade_status"
);
boolean
notifyResult
=
false
;
if
(
AlipayConstant
.
AlipayTradeStateEnum
.
TRADE_SUCCESS
.
name
().
equals
(
tradeStatus
)
||
AlipayConstant
.
AlipayTradeStateEnum
.
TRADE_FINISHED
.
name
().
equals
(
tradeStatus
))
{
String
gmtPaymentStr
=
notifyMap
.
get
(
"gmt_payment"
);
// 付款时间
LocalDateTime
timeEnd
=
null
;
if
(!
StringUtil
.
isEmpty
(
gmtPaymentStr
))
{
timeEnd
=
DateUtil
.
Formatter
.
yyyyMMddHHmmss
.
parse
(
gmtPaymentStr
);
}
notifyResult
=
this
.
completeSuccessOrder
(
dragonOrdersDto
,
notifyMap
.
get
(
"trade_no"
),
timeEnd
,
notifyMap
.
toString
());
}
else
{
notifyResult
=
this
.
completeFailOrder
(
dragonOrdersDto
,
notifyMap
.
toString
());
}
if
(
notifyResult
){
returnStr
=
"success"
;
}
}
else
{
// 验证失败
log
.
error
(
"alipay notify fail code:{} msg:{} "
,
DragonErrorCodeEnum
.
TRADE_ALIPAY_SIGN_ERROR
.
getCode
(),
DragonErrorCodeEnum
.
TRADE_ALIPAY_SIGN_ERROR
.
getMessage
());
return
returnStr
;
}
}
catch
(
AlipayApiException
e
)
{
log
.
error
(
"alipay notify fail 验签失败:e:{}"
,
e
);
log
.
error
(
"alipay notify fail 验签失败:code:{} msg:{}"
,
DragonErrorCodeEnum
.
TRADE_ALIPAY_SIGN_ERROR
.
getCode
(),
DragonErrorCodeEnum
.
TRADE_ALIPAY_SIGN_ERROR
.
getMessage
());
}
log
.
info
(
"返回支付通道{}信息{}"
,
payType
,
returnStr
);
log
.
info
(
"alipay-->notify-->end payType:{} deviceFrom:{}"
,
payType
,
deviceFrom
);
return
returnStr
;
}
@Override
public
DragonPayOrderQueryRespDto
checkOrderStatus
(
String
code
)
{
DragonOrdersDto
ordersDto
=
dataUtils
.
getPayOrderByCode
(
code
);
Map
<
String
,
Object
>
resultMap
=
alipayBiz
.
tradeQuery
(
code
);
DragonPayOrderQueryRespDto
respDto
=
dragonPayBiz
.
buildPayOrderQueryRespDto
(
ordersDto
);
if
(
"10000"
.
equals
(
resultMap
.
get
(
"code"
)))
{
// 当返回状态为“TRADE_FINISHED”交易成功结束和“TRADE_SUCCESS”支付成功时更新交易状态
if
(
AlipayConstant
.
AlipayTradeStateEnum
.
TRADE_SUCCESS
.
getCode
().
equals
(
resultMap
.
get
(
"tradeStatus"
))
||
AlipayConstant
.
AlipayTradeStateEnum
.
TRADE_FINISHED
.
getCode
().
equals
(
resultMap
.
get
(
"tradeStatus"
)))
{
respDto
.
setStatus
(
Integer
.
valueOf
(
DragonConstant
.
PayStatusEnum
.
STATUS_PAID
.
getCode
()));
}
else
{
respDto
.
setStatus
(
Integer
.
valueOf
(
DragonConstant
.
PayStatusEnum
.
STATUS_PAY_FAIL
.
getCode
()));
}
// throw new LiquidnetServiceException(DragonErrorCodeEnum.TRADE_ALIPAY_QUERY_ERROR.getCode(),DragonErrorCodeEnum.TRADE_ALIPAY_QUERY_ERROR.getMessage());
}
else
if
(
"40004"
.
equals
(
resultMap
.
get
(
"code"
))&&
"ACQ.TRADE_NOT_EXIST"
.
equalsIgnoreCase
(
resultMap
.
get
(
"subCode"
).
toString
())){
respDto
.
setStatus
(
Integer
.
valueOf
(
DragonConstant
.
PayStatusEnum
.
STATUS_UNPAID
.
getCode
()));
}
else
{
throw
new
LiquidnetServiceException
(
DragonErrorCodeEnum
.
TRADE_ALIPAY_QUERY_ERROR
.
getCode
(),
DragonErrorCodeEnum
.
TRADE_ALIPAY_QUERY_ERROR
.
getMessage
());
}
return
respDto
;
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/biz/UnionpayBiz.java
0 → 100644
View file @
a3ef7eb2
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
unionpay
.
biz
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alipay.api.AlipayApiException
;
import
com.alipay.api.AlipayClient
;
import
com.alipay.api.request.AlipayTradeAppPayRequest
;
import
com.alipay.api.request.AlipayTradeQueryRequest
;
import
com.alipay.api.request.AlipayTradeWapPayRequest
;
import
com.alipay.api.response.AlipayTradeAppPayResponse
;
import
com.alipay.api.response.AlipayTradeQueryResponse
;
import
com.alipay.api.response.AlipayTradeWapPayResponse
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.liquidnet.commons.lang.util.JsonUtils
;
import
com.liquidnet.commons.lang.util.StringUtil
;
import
com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq
;
import
com.liquidnet.service.dragon.channel.alipay.sign.MD5
;
import
com.liquidnet.service.dragon.utils.ObjectUtil
;
import
com.liquidnet.service.dragon.utils.PayAlipayUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
java.util.*
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: UnionpayBiz
* @Package com.liquidnet.service.dragon.channel.unionpay.biz
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/11/08 18:21
*/
@Slf4j
@Component
public
class
UnionpayBiz
{
/**
* tradeWapPay
* @param alipayTradePayReq
* @return
*/
public
static
Map
<
String
,
Object
>
tradeWapPay
(
AlipayTradePayReq
alipayTradePayReq
)
{
log
.
info
(
"AlipayBiz.tradeWapPay-->> req : {}"
,
alipayTradePayReq
.
toString
());
String
timeExpress
=
"5m"
;
// 支付超时,线下扫码交易定义为5分钟
AlipayClient
alipayClient
=
PayAlipayUtils
.
getInstance
().
getHttpClient
();
SortedMap
<
String
,
Object
>
paramMap
=
new
TreeMap
<>();
paramMap
.
put
(
"product_code"
,
alipayTradePayReq
.
getProductCode
());
paramMap
.
put
(
"total_amount"
,
alipayTradePayReq
.
getTotalAmount
().
toString
());
paramMap
.
put
(
"subject"
,
alipayTradePayReq
.
getSubject
());
paramMap
.
put
(
"body"
,
alipayTradePayReq
.
getBody
());
paramMap
.
put
(
"out_trade_no"
,
alipayTradePayReq
.
getOutTradeNo
());
paramMap
.
put
(
"timeout_express"
,
timeExpress
);
AlipayTradeWapPayRequest
request
=
new
AlipayTradeWapPayRequest
();
request
.
setNotifyUrl
(
alipayTradePayReq
.
getNotifyUrl
());
// request.setTimestamp(DateUtil.now());
log
.
info
(
"bizContent :{}"
,
JsonUtils
.
toJson
(
paramMap
));
request
.
setBizContent
(
JsonUtils
.
toJson
(
paramMap
));
try
{
long
startTime
=
System
.
currentTimeMillis
();
AlipayTradeWapPayResponse
response
=
alipayClient
.
sdkExecute
(
request
);
// AlipayTradeWapPayResponse response = new AlipayTradeWapPayResponse();
log
.
info
(
"alipay-alipayClient.sdkExecut->耗时:{}"
,(
System
.
currentTimeMillis
()
-
startTime
)+
"毫秒"
);
// Map<String,Object> responseJSON = JsonUtils.OM().convertValue(response,Map.class);
startTime
=
System
.
currentTimeMillis
();
Map
<
String
,
Object
>
responseJSON
=
ObjectUtil
.
cloneHashMapStringAndObj
();
log
.
info
(
"AlipayUtil-->tradeWapPay-->cloneHashMapStringAndObj 耗时:{}"
,(
System
.
currentTimeMillis
()
-
startTime
)+
"毫秒"
);
responseJSON
.
put
(
"code"
,
response
.
getCode
());
responseJSON
.
put
(
"msg"
,
response
.
getMsg
());
responseJSON
.
put
(
"subCode"
,
response
.
getSubCode
());
responseJSON
.
put
(
"subMsg"
,
response
.
getSubMsg
());
responseJSON
.
put
(
"body"
,
response
.
getBody
());
responseJSON
.
put
(
"merchantOrderNo"
,
response
.
getMerchantOrderNo
());
responseJSON
.
put
(
"outTradeNo"
,
response
.
getOutTradeNo
());
responseJSON
.
put
(
"sellerId"
,
response
.
getSellerId
());
responseJSON
.
put
(
"totalAmount"
,
response
.
getTotalAmount
());
responseJSON
.
put
(
"tradeNo"
,
response
.
getTradeNo
());
startTime
=
System
.
currentTimeMillis
();
// log.info("AlipayUtil-->tradeWapPay-->支付宝返回结果:{}", JsonUtils.toJson(response));
log
.
info
(
"AlipayUtil-->tradeWapPay-->支付宝返回结果 耗时:{}"
,(
System
.
currentTimeMillis
()
-
startTime
)+
"毫秒"
);
return
responseJSON
;
}
catch
(
Exception
e
)
{
log
.
error
(
"支付宝支付异常:{}"
,
e
);
JSONObject
resultJSON
=
ObjectUtil
.
cloneJsonObjectObj
();
resultJSON
.
put
(
"outTradeNo"
,
alipayTradePayReq
.
getOutTradeNo
());
resultJSON
.
put
(
"totalAmount"
,
alipayTradePayReq
.
getTotalAmount
().
toString
());
resultJSON
.
put
(
"errorCode"
,
"9999"
);
return
resultJSON
;
}
}
/**
* 支付宝支付
* @param alipayTradePayReq
* @return
*/
public
static
Map
<
String
,
Object
>
tradeAppPay
(
AlipayTradePayReq
alipayTradePayReq
)
{
log
.
info
(
"AlipayUtil.tradeAppPay-->> req : {}"
,
alipayTradePayReq
.
toString
());
String
timeExpress
=
"5m"
;
// 支付超时,线下扫码交易定义为5分钟
AlipayClient
alipayClient
=
PayAlipayUtils
.
getInstance
().
getHttpClient
();
SortedMap
<
String
,
Object
>
paramMap
=
new
TreeMap
<>();
paramMap
.
put
(
"product_code"
,
alipayTradePayReq
.
getProductCode
());
paramMap
.
put
(
"total_amount"
,
alipayTradePayReq
.
getTotalAmount
().
toString
());
paramMap
.
put
(
"subject"
,
alipayTradePayReq
.
getSubject
());
paramMap
.
put
(
"body"
,
alipayTradePayReq
.
getBody
());
paramMap
.
put
(
"out_trade_no"
,
alipayTradePayReq
.
getOutTradeNo
());
paramMap
.
put
(
"timeout_express"
,
timeExpress
);
AlipayTradeAppPayRequest
request
=
new
AlipayTradeAppPayRequest
();
request
.
setNotifyUrl
(
alipayTradePayReq
.
getNotifyUrl
());
// request.setTimestamp(DateUtil.now());
log
.
info
(
"bizContent :{}"
,
JSONObject
.
toJSONString
(
paramMap
));
request
.
setBizContent
(
JSONObject
.
toJSONString
(
paramMap
));
try
{
AlipayTradeAppPayResponse
response
=
alipayClient
.
sdkExecute
(
request
);
// JSONObject responseJSON = JSONObject.parseObject(JSONObject.toJSONString(response));
Map
<
String
,
Object
>
responseJSON
=
JsonUtils
.
fromJson
(
JsonUtils
.
toJson
(
response
),
new
TypeReference
<
Map
<
String
,
Object
>>()
{
});
log
.
info
(
"AlipayUtil-->tradeAppPay-->支付宝返回结果:{}"
,
responseJSON
);
return
responseJSON
;
}
catch
(
AlipayApiException
e
)
{
log
.
error
(
"支付宝支付异常:{}"
,
e
);
JSONObject
resultJSON
=
new
JSONObject
();
resultJSON
.
put
(
"outTradeNo"
,
alipayTradePayReq
.
getOutTradeNo
());
resultJSON
.
put
(
"totalAmount"
,
alipayTradePayReq
.
getTotalAmount
().
toString
());
resultJSON
.
put
(
"errorCode"
,
"9999"
);
return
resultJSON
;
}
}
/**
* 订单查询
*
* @return
*/
public
static
Map
<
String
,
Object
>
tradeQuery
(
String
outTradeNo
)
{
log
.
info
(
"AlipayBiz.tradeQuery-->> 支付宝交易查询"
);
AlipayClient
alipayClient
=
PayAlipayUtils
.
getInstance
().
getHttpClient
();
SortedMap
<
String
,
Object
>
bizContentMap
=
new
TreeMap
<>();
bizContentMap
.
put
(
"out_trade_no"
,
outTradeNo
);
AlipayTradeQueryRequest
request
=
new
AlipayTradeQueryRequest
();
request
.
setBizContent
(
JSONObject
.
toJSONString
(
bizContentMap
));
try
{
AlipayTradeQueryResponse
response
=
alipayClient
.
execute
(
request
);
JSONObject
responseJSON
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
response
));
log
.
info
(
"支付宝订单查询返回结果:{}"
,
responseJSON
);
return
responseJSON
;
}
catch
(
AlipayApiException
e
)
{
log
.
error
(
"支付宝交易查询异常:{}"
,
e
);
return
null
;
}
}
private
static
String
getSign
(
SortedMap
<
String
,
String
>
paramMap
,
String
key
)
{
StringBuilder
signBuilder
=
new
StringBuilder
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
paramMap
.
entrySet
())
{
if
(!
"sign"
.
equals
(
entry
.
getKey
())
&&
!
"sign_type"
.
equals
(
entry
.
getKey
())
&&
!
StringUtil
.
isEmpty
(
entry
.
getValue
()))
{
signBuilder
.
append
(
entry
.
getKey
()).
append
(
"="
).
append
(
entry
.
getValue
()).
append
(
"&"
);
}
}
return
MD5
.
sign
(
signBuilder
.
substring
(
0
,
signBuilder
.
length
()
-
1
),
key
,
"UTF-8"
);
}
public
static
Map
<
String
,
String
>
parseNotifyMsg
(
Map
<
String
,
String
[]>
requestParams
){
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
for
(
Iterator
iter
=
requestParams
.
keySet
().
iterator
();
iter
.
hasNext
();)
{
String
name
=
(
String
)
iter
.
next
();
String
[]
values
=
requestParams
.
get
(
name
);
String
valueStr
=
""
;
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
valueStr
=
(
i
==
values
.
length
-
1
)
?
valueStr
+
values
[
i
]
:
valueStr
+
values
[
i
]
+
","
;
}
params
.
put
(
name
,
valueStr
);
}
return
params
;
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/constant/UnionpayConstant.java
0 → 100644
View file @
a3ef7eb2
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
unionpay
.
constant
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: UnionpayConstant
* @Package com.liquidnet.service.dragon.channel.unionpay.constant
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/11/8 18:12
*/
public
class
UnionpayConstant
{
public
enum
UnionpayTradeStateEnum
{
TRADE_CLOSED
(
"TRADE_CLOSED"
,
"交易关闭"
),
TRADE_FINISHED
(
"TRADE_FINISHED"
,
"支付完成"
),
TRADE_SUCCESS
(
"TRADE_SUCCESS"
,
"支付成功"
),
WAIT_BUYER_PAY
(
"WAIT_BUYER_PAY"
,
"交易创建"
),
FAIL
(
""
,
"支付失败"
);
private
String
code
;
private
String
message
;
UnionpayTradeStateEnum
(
String
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
}
public
String
getCode
()
{
return
code
;
}
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/req/UnionpayTradePayReq.java
0 → 100644
View file @
a3ef7eb2
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
unionpay
.
req
;
import
com.alibaba.fastjson.JSON
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.math.BigDecimal
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AlipayTradePayReq
* @Package com.liquidnet.service.dragon.channel.alipay.req
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/9 17:50
*/
@Data
public
class
UnionpayTradePayReq
implements
Serializable
,
Cloneable
{
private
static
final
long
serialVersionUID
=
-
5827961038383330701L
;
private
String
productCode
;
private
BigDecimal
totalAmount
;
private
String
subject
;
private
String
body
;
private
String
outTradeNo
;
private
String
timeExpire
;
private
String
notifyUrl
;
private
String
timestamp
;
@Override
public
String
toString
(){
return
JSON
.
toJSONString
(
this
);
}
private
static
final
UnionpayTradePayReq
obj
=
new
UnionpayTradePayReq
();
public
static
UnionpayTradePayReq
getNew
()
{
try
{
return
(
UnionpayTradePayReq
)
obj
.
clone
();
}
catch
(
CloneNotSupportedException
e
)
{
return
new
UnionpayTradePayReq
();
}
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/strategy/IUnionpayStrategy.java
0 → 100644
View file @
a3ef7eb2
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
unionpay
.
strategy
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: Test
* @Package com.liquidnet.service.dragon.channel.strategy
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:27
*/
public
interface
IUnionpayStrategy
{
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
);
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/strategy/UnionpayStrategyContext.java
0 → 100644
View file @
a3ef7eb2
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
unionpay
.
strategy
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: Test
* @Package com.liquidnet.service.dragon.channel.strategy
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:27
*/
@Component
public
class
UnionpayStrategyContext
{
private
final
Map
<
String
,
IUnionpayStrategy
>
handlerMap
=
new
HashMap
<>();
public
IUnionpayStrategy
getStrategy
(
String
type
)
{
return
handlerMap
.
get
(
type
);
}
public
void
putStrategy
(
String
code
,
IUnionpayStrategy
strategy
)
{
handlerMap
.
put
(
code
,
strategy
);
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/strategy/UnionpayStrategyListener.java
0 → 100644
View file @
a3ef7eb2
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
unionpay
.
strategy
;
import
com.liquidnet.service.dragon.channel.unionpay.strategy.annotation.StrategyUnionpayHandler
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: Test
* @Package com.liquidnet.service.dragon.channel.strategy
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:27
*/
@Component
public
class
UnionpayStrategyListener
implements
ApplicationListener
<
ContextRefreshedEvent
>
{
@Override
public
void
onApplicationEvent
(
ContextRefreshedEvent
event
)
{
Map
<
String
,
Object
>
beans
=
event
.
getApplicationContext
().
getBeansWithAnnotation
(
StrategyUnionpayHandler
.
class
);
UnionpayStrategyContext
strategyContext
=
event
.
getApplicationContext
().
getBean
(
UnionpayStrategyContext
.
class
);
beans
.
forEach
((
name
,
bean
)
->
{
StrategyUnionpayHandler
typeHandler
=
bean
.
getClass
().
getAnnotation
(
StrategyUnionpayHandler
.
class
);
strategyContext
.
putStrategy
(
typeHandler
.
value
().
getCode
(),
(
IUnionpayStrategy
)
bean
);
});
}
}
\ No newline at end of file
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/strategy/annotation/StrategyUnionpayHandler.java
0 → 100644
View file @
a3ef7eb2
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
unionpay
.
strategy
.
annotation
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
java.lang.annotation.*
;
/**
* @author AnJiabin <jiabin.an@lightnet.io>
* @version V1.0
* @Description: TODO
* @class: StrategyUnionpayHandler
* @Package com.liquidnet.service.dragon.channel.unionpay.strategy.annotation
* @Copyright: LightNet @ Copyright (c) 2020
* @date 2020/11/08 15:29
*/
@Documented
@Inherited
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
StrategyUnionpayHandler
{
DragonConstant
.
DeviceFromEnum
value
();
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/strategy/impl/AbstractUnionPayStrategy.java
0 → 100644
View file @
a3ef7eb2
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
unionpay
.
strategy
.
impl
;
import
com.liquidnet.commons.lang.util.DateUtil
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.dragon.biz.DragonServiceCommonBiz
;
import
com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq
;
import
com.liquidnet.service.dragon.channel.strategy.biz.DragonPayBiz
;
import
com.liquidnet.service.dragon.channel.unionpay.strategy.IUnionpayStrategy
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.Map
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AbstractUnionPayStrategy
* @Package com.liquidnet.service.dragon.channel.unionpay.strategy.impl
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/11/08 18:36
*/
@Slf4j
public
abstract
class
AbstractUnionPayStrategy
implements
IUnionpayStrategy
{
@Autowired
private
DragonPayBiz
dragonPayBiz
;
@Autowired
private
DragonServiceCommonBiz
dragonServiceCommonBiz
;
protected
String
productCode
=
"QUICK_WAP_PAY"
;
@Override
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
//设置productCode
setProductCode
();
AlipayTradePayReq
alipayTradePayReq
=
AlipayTradePayReq
.
getNew
();
alipayTradePayReq
.
setProductCode
(
this
.
productCode
);
alipayTradePayReq
.
setTotalAmount
(
dragonPayBaseReqDto
.
getPrice
());
alipayTradePayReq
.
setSubject
(
dragonPayBaseReqDto
.
getName
());
alipayTradePayReq
.
setBody
(
dragonPayBaseReqDto
.
getDetail
());
//dragon中支付编号
alipayTradePayReq
.
setOutTradeNo
(
dragonPayBaseReqDto
.
getCode
());
//设置订单过期时间
String
timeExpire
=
DateUtil
.
format
(
DateUtil
.
Formatter
.
yyyyMMddHHmmss
.
parse
(
dragonPayBaseReqDto
.
getCreateDate
()).
plusMinutes
(
Long
.
parseLong
(
dragonPayBaseReqDto
.
getExpireTime
())),
DateUtil
.
Formatter
.
yyyyMMddHHmmss
);
alipayTradePayReq
.
setTimeExpire
(
timeExpire
);
alipayTradePayReq
.
setNotifyUrl
(
this
.
getNotifyUrl
());
alipayTradePayReq
.
setTimestamp
(
dragonPayBaseReqDto
.
getCreateDate
());
//调用支付
long
startTime
=
System
.
currentTimeMillis
();
Map
<
String
,
Object
>
result
=
this
.
executePay
(
alipayTradePayReq
);
// log.info("dragonPay:alipay:"+dragonPayBaseReqDto.getDeviceFrom()+" response xmlStr: {} ", JSON.toJSONString(result));
log
.
info
(
"alipay-dragonPay->耗时:{}"
,(
System
.
currentTimeMillis
()
-
startTime
)+
"毫秒"
);
//拼接返回参数
DragonPayBaseRespDto
respDto
=
buildCommonRespDto
(
dragonPayBaseReqDto
);
respDto
=
this
.
buildResponseDto
(
respDto
,
result
);
//支付订单持久化
dragonServiceCommonBiz
.
buildPayOrders
(
dragonPayBaseReqDto
,
null
);
return
ResponseDto
.
success
(
respDto
);
}
/**
* 支付请求
* @param alipayTradePayReq
* @return
*/
protected
abstract
Map
<
String
,
Object
>
executePay
(
AlipayTradePayReq
alipayTradePayReq
);
/**
* 设置productCode
*/
protected
abstract
void
setProductCode
();
/**
* 设置notifyUrl
*/
protected
abstract
String
getNotifyUrl
();
/**
* 构造公共返回参数
* @param dragonPayBaseReqDto
* @return
*/
protected
DragonPayBaseRespDto
buildCommonRespDto
(
DragonPayBaseReqDto
dragonPayBaseReqDto
){
DragonPayBaseRespDto
respDto
=
new
DragonPayBaseRespDto
();
respDto
.
setCode
(
dragonPayBaseReqDto
.
getCode
());
respDto
.
setOrderCode
(
dragonPayBaseReqDto
.
getOrderCode
());
DragonPayBaseRespDto
.
PayData
payData
=
new
DragonPayBaseRespDto
.
PayData
();
respDto
.
setPayData
(
payData
);
return
respDto
;
}
/**
* 构造返回参数
*/
abstract
DragonPayBaseRespDto
buildResponseDto
(
DragonPayBaseRespDto
payBaseRespDto
,
Map
<
String
,
Object
>
respResult
);
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/strategy/impl/UnionpayStrategyAppImpl.java
0 → 100644
View file @
a3ef7eb2
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
unionpay
.
strategy
.
impl
;
import
com.liquidnet.service.dragon.channel.alipay.biz.AlipayBiz
;
import
com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq
;
import
com.liquidnet.service.dragon.channel.unionpay.strategy.annotation.StrategyUnionpayHandler
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AlipayStrategyWapImpl
* @Package com.liquidnet.service.dragon.channel.unionpay.strategy.impl
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/11/08 18:34
*/
@Slf4j
@Component
@StrategyUnionpayHandler
(
DragonConstant
.
DeviceFromEnum
.
APP
)
public
class
UnionpayStrategyAppImpl
extends
AbstractUnionPayStrategy
{
@Value
(
"${liquidnet.dragon.alipay.gataway-url}"
)
private
String
alipayGatewayUrl
;
@Value
(
"${liquidnet.dragon.url}"
)
private
String
notifyUrl
;
@Autowired
StringRedisTemplate
stringRedisTemplate
;
@Autowired
private
AlipayBiz
alipayBiz
;
@Override
protected
Map
<
String
,
Object
>
executePay
(
AlipayTradePayReq
alipayTradePayReq
)
{
return
alipayBiz
.
tradeAppPay
(
alipayTradePayReq
);
}
protected
void
setProductCode
()
{
this
.
productCode
=
"QUICK_MSECURITY_PAY"
;
}
@Override
protected
String
getNotifyUrl
()
{
// notifyUrl = "/notify/app/alipay/1";
return
notifyUrl
+
"/notify/alipay/app"
;
}
@Override
DragonPayBaseRespDto
buildResponseDto
(
DragonPayBaseRespDto
payBaseRespDto
,
Map
<
String
,
Object
>
respResult
)
{
payBaseRespDto
.
getPayData
().
setOrderStr
(
respResult
.
get
(
"body"
).
toString
());
return
payBaseRespDto
;
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/unionpay/strategy/impl/UnionpayStrategyWapImpl.java
0 → 100644
View file @
a3ef7eb2
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
unionpay
.
strategy
.
impl
;
import
com.liquidnet.service.dragon.channel.alipay.biz.AlipayBiz
;
import
com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq
;
import
com.liquidnet.service.dragon.channel.unionpay.strategy.annotation.StrategyUnionpayHandler
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AlipayStrategyWapImpl
* @Package com.liquidnet.service.dragon.channel.alipay.strategy.impl
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:34
*/
@Slf4j
@Service
@StrategyUnionpayHandler
(
DragonConstant
.
DeviceFromEnum
.
WAP
)
public
class
UnionpayStrategyWapImpl
extends
AbstractUnionPayStrategy
{
@Value
(
"${liquidnet.dragon.alipay.gataway-url}"
)
private
String
alipayGatewayUrl
;
@Value
(
"${liquidnet.dragon.url}"
)
private
String
notifyUrl
;
@Autowired
StringRedisTemplate
stringRedisTemplate
;
@Autowired
private
AlipayBiz
alipayBiz
;
@Override
protected
Map
<
String
,
Object
>
executePay
(
AlipayTradePayReq
alipayTradePayReq
)
{
return
alipayBiz
.
tradeWapPay
(
alipayTradePayReq
);
}
protected
void
setProductCode
()
{
this
.
productCode
=
"QUICK_WAP_PAY"
;
}
@Override
protected
String
getNotifyUrl
()
{
// notifyUrl = "/notify/wap/alipay/1";
return
notifyUrl
+
"/notify/alipay/wap"
;
}
@Override
DragonPayBaseRespDto
buildResponseDto
(
DragonPayBaseRespDto
payBaseRespDto
,
Map
<
String
,
Object
>
respResult
)
{
payBaseRespDto
.
getPayData
().
setRedirectUrl
(
alipayGatewayUrl
+
"?"
+
respResult
.
get
(
"body"
));
return
payBaseRespDto
;
}
}
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