记得上下班打卡 | 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
37864a81
Commit
37864a81
authored
Jul 11, 2021
by
anjiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交微信支付
parent
2ddb4997
Changes
27
Show whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
1557 additions
and
203 deletions
+1557
-203
DragonPayBaseReqDto.java
...com/liquidnet/service/dragon/dto/DragonPayBaseReqDto.java
+3
-0
DragonPayBaseRespDto.java
...om/liquidnet/service/dragon/dto/DragonPayBaseRespDto.java
+1
-1
IDragonOrdersService.java
...iquidnet/service/dragon/service/IDragonOrdersService.java
+1
-1
liquidnet-service-dragon-dev.yml
...-config/liquidnet-config/liquidnet-service-dragon-dev.yml
+10
-1
AlipayBiz.java
...iquidnet/service/dragon/channel/alipay/biz/AlipayBiz.java
+59
-0
AlipayStrategyAppImpl.java
...n/channel/alipay/strategy/impl/AlipayStrategyAppImpl.java
+38
-1
AlipayStrategyWapImpl.java
...n/channel/alipay/strategy/impl/AlipayStrategyWapImpl.java
+40
-2
AlipayStrategyWebImpl.java
...n/channel/alipay/strategy/impl/AlipayStrategyWebImpl.java
+37
-1
AlipayUtil.java
...uidnet/service/dragon/channel/alipay/util/AlipayUtil.java
+2
-41
PayChannelStrategyAlipayImpl.java
...n/channel/strategy/impl/PayChannelStrategyAlipayImpl.java
+5
-4
PayChannelStrategyWepayImpl.java
...on/channel/strategy/impl/PayChannelStrategyWepayImpl.java
+6
-1
WepayBiz.java
.../liquidnet/service/dragon/channel/wepay/biz/WepayBiz.java
+41
-0
WeixinConfigUtil.java
...service/dragon/channel/wepay/config/WeixinConfigUtil.java
+82
-0
WepayPrePayReq.java
...dnet/service/dragon/channel/wepay/req/WepayPrePayReq.java
+238
-0
IWepayStrategy.java
...service/dragon/channel/wepay/strategy/IWepayStrategy.java
+19
-0
WepayStrategyContext.java
...e/dragon/channel/wepay/strategy/WepayStrategyContext.java
+28
-0
WepayStrategyListener.java
.../dragon/channel/wepay/strategy/WepayStrategyListener.java
+32
-0
StrategyWepayHandler.java
...annel/wepay/strategy/annotation/StrategyWepayHandler.java
+22
-0
AbstractWepayStrategy.java
...on/channel/wepay/strategy/impl/AbstractWepayStrategy.java
+71
-0
WepayStrategyAppImpl.java
...gon/channel/wepay/strategy/impl/WepayStrategyAppImpl.java
+41
-0
WepayStrategyJsImpl.java
...agon/channel/wepay/strategy/impl/WepayStrategyJsImpl.java
+41
-0
WepayStrategyWapImpl.java
...gon/channel/wepay/strategy/impl/WepayStrategyWapImpl.java
+57
-0
MD5Util.java
.../liquidnet/service/dragon/channel/wepay/util/MD5Util.java
+70
-0
WepayUtil.java
...iquidnet/service/dragon/channel/wepay/util/WepayUtil.java
+459
-1
PayController.java
...om/liquidnet/service/dragon/controller/PayController.java
+94
-61
DragonOrdersServiceImpl.java
.../service/dragon/service/impl/DragonOrdersServiceImpl.java
+8
-88
MqHandleUtil.java
...java/com/liquidnet/service/dragon/utils/MqHandleUtil.java
+52
-0
No files found.
liquidnet-bus-api/liquidnet-service-dragon-api/src/main/java/com/liquidnet/service/dragon/dto/DragonPayBaseReqDto.java
View file @
37864a81
...
@@ -17,6 +17,9 @@ import java.math.BigDecimal;
...
@@ -17,6 +17,9 @@ import java.math.BigDecimal;
*/
*/
@Data
@Data
public
class
DragonPayBaseReqDto
{
public
class
DragonPayBaseReqDto
{
private
String
payType
;
private
String
deviceFrom
;
private
String
openId
;
private
String
type
;
private
String
type
;
private
BigDecimal
price
;
private
BigDecimal
price
;
private
String
name
;
private
String
name
;
...
...
liquidnet-bus-api/liquidnet-service-dragon-api/src/main/java/com/liquidnet/service/dragon/dto/DragonPayBaseRespDto.java
View file @
37864a81
...
@@ -30,7 +30,7 @@ public class DragonPayBaseRespDto {
...
@@ -30,7 +30,7 @@ public class DragonPayBaseRespDto {
private
BigDecimal
price
;
private
BigDecimal
price
;
private
PayData
pay
_d
ata
;
private
PayData
pay
D
ata
;
public
static
class
PayData
{
public
static
class
PayData
{
@JsonProperty
(
"appId"
)
@JsonProperty
(
"appId"
)
...
...
liquidnet-bus-api/liquidnet-service-dragon-api/src/main/java/com/liquidnet/service/dragon/service/IDragonOrdersService.java
View file @
37864a81
...
@@ -10,5 +10,5 @@ import java.math.BigDecimal;
...
@@ -10,5 +10,5 @@ import java.math.BigDecimal;
public
interface
IDragonOrdersService
{
public
interface
IDragonOrdersService
{
void
sendRedisQueue
();
void
sendRedisQueue
();
ResponseDto
<
DragonPayBaseRespDto
>
alip
ay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
);
ResponseDto
<
DragonPayBaseRespDto
>
dragonP
ay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
);
}
}
liquidnet-bus-config/liquidnet-config/liquidnet-service-dragon-dev.yml
View file @
37864a81
...
@@ -23,4 +23,13 @@ liquidnet:
...
@@ -23,4 +23,13 @@ liquidnet:
sslEnabled
:
false
sslEnabled
:
false
database
:
dev_ln_scene
database
:
dev_ln_scene
dragon
:
dragon
:
alipay-gataway-url
:
https://openapi.alipay.com/gateway.do
alipay
:
gataway-url
:
https://openapi.alipay.com/gateway.do
notify-url
:
https://testpay.zhengzai.tv/alipay
wepay
:
gataway-url
:
https://openapi.alipay.com/gateway.do
notify-url
:
https://testpay.zhengzai.tv/wepay
merchantId
:
1551961491
appId
:
wx3498304dda39c5a1
parentKey
:
itIuO65O9yKmemOu3S8g1S4orqvCGwXK
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/alipay/biz/AlipayBiz.java
0 → 100644
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
alipay
.
biz
;
import
com.liquidnet.service.base.SqlMapping
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
com.liquidnet.service.dragon.entity.DragonOrders
;
import
com.liquidnet.service.dragon.utils.MqHandleUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.time.LocalDateTime
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AlipayBiz
* @Package com.liquidnet.service.dragon.channel.alipay.biz
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 16:21
*/
@Component
public
class
AlipayBiz
{
@Autowired
private
MqHandleUtil
mqHandleUtil
;
public
DragonOrders
buildPayOrders
(
DragonPayBaseReqDto
dragonPayBaseReqDto
,
DragonPayBaseRespDto
respDto
){
DragonOrders
orders
=
new
DragonOrders
();
// orders.setMid();
orders
.
setStatus
(
Integer
.
valueOf
(
DragonConstant
.
PayStatusEnum
.
STATUS_UNPAID
.
getCode
()));
orders
.
setCode
(
respDto
.
getCode
());
orders
.
setType
(
dragonPayBaseReqDto
.
getType
());
orders
.
setPrice
(
dragonPayBaseReqDto
.
getPrice
());
orders
.
setName
(
dragonPayBaseReqDto
.
getName
());
orders
.
setDetail
(
dragonPayBaseReqDto
.
getDetail
());
orders
.
setOrderCode
(
dragonPayBaseReqDto
.
getOrderCode
());
orders
.
setClientIp
(
dragonPayBaseReqDto
.
getClientIp
());
orders
.
setNotifyUrl
(
dragonPayBaseReqDto
.
getNotifyUrl
());
orders
.
setPaymentType
(
DragonConstant
.
PayTypeEnum
.
PAYMENT_TYPE_APP_IAP
.
getCode
());
// orders.setPaymentId();
orders
.
setPaymentAt
(
LocalDateTime
.
now
());
// orders.setFinishedAt();
orders
.
setCreatedAt
(
LocalDateTime
.
now
());
// orders.setUpdatedAt();
// 修改退款订单
boolean
insertResult
=
mqHandleUtil
.
sendMySqlRedis
(
SqlMapping
.
get
(
"dragon_orders.insert"
),
new
Object
[]{
orders
.
getStatus
(),
orders
.
getCode
(),
orders
.
getType
()
,
orders
.
getPrice
(),
orders
.
getName
(),
orders
.
getDetail
()
,
orders
.
getOrderCode
(),
orders
.
getClientIp
()
,
orders
.
getNotifyUrl
(),
orders
.
getPaymentType
(),
orders
.
getPaymentId
(),
orders
.
getPaymentAt
()
,
orders
.
getFinishedAt
(),
orders
.
getCreatedAt
()
,
orders
.
getUpdatedAt
()}
);
return
orders
;
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/alipay/strategy/impl/AlipayStrategyAppImpl.java
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
alipay
.
strategy
.
impl
;
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
alipay
.
strategy
.
impl
;
import
com.liquidnet.commons.lang.util.IDGenerator
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.dragon.channel.alipay.biz.AlipayBiz
;
import
com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.IAlipayStrategy
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.IAlipayStrategy
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler
;
import
com.liquidnet.service.dragon.channel.alipay.util.AlipayUtil
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
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
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @version V1.0
...
@@ -20,8 +29,36 @@ import org.springframework.stereotype.Component;
...
@@ -20,8 +29,36 @@ import org.springframework.stereotype.Component;
@Component
@Component
@StrategyAlipayHandler
(
DragonConstant
.
DeviceFromEnum
.
APP
)
@StrategyAlipayHandler
(
DragonConstant
.
DeviceFromEnum
.
APP
)
public
class
AlipayStrategyAppImpl
implements
IAlipayStrategy
{
public
class
AlipayStrategyAppImpl
implements
IAlipayStrategy
{
@Autowired
StringRedisTemplate
stringRedisTemplate
;
@Value
(
"liquidnet.dragon.alipay.gataway-url"
)
private
String
alipayGatewayUrl
;
@Autowired
private
AlipayBiz
alipayBiz
;
@Override
@Override
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
return
null
;
AlipayTradePayReq
alipayTradePayReq
=
new
AlipayTradePayReq
();
alipayTradePayReq
.
setProductCode
(
"QUICK_WAP_PAY"
);
alipayTradePayReq
.
setTotalAmount
(
dragonPayBaseReqDto
.
getPrice
());
alipayTradePayReq
.
setSubject
(
dragonPayBaseReqDto
.
getName
());
alipayTradePayReq
.
setBody
(
dragonPayBaseReqDto
.
getDetail
());
//dragon中支付编号
alipayTradePayReq
.
setOutTradeNo
(
IDGenerator
.
payCode
());
alipayTradePayReq
.
setTimeExpire
(
dragonPayBaseReqDto
.
getExpireTime
());
//调用支付
Map
<
String
,
Object
>
result
=
AlipayUtil
.
tradeWapPay
(
alipayTradePayReq
);
//拼接返回参数
DragonPayBaseRespDto
respDto
=
new
DragonPayBaseRespDto
();
respDto
.
setCode
(
alipayTradePayReq
.
getOutTradeNo
());
respDto
.
setOrder_code
(
dragonPayBaseReqDto
.
getOrderCode
());
DragonPayBaseRespDto
.
PayData
payData
=
new
DragonPayBaseRespDto
.
PayData
();
payData
.
setRedirectUrl
(
alipayGatewayUrl
+
result
.
get
(
"body"
));
respDto
.
setPayData
(
payData
);
//支付订单持久化
alipayBiz
.
buildPayOrders
(
dragonPayBaseReqDto
,
respDto
);
return
ResponseDto
.
success
(
respDto
);
}
}
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/alipay/strategy/impl/AlipayStrategyWapImpl.java
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
alipay
.
strategy
.
impl
;
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
alipay
.
strategy
.
impl
;
import
com.liquidnet.commons.lang.util.IDGenerator
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.dragon.channel.alipay.biz.AlipayBiz
;
import
com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.IAlipayStrategy
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.IAlipayStrategy
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler
;
import
com.liquidnet.service.dragon.channel.alipay.util.AlipayUtil
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
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
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
/**
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @author AnJiabin <anjiabin@zhengzai.tv>
...
@@ -17,11 +27,39 @@ import org.springframework.stereotype.Component;
...
@@ -17,11 +27,39 @@ import org.springframework.stereotype.Component;
* @Copyright: LightNet @ Copyright (c) 2021
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 14:34
* @date 2021/7/10 14:34
*/
*/
@
Component
@
Service
@StrategyAlipayHandler
(
DragonConstant
.
DeviceFromEnum
.
WAP
)
@StrategyAlipayHandler
(
DragonConstant
.
DeviceFromEnum
.
WAP
)
public
class
AlipayStrategyWapImpl
implements
IAlipayStrategy
{
public
class
AlipayStrategyWapImpl
implements
IAlipayStrategy
{
@Autowired
StringRedisTemplate
stringRedisTemplate
;
@Value
(
"${liquidnet.dragon.alipay.gataway-url}"
)
private
String
alipayGatewayUrl
;
@Autowired
private
AlipayBiz
alipayBiz
;
@Override
@Override
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
return
null
;
AlipayTradePayReq
alipayTradePayReq
=
new
AlipayTradePayReq
();
alipayTradePayReq
.
setProductCode
(
"QUICK_WAP_PAY"
);
alipayTradePayReq
.
setTotalAmount
(
dragonPayBaseReqDto
.
getPrice
());
alipayTradePayReq
.
setSubject
(
dragonPayBaseReqDto
.
getName
());
alipayTradePayReq
.
setBody
(
dragonPayBaseReqDto
.
getDetail
());
//dragon中支付编号
alipayTradePayReq
.
setOutTradeNo
(
IDGenerator
.
payCode
());
alipayTradePayReq
.
setTimeExpire
(
dragonPayBaseReqDto
.
getExpireTime
());
//调用支付
Map
<
String
,
Object
>
result
=
AlipayUtil
.
tradeWapPay
(
alipayTradePayReq
);
//拼接返回参数
DragonPayBaseRespDto
respDto
=
new
DragonPayBaseRespDto
();
respDto
.
setCode
(
alipayTradePayReq
.
getOutTradeNo
());
respDto
.
setOrder_code
(
dragonPayBaseReqDto
.
getOrderCode
());
DragonPayBaseRespDto
.
PayData
payData
=
new
DragonPayBaseRespDto
.
PayData
();
payData
.
setRedirectUrl
(
alipayGatewayUrl
+
"?"
+
result
.
get
(
"body"
));
respDto
.
setPayData
(
payData
);
//支付订单持久化
alipayBiz
.
buildPayOrders
(
dragonPayBaseReqDto
,
respDto
);
return
ResponseDto
.
success
(
respDto
);
}
}
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/alipay/strategy/impl/AlipayStrategyWebImpl.java
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
alipay
.
strategy
.
impl
;
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
alipay
.
strategy
.
impl
;
import
com.liquidnet.commons.lang.util.IDGenerator
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.dragon.channel.alipay.biz.AlipayBiz
;
import
com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.IAlipayStrategy
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.IAlipayStrategy
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.annotation.StrategyAlipayHandler
;
import
com.liquidnet.service.dragon.channel.alipay.util.AlipayUtil
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
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
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @version V1.0
...
@@ -20,9 +29,36 @@ import org.springframework.stereotype.Component;
...
@@ -20,9 +29,36 @@ import org.springframework.stereotype.Component;
@Component
@Component
@StrategyAlipayHandler
(
DragonConstant
.
DeviceFromEnum
.
WEB
)
@StrategyAlipayHandler
(
DragonConstant
.
DeviceFromEnum
.
WEB
)
public
class
AlipayStrategyWebImpl
implements
IAlipayStrategy
{
public
class
AlipayStrategyWebImpl
implements
IAlipayStrategy
{
@Autowired
StringRedisTemplate
stringRedisTemplate
;
@Value
(
"liquidnet.dragon.alipay.gataway-url"
)
private
String
alipayGatewayUrl
;
@Autowired
private
AlipayBiz
alipayBiz
;
@Override
@Override
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
return
null
;
AlipayTradePayReq
alipayTradePayReq
=
new
AlipayTradePayReq
();
alipayTradePayReq
.
setProductCode
(
"QUICK_WAP_PAY"
);
alipayTradePayReq
.
setTotalAmount
(
dragonPayBaseReqDto
.
getPrice
());
alipayTradePayReq
.
setSubject
(
dragonPayBaseReqDto
.
getName
());
alipayTradePayReq
.
setBody
(
dragonPayBaseReqDto
.
getDetail
());
//dragon中支付编号
alipayTradePayReq
.
setOutTradeNo
(
IDGenerator
.
payCode
());
alipayTradePayReq
.
setTimeExpire
(
dragonPayBaseReqDto
.
getExpireTime
());
//调用支付
Map
<
String
,
Object
>
result
=
AlipayUtil
.
tradeWapPay
(
alipayTradePayReq
);
//拼接返回参数
DragonPayBaseRespDto
respDto
=
new
DragonPayBaseRespDto
();
respDto
.
setCode
(
alipayTradePayReq
.
getOutTradeNo
());
respDto
.
setOrder_code
(
dragonPayBaseReqDto
.
getOrderCode
());
DragonPayBaseRespDto
.
PayData
payData
=
new
DragonPayBaseRespDto
.
PayData
();
payData
.
setRedirectUrl
(
alipayGatewayUrl
+
result
.
get
(
"body"
));
respDto
.
setPayData
(
payData
);
//支付订单持久化
alipayBiz
.
buildPayOrders
(
dragonPayBaseReqDto
,
respDto
);
return
ResponseDto
.
success
(
respDto
);
}
}
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/alipay/util/AlipayUtil.java
View file @
37864a81
...
@@ -44,46 +44,6 @@ public class AlipayUtil {
...
@@ -44,46 +44,6 @@ public class AlipayUtil {
}
}
/**
* 支付宝支付
* @param alipayTradePayReq
* @return
*/
public
static
Map
<
String
,
Object
>
tradePagePay
(
AlipayTradePayReq
alipayTradePayReq
)
{
logger
.
info
(
"AlipayUtil.tradePay-->> req : {}"
,
alipayTradePayReq
.
toString
());
String
timeExpress
=
"5m"
;
// 支付超时,线下扫码交易定义为5分钟
AlipayClient
alipayClient
=
PayAlipayUtils
.
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
);
AlipayTradePagePayRequest
request
=
new
AlipayTradePagePayRequest
();
request
.
setNotifyUrl
(
"https://testpay.zhengzai.tv"
);
// request.setTimestamp(DateUtil.now());
logger
.
info
(
"bizContent :{}"
,
JSONObject
.
toJSONString
(
paramMap
));
request
.
setBizContent
(
JSONObject
.
toJSONString
(
paramMap
));
try
{
AlipayTradePagePayResponse
response
=
alipayClient
.
sdkExecute
(
request
);
JSONObject
responseJSON
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
response
));
logger
.
info
(
"支付宝返回结果:{}"
,
responseJSON
);
return
responseJSON
;
}
catch
(
AlipayApiException
e
)
{
logger
.
error
(
"支付宝支付异常:{}"
,
e
);
JSONObject
resultJSON
=
new
JSONObject
();
resultJSON
.
put
(
"outTradeNo"
,
alipayTradePayReq
.
getOutTradeNo
());
resultJSON
.
put
(
"totalAmount"
,
alipayTradePayReq
.
getTotalAmount
().
toString
());
resultJSON
.
put
(
"errorCode"
,
"9999"
);
return
resultJSON
;
}
}
/**
/**
* 支付宝支付
* 支付宝支付
* @param alipayTradePayReq
* @param alipayTradePayReq
...
@@ -93,7 +53,7 @@ public class AlipayUtil {
...
@@ -93,7 +53,7 @@ public class AlipayUtil {
logger
.
info
(
"AlipayUtil.tradePay-->> req : {}"
,
alipayTradePayReq
.
toString
());
logger
.
info
(
"AlipayUtil.tradePay-->> req : {}"
,
alipayTradePayReq
.
toString
());
String
timeExpress
=
"5m"
;
// 支付超时,线下扫码交易定义为5分钟
String
timeExpress
=
"5m"
;
// 支付超时,线下扫码交易定义为5分钟
AlipayClient
alipayClient
=
PayAlipayUtils
.
getHttpClient
();
AlipayClient
alipayClient
=
PayAlipayUtils
.
get
Instance
().
get
HttpClient
();
SortedMap
<
String
,
Object
>
paramMap
=
new
TreeMap
<>();
SortedMap
<
String
,
Object
>
paramMap
=
new
TreeMap
<>();
paramMap
.
put
(
"product_code"
,
alipayTradePayReq
.
getProductCode
());
paramMap
.
put
(
"product_code"
,
alipayTradePayReq
.
getProductCode
());
...
@@ -127,6 +87,7 @@ public class AlipayUtil {
...
@@ -127,6 +87,7 @@ public class AlipayUtil {
}
}
}
}
/**
/**
* 订单查询
* 订单查询
*
*
...
...
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/strategy/impl/PayChannelStrategyAlipayImpl.java
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
strategy
.
impl
;
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
strategy
.
impl
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.AlipayStrategyContext
;
import
com.liquidnet.service.dragon.channel.strategy.IPayChannelStrategy
;
import
com.liquidnet.service.dragon.channel.strategy.IPayChannelStrategy
;
import
com.liquidnet.service.dragon.channel.strategy.annotation.StrategyPayChannelHandler
;
import
com.liquidnet.service.dragon.channel.strategy.annotation.StrategyPayChannelHandler
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
/**
* @author AnJiabin <jiabin.an@lightnet.io>
* @author AnJiabin <jiabin.an@lightnet.io>
* @version V1.0
* @version V1.0
...
@@ -23,9 +22,11 @@ import java.util.List;
...
@@ -23,9 +22,11 @@ import java.util.List;
@Component
@Component
@StrategyPayChannelHandler
(
DragonConstant
.
PayChannelEnum
.
ALIPAY
)
@StrategyPayChannelHandler
(
DragonConstant
.
PayChannelEnum
.
ALIPAY
)
public
class
PayChannelStrategyAlipayImpl
implements
IPayChannelStrategy
{
public
class
PayChannelStrategyAlipayImpl
implements
IPayChannelStrategy
{
@Autowired
private
AlipayStrategyContext
alipayStrategyContext
;
@Override
@Override
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
return
null
;
return
alipayStrategyContext
.
getStrategy
(
dragonPayBaseReqDto
.
getDeviceFrom
()).
dragonPay
(
dragonPayBaseReqDto
)
;
}
}
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/strategy/impl/PayChannelStrategyWepayImpl.java
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
strategy
.
impl
;
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
strategy
.
impl
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.dragon.channel.alipay.strategy.AlipayStrategyContext
;
import
com.liquidnet.service.dragon.channel.strategy.IPayChannelStrategy
;
import
com.liquidnet.service.dragon.channel.strategy.IPayChannelStrategy
;
import
com.liquidnet.service.dragon.channel.strategy.annotation.StrategyPayChannelHandler
;
import
com.liquidnet.service.dragon.channel.strategy.annotation.StrategyPayChannelHandler
;
import
com.liquidnet.service.dragon.channel.wepay.strategy.WepayStrategyContext
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -23,9 +26,11 @@ import java.util.List;
...
@@ -23,9 +26,11 @@ import java.util.List;
@Component
@Component
@StrategyPayChannelHandler
(
DragonConstant
.
PayChannelEnum
.
WEPAY
)
@StrategyPayChannelHandler
(
DragonConstant
.
PayChannelEnum
.
WEPAY
)
public
class
PayChannelStrategyWepayImpl
implements
IPayChannelStrategy
{
public
class
PayChannelStrategyWepayImpl
implements
IPayChannelStrategy
{
@Autowired
private
WepayStrategyContext
wepayStrategyContext
;
@Override
@Override
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
return
null
;
return
wepayStrategyContext
.
getStrategy
(
dragonPayBaseReqDto
.
getDeviceFrom
()).
dragonPay
(
dragonPayBaseReqDto
)
;
}
}
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/wepay/biz/WepayBiz.java
0 → 100644
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
biz
;
import
com.liquidnet.service.dragon.channel.wepay.req.WepayPrePayReq
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: WepayBiz
* @Package com.liquidnet.service.dragon.channel.wepay.biz
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 16:46
*/
@Slf4j
@Component
public
class
WepayBiz
{
public
WepayPrePayReq
sealWeixinPerPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
WepayPrePayReq
WepayPrePayReq
=
new
WepayPrePayReq
();
// WepayPrePayReq.setAppid(appId);
// WepayPrePayReq.setMchId(mchId);
// WepayPrePayReq.setBody(productName);// 商品描述
// WepayPrePayReq.setAttach(remark);// 支付备注
// WepayPrePayReq.setOutTradeNo(bankOrderNo);// 银行订单号
//
// Integer totalFee = orderPrice.multiply(BigDecimal.valueOf(100d)).intValue();
// WepayPrePayReq.setTotalFee(totalFee);// 订单金额
// WepayPrePayReq.setTimeStart(DateUtil.parse(orderTime, "yyyyMMddHHmmss"));// 订单开始时间
//// WepayPrePayReq.setTimeExpire(DateUtil.formatDate(DateUtil.addMinute(orderTime, orderPeriod), "yyyyMMddHHmmss"));// 订单到期时间
// WepayPrePayReq.setNotifyUrl(WeixinConfigUtil.readConfig("notify_url"));// 通知地址
//// WepayPrePayReq.setTradeType("");// 交易类型
// WepayPrePayReq.setProductId(productId);// 商品ID
// WepayPrePayReq.setOpenid(openId);// 用户标识
// WepayPrePayReq.setSpbillCreateIp(orderIp);// 下单IP
return
WepayPrePayReq
;
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/wepay/config/WeixinConfigUtil.java
0 → 100644
View file @
37864a81
/*
* Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
config
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
java.io.IOException
;
import
java.util.Properties
;
/**
* <b>功能说明:微信属性文件工具类
* </b>
* @author Peter
* <a href="http://www.roncoo.com">龙果学院(www.roncoo.com)</a>
*/
public
class
WeixinConfigUtil
{
private
static
final
Log
LOG
=
LogFactory
.
getLog
(
WeixinConfigUtil
.
class
);
/**
* 通过静态代码块读取上传文件的验证格式配置文件,静态代码块只执行一次(单例)
*/
private
static
Properties
properties
=
new
Properties
();
private
WeixinConfigUtil
()
{
}
// 通过类装载器装载进来
static
{
try
{
// 从类路径下读取属性文件
properties
.
load
(
WeixinConfigUtil
.
class
.
getClassLoader
()
.
getResourceAsStream
(
"weixinpay_config.properties"
));
}
catch
(
IOException
e
)
{
LOG
.
error
(
e
);
}
}
/**
* 函数功能说明 :读取配置项 Administrator 2012-12-14 修改者名字 : 修改日期 : 修改内容 :
*
* @参数:
* @return void
* @throws
*/
public
static
String
readConfig
(
String
key
)
{
return
(
String
)
properties
.
get
(
key
);
}
//app_id
public
static
final
String
appId
=
(
String
)
properties
.
get
(
"appId"
);
//商户号
public
static
final
String
mch_id
=
(
String
)
properties
.
get
(
"mch_id"
);
//商户秘钥
public
static
final
String
partnerKey
=
(
String
)
properties
.
get
(
"partnerKey"
);
//小程序支付
public
static
final
String
xAuthUrl
=
(
String
)
properties
.
get
(
"x_auth_url"
);
public
static
final
String
xGrantType
=
(
String
)
properties
.
get
(
"x_grant_type"
);
public
static
final
String
xAppId
=
(
String
)
properties
.
get
(
"x_appId"
);
public
static
final
String
xPartnerKey
=
(
String
)
properties
.
get
(
"x_partnerKey"
);
public
static
final
String
xPayKey
=
(
String
)
properties
.
get
(
"x_payKey"
);
public
static
final
String
xMchId
=
(
String
)
properties
.
get
(
"x_mch_id"
);
public
static
final
String
x_notify_url
=
(
String
)
properties
.
get
(
"x_notify_url"
);
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/wepay/req/WepayPrePayReq.java
0 → 100644
View file @
37864a81
/*
* Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
req
;
import
com.liquidnet.commons.lang.util.IDGenerator
;
import
java.io.Serializable
;
/**
* <b>功能说明:微信预支付实体类</b>
* @author Peter
* <a href="http://www.roncoo.com">龙果学院(www.roncoo.com)</a>
*/
public
class
WepayPrePayReq
implements
Serializable
{
/** 公众账号ID 必填 **/
private
String
appid
;
/** 商户号 必填 **/
private
String
mchId
;
/** 设备号 终端设备号(门店号或收银设备ID),注意:PC网页或公众号内支付请传"WEB" 默认为'WEB'**/
private
String
deviceInfo
=
"WEB"
;
/** 随机字符串 **/
private
String
nonceStr
=
IDGenerator
.
get32UUID
();
/** 签名 **/
private
String
sign
;
/** 商品描述 **/
private
String
body
;
/** 商品详情 **/
private
String
detail
;
/** 附加数据 **/
private
String
attach
;
/** 商户订单号 **/
private
String
outTradeNo
;
/** 货币类型 默认为人民币 **/
private
String
feeType
=
"CNY"
;
/** 总金额 **/
private
Integer
totalFee
;
/** 终端IP **/
private
String
spbillCreateIp
;
/** 交易起始时间 **/
private
String
timeStart
;
/** 交易结束时间 **/
private
String
timeExpire
;
/** 商品标记 **/
private
String
goodsTag
;
/** 通知地址 **/
private
String
notifyUrl
;
/** 商品ID **/
private
String
productId
;
/** 制定支付方式 **/
private
String
limitPay
;
/** 用户标识 **/
private
String
openid
;
public
String
getAppid
()
{
return
appid
;
}
public
void
setAppid
(
String
appid
)
{
this
.
appid
=
appid
;
}
public
String
getSign
()
{
return
sign
;
}
public
void
setSign
(
String
sign
)
{
this
.
sign
=
sign
;
}
public
String
getBody
()
{
return
body
;
}
public
void
setBody
(
String
body
)
{
this
.
body
=
body
;
}
public
String
getDetail
()
{
return
detail
;
}
public
void
setDetail
(
String
detail
)
{
this
.
detail
=
detail
;
}
public
String
getAttach
()
{
return
attach
;
}
public
void
setAttach
(
String
attach
)
{
this
.
attach
=
attach
;
}
public
String
getOpenid
()
{
return
openid
;
}
public
void
setOpenid
(
String
openid
)
{
this
.
openid
=
openid
;
}
public
String
getMchId
()
{
return
mchId
;
}
public
void
setMchId
(
String
mchId
)
{
this
.
mchId
=
mchId
;
}
public
String
getDeviceInfo
()
{
return
deviceInfo
;
}
public
void
setDeviceInfo
(
String
deviceInfo
)
{
this
.
deviceInfo
=
deviceInfo
;
}
public
String
getNonceStr
()
{
return
nonceStr
;
}
public
void
setNonceStr
(
String
nonceStr
)
{
this
.
nonceStr
=
nonceStr
;
}
public
String
getOutTradeNo
()
{
return
outTradeNo
;
}
public
void
setOutTradeNo
(
String
outTradeNo
)
{
this
.
outTradeNo
=
outTradeNo
;
}
public
String
getFeeType
()
{
return
feeType
;
}
public
void
setFeeType
(
String
feeType
)
{
this
.
feeType
=
feeType
;
}
public
Integer
getTotalFee
()
{
return
totalFee
;
}
public
void
setTotalFee
(
Integer
totalFee
)
{
this
.
totalFee
=
totalFee
;
}
public
String
getSpbillCreateIp
()
{
return
spbillCreateIp
;
}
public
void
setSpbillCreateIp
(
String
spbillCreateIp
)
{
this
.
spbillCreateIp
=
spbillCreateIp
;
}
public
String
getTimeStart
()
{
return
timeStart
;
}
public
void
setTimeStart
(
String
timeStart
)
{
this
.
timeStart
=
timeStart
;
}
public
String
getTimeExpire
()
{
return
timeExpire
;
}
public
void
setTimeExpire
(
String
timeExpire
)
{
this
.
timeExpire
=
timeExpire
;
}
public
String
getGoodsTag
()
{
return
goodsTag
;
}
public
void
setGoodsTag
(
String
goodsTag
)
{
this
.
goodsTag
=
goodsTag
;
}
public
String
getNotifyUrl
()
{
return
notifyUrl
;
}
public
void
setNotifyUrl
(
String
notifyUrl
)
{
this
.
notifyUrl
=
notifyUrl
;
}
public
String
getProductId
()
{
return
productId
;
}
public
void
setProductId
(
String
productId
)
{
this
.
productId
=
productId
;
}
public
String
getLimitPay
()
{
return
limitPay
;
}
public
void
setLimitPay
(
String
limitPay
)
{
this
.
limitPay
=
limitPay
;
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/wepay/strategy/IWepayStrategy.java
0 → 100644
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
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
IWepayStrategy
{
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
);
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/wepay/strategy/WepayStrategyContext.java
0 → 100644
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
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
WepayStrategyContext
{
private
final
Map
<
String
,
IWepayStrategy
>
handlerMap
=
new
HashMap
<>();
public
IWepayStrategy
getStrategy
(
String
type
)
{
return
handlerMap
.
get
(
type
);
}
public
void
putStrategy
(
String
code
,
IWepayStrategy
strategy
)
{
handlerMap
.
put
(
code
,
strategy
);
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/wepay/strategy/WepayStrategyListener.java
0 → 100644
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
strategy
;
import
com.liquidnet.service.dragon.channel.wepay.strategy.annotation.StrategyWepayHandler
;
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
WepayStrategyListener
implements
ApplicationListener
<
ContextRefreshedEvent
>
{
@Override
public
void
onApplicationEvent
(
ContextRefreshedEvent
event
)
{
Map
<
String
,
Object
>
beans
=
event
.
getApplicationContext
().
getBeansWithAnnotation
(
StrategyWepayHandler
.
class
);
WepayStrategyContext
strategyContext
=
event
.
getApplicationContext
().
getBean
(
WepayStrategyContext
.
class
);
beans
.
forEach
((
name
,
bean
)
->
{
StrategyWepayHandler
typeHandler
=
bean
.
getClass
().
getAnnotation
(
StrategyWepayHandler
.
class
);
strategyContext
.
putStrategy
(
typeHandler
.
value
().
getCode
(),
(
IWepayStrategy
)
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/wepay/strategy/annotation/StrategyWepayHandler.java
0 → 100644
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
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: StrategyGetFundDataHandler
* @Package com.liquidnet.service.reconciliation.strategy.annotation
* @Copyright: LightNet @ Copyright (c) 2020
* @date 2020/10/27 15:29
*/
@Documented
@Inherited
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
StrategyWepayHandler
{
DragonConstant
.
DeviceFromEnum
value
();
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/wepay/strategy/impl/AbstractWepayStrategy.java
0 → 100644
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
strategy
.
impl
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.dragon.channel.wepay.strategy.IWepayStrategy
;
import
com.liquidnet.service.dragon.channel.wepay.util.WepayUtil
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
com.liquidnet.service.dragon.utils.PayWepayUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.util.EntityUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
java.util.SortedMap
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AbstractWepayStrategy
* @Package com.liquidnet.service.dragon.channel.wepay.strategy.impl
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/11 11:56
*/
@Slf4j
public
abstract
class
AbstractWepayStrategy
implements
IWepayStrategy
{
@Value
(
"${liquidnet.dragon.wepay.parentKey}"
)
private
String
parentKey
;
@Override
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
try
{
//构造请求参数
SortedMap
<
String
,
Object
>
parameters
=
this
.
buildRequestParamMap
(
dragonPayBaseReqDto
);
//生成签名
String
sign
=
WepayUtil
.
getSign
(
parameters
,
parentKey
);
parameters
.
put
(
"sign"
,
sign
);
//构造支付请求xml
String
data
=
WepayUtil
.
mapToXml
(
parameters
);
HttpPost
httpost
=
new
HttpPost
(
this
.
getRequestUrl
());
httpost
.
setEntity
(
new
StringEntity
(
data
,
"UTF-8"
));
CloseableHttpResponse
response
=
PayWepayUtils
.
getInstance
().
getHttpClient
().
execute
(
httpost
);
HttpEntity
entity
=
response
.
getEntity
();
//接受到返回信息
String
jsonStr
=
EntityUtils
.
toString
(
response
.
getEntity
(),
"UTF-8"
);
EntityUtils
.
consume
(
entity
);
log
.
info
(
"dragonPay:wepay:wap response json: {} "
,
jsonStr
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
/**
* 构造请求参数
* @return
*/
abstract
SortedMap
<
String
,
Object
>
buildRequestParamMap
(
DragonPayBaseReqDto
dragonPayBaseReqDto
);
/**
* 构造返回参数
*/
abstract
DragonPayBaseRespDto
buildResponseDto
();
protected
abstract
String
getRequestUrl
();
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/wepay/strategy/impl/WepayStrategyAppImpl.java
0 → 100644
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
strategy
.
impl
;
import
com.liquidnet.service.dragon.channel.wepay.strategy.annotation.StrategyWepayHandler
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
java.util.SortedMap
;
/**
* @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
@Component
@StrategyWepayHandler
(
DragonConstant
.
DeviceFromEnum
.
APP
)
public
class
WepayStrategyAppImpl
extends
AbstractWepayStrategy
{
@Override
SortedMap
<
String
,
Object
>
buildRequestParamMap
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
return
null
;
}
@Override
DragonPayBaseRespDto
buildResponseDto
()
{
return
null
;
}
@Override
protected
String
getRequestUrl
()
{
return
null
;
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/wepay/strategy/impl/WepayStrategyJsImpl.java
0 → 100644
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
strategy
.
impl
;
import
com.liquidnet.service.dragon.channel.wepay.strategy.annotation.StrategyWepayHandler
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
java.util.SortedMap
;
/**
* @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
@Component
@StrategyWepayHandler
(
DragonConstant
.
DeviceFromEnum
.
JS
)
public
class
WepayStrategyJsImpl
extends
AbstractWepayStrategy
{
@Override
SortedMap
<
String
,
Object
>
buildRequestParamMap
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
return
null
;
}
@Override
DragonPayBaseRespDto
buildResponseDto
()
{
return
null
;
}
@Override
protected
String
getRequestUrl
()
{
return
null
;
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/wepay/strategy/impl/WepayStrategyWapImpl.java
0 → 100644
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
strategy
.
impl
;
import
com.liquidnet.commons.lang.util.IDGenerator
;
import
com.liquidnet.service.dragon.channel.wepay.strategy.annotation.StrategyWepayHandler
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
com.liquidnet.service.dragon.utils.PayWepayUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
java.math.BigDecimal
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
/**
* @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
@Component
@StrategyWepayHandler
(
DragonConstant
.
DeviceFromEnum
.
WAP
)
public
class
WepayStrategyWapImpl
extends
AbstractWepayStrategy
{
@Override
SortedMap
<
String
,
Object
>
buildRequestParamMap
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
String
nonceStr
=
PayWepayUtils
.
getInstance
().
getNonceStr
();
SortedMap
<
String
,
Object
>
parameters
=
new
TreeMap
<>();
parameters
.
put
(
"mch_id"
,
PayWepayUtils
.
getInstance
().
getMerchantId
());
parameters
.
put
(
"appid"
,
PayWepayUtils
.
getInstance
().
getAppId
());
parameters
.
put
(
"nonce_str"
,
nonceStr
);
parameters
.
put
(
"spbill_create_ip"
,
dragonPayBaseReqDto
.
getClientIp
());
parameters
.
put
(
"total_fee"
,
dragonPayBaseReqDto
.
getPrice
().
multiply
(
BigDecimal
.
valueOf
(
100L
)).
intValue
());
parameters
.
put
(
"body"
,
dragonPayBaseReqDto
.
getName
());
parameters
.
put
(
"detail"
,
dragonPayBaseReqDto
.
getDetail
());
parameters
.
put
(
"out_trade_no"
,
IDGenerator
.
payCode
());
parameters
.
put
(
"time_expire"
,
"20210908103456"
);
parameters
.
put
(
"notify_url"
,
"https://www.baidu.com"
);
parameters
.
put
(
"trade_type"
,
"MWEB"
);
return
parameters
;
}
@Override
DragonPayBaseRespDto
buildResponseDto
()
{
return
null
;
}
@Override
protected
String
getRequestUrl
()
{
return
"https://api.mch.weixin.qq.com/pay/unifiedorder"
;
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/wepay/util/MD5Util.java
0 → 100644
View file @
37864a81
/*
* Copyright 2015-2102 RonCoo(http://www.roncoo.com) Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
util
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.security.MessageDigest
;
/**
* <b>功能说明:MD5签名工具类
* </b>
* @author Peter
* <a href="http://www.roncoo.com">龙果学院(www.roncoo.com)</a>
*/
public
class
MD5Util
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
MD5Util
.
class
);
/**
* 私有构造方法,将该工具类设为单例模式.
*/
private
MD5Util
()
{
}
private
static
final
String
[]
hex
=
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
};
public
static
String
encode
(
String
password
)
{
try
{
MessageDigest
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
byte
[]
byteArray
=
md5
.
digest
(
password
.
getBytes
(
"utf-8"
));
String
passwordMD5
=
byteArrayToHexString
(
byteArray
);
return
passwordMD5
;
}
catch
(
Exception
e
)
{
LOG
.
error
(
e
.
toString
());
}
return
password
;
}
private
static
String
byteArrayToHexString
(
byte
[]
byteArray
)
{
StringBuffer
sb
=
new
StringBuffer
();
for
(
byte
b
:
byteArray
)
{
sb
.
append
(
byteToHexChar
(
b
));
}
return
sb
.
toString
();
}
private
static
Object
byteToHexChar
(
byte
b
)
{
int
n
=
b
;
if
(
n
<
0
)
{
n
=
256
+
n
;
}
int
d1
=
n
/
16
;
int
d2
=
n
%
16
;
return
hex
[
d1
]
+
hex
[
d2
];
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/channel/wepay/util/WepayUtil.java
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
util
;
package
com
.
liquidnet
.
service
.
dragon
.
channel
.
wepay
.
util
;
import
com.liquidnet.commons.lang.util.StringUtil
;
import
com.liquidnet.service.dragon.channel.wepay.config.WeixinConfigUtil
;
import
com.liquidnet.service.dragon.channel.wepay.req.WepayPrePayReq
;
import
lombok.extern.slf4j.Slf4j
;
import
org.dom4j.Document
;
import
org.dom4j.Element
;
import
org.dom4j.io.SAXReader
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.net.ssl.HttpsURLConnection
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.OutputStream
;
import
java.math.BigDecimal
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.*
;
/**
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @version V1.0
...
@@ -9,5 +29,443 @@ package com.liquidnet.service.dragon.channel.wepay.util;
...
@@ -9,5 +29,443 @@ package com.liquidnet.service.dragon.channel.wepay.util;
* @Copyright: LightNet @ Copyright (c) 2021
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/9 15:20
* @date 2021/7/9 15:20
*/
*/
@Slf4j
public
class
WepayUtil
{
public
class
WepayUtil
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
WepayUtil
.
class
);
private
WepayUtil
()
{
}
/**
* 微信被扫(扫码设备)
*
* @param outTradeNo
* @param body
* @param totalAmount
* @param spbillCreateIp
* @param authCode
* @return
*/
public
static
Map
<
String
,
Object
>
micropay
(
String
outTradeNo
,
String
body
,
BigDecimal
totalAmount
,
String
spbillCreateIp
,
String
authCode
)
{
String
nonce_str
=
getnonceStr
();
Integer
total_fee
=
totalAmount
.
multiply
(
BigDecimal
.
valueOf
(
100L
)).
intValue
();
SortedMap
<
String
,
Object
>
paramMap
=
new
TreeMap
<>();
paramMap
.
put
(
"appid"
,
WeixinConfigUtil
.
appId
);
paramMap
.
put
(
"mch_id"
,
WeixinConfigUtil
.
mch_id
);
paramMap
.
put
(
"nonce_str"
,
nonce_str
);
paramMap
.
put
(
"sign_type"
,
"MD5"
);
paramMap
.
put
(
"body"
,
body
);
paramMap
.
put
(
"out_trade_no"
,
outTradeNo
);
paramMap
.
put
(
"total_fee"
,
total_fee
);
paramMap
.
put
(
"fee_type"
,
"CNY"
);
paramMap
.
put
(
"spbill_create_ip"
,
spbillCreateIp
);
paramMap
.
put
(
"auth_code"
,
authCode
);
paramMap
.
put
(
"sign"
,
getSign
(
paramMap
,
WeixinConfigUtil
.
partnerKey
));
String
data
=
mapToXml
(
paramMap
);
logger
.
info
(
"微信条码请求报文:{}"
,
data
);
Map
<
String
,
Object
>
resultMap
=
httpXmlRequest
(
"https://api.mch.weixin.qq.com/pay/micropay"
,
"POST"
,
data
);
logger
.
info
(
"微信条码返回报文:{}"
,
resultMap
);
if
(
resultMap
==
null
||
resultMap
.
isEmpty
())
{
return
null
;
}
SortedMap
<
String
,
Object
>
responseMap
=
new
TreeMap
<>();
responseMap
.
putAll
(
resultMap
);
String
resultSign
=
getSign
(
responseMap
,
WeixinConfigUtil
.
partnerKey
);
if
(
resultSign
.
equals
(
resultMap
.
get
(
"sign"
)))
{
resultMap
.
put
(
"verify"
,
"YES"
);
}
else
{
logger
.
info
(
"返回报文验签失败,返回报文签名:{},返回签名:{}"
,
resultSign
,
resultMap
.
get
(
"sign"
));
resultMap
.
put
(
"verify"
,
"NO"
);
}
return
resultMap
;
}
/**
* 小程序支付
*
* @return
*/
public
static
Map
<
String
,
Object
>
appletPay
(
String
outTradeNo
,
String
body
,
BigDecimal
totalAmount
,
String
spbillCreateIp
,
String
notifyUrl
,
String
openid
)
{
String
nonce_str
=
getnonceStr
();
Integer
totalFee
=
totalAmount
.
multiply
(
BigDecimal
.
valueOf
(
100L
)).
intValue
();
String
tradeType
=
"JSAPI"
;
SortedMap
<
String
,
Object
>
paramMap
=
new
TreeMap
<>();
paramMap
.
put
(
"appid"
,
WeixinConfigUtil
.
xAppId
);
paramMap
.
put
(
"mch_id"
,
WeixinConfigUtil
.
xMchId
);
paramMap
.
put
(
"nonce_str"
,
nonce_str
);
paramMap
.
put
(
"sign_type"
,
"MD5"
);
paramMap
.
put
(
"body"
,
body
);
paramMap
.
put
(
"out_trade_no"
,
outTradeNo
);
paramMap
.
put
(
"total_fee"
,
totalFee
);
paramMap
.
put
(
"spbill_create_ip"
,
spbillCreateIp
);
paramMap
.
put
(
"notify_url"
,
notifyUrl
);
paramMap
.
put
(
"trade_type"
,
tradeType
);
paramMap
.
put
(
"openid"
,
openid
);
// if (goodsDetails != null && !goodsDetails.isEmpty()) {
// List<SortedMap<String, Object>> goodList = new ArrayList<>();
// for (RoncooPayGoodsDetails goodsDetail : goodsDetails) {
// SortedMap<String, Object> goodsDetailMap = new TreeMap<>();
// goodsDetailMap.put("goods_id", goodsDetail.getGoodsId());
// goodsDetailMap.put("quantity", goodsDetail.getNums());
// goodsDetailMap.put("goods_name", goodsDetail.getGoodsName());
// goodsDetailMap.put("price", goodsDetail.getSinglePrice());
// goodList.add(goodsDetailMap);
// }
// JSONObject goodsDetailJson = new JSONObject();
// goodsDetailJson.put("goods_detail", goodList);
// paramMap.put("detail", goodsDetailJson.toJSONString());
// }
paramMap
.
put
(
"sign"
,
getSign
(
paramMap
,
WeixinConfigUtil
.
xPayKey
));
String
data
=
mapToXml
(
paramMap
);
logger
.
info
(
"微信小程序统一下单,请求报文:{}"
,
data
);
Map
<
String
,
Object
>
resultMap
=
httpXmlRequest
(
"https://api.mch.weixin.qq.com/pay/unifiedorder"
,
"POST"
,
data
);
logger
.
info
(
"微信小程序统一下单,返回报文:{}"
,
resultMap
);
if
(
resultMap
==
null
||
resultMap
.
isEmpty
())
{
return
null
;
}
SortedMap
<
String
,
Object
>
responseMap
=
new
TreeMap
<>();
responseMap
.
putAll
(
resultMap
);
String
resultSign
=
getSign
(
responseMap
,
WeixinConfigUtil
.
xPayKey
);
if
(
resultSign
.
equals
(
resultMap
.
get
(
"sign"
)))
{
resultMap
.
put
(
"verify"
,
"YES"
);
}
else
{
logger
.
info
(
"返回报文验签失败,返回报文签名:{},返回签名:{}"
,
resultSign
,
resultMap
.
get
(
"sign"
));
resultMap
.
put
(
"verify"
,
"NO"
);
}
return
resultMap
;
}
/**
* 生成随机字符串
*
* @return
*/
public
static
String
getnonceStr
()
{
Random
random
=
new
Random
();
StringBuilder
nonceStrBuilder
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
31
;
i
++)
{
nonceStrBuilder
.
append
(
random
.
nextInt
(
10
));
}
return
nonceStrBuilder
.
toString
();
}
/**
* 签名
*
* @param paramMap
* @param key
* @return
*/
public
static
String
getSign
(
SortedMap
<
String
,
Object
>
paramMap
,
String
key
)
{
StringBuilder
signBuilder
=
new
StringBuilder
();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
paramMap
.
entrySet
())
{
if
(!
"sign"
.
equals
(
entry
.
getKey
())
&&
!
StringUtil
.
isEmpty
(
entry
.
getValue
()))
{
signBuilder
.
append
(
entry
.
getKey
()).
append
(
"="
).
append
(
entry
.
getValue
()).
append
(
"&"
);
}
}
signBuilder
.
append
(
"key="
).
append
(
key
);
logger
.
info
(
"微信待签名参数字符串:{}"
,
signBuilder
.
toString
());
return
MD5Util
.
encode
(
signBuilder
.
toString
()).
toUpperCase
();
}
/**
* 转xml格式
*
* @param paramMap
* @return
*/
public
static
String
mapToXml
(
SortedMap
<
String
,
Object
>
paramMap
)
{
StringBuilder
dataBuilder
=
new
StringBuilder
(
"<xml>"
);
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
paramMap
.
entrySet
())
{
if
(!
StringUtil
.
isEmpty
(
entry
.
getValue
()))
{
dataBuilder
.
append
(
"<"
).
append
(
entry
.
getKey
()).
append
(
">"
).
append
(
entry
.
getValue
()).
append
(
"</"
).
append
(
entry
.
getKey
()).
append
(
">"
);
}
}
dataBuilder
.
append
(
"</xml>"
);
logger
.
info
(
"Map转Xml结果:{}"
,
dataBuilder
.
toString
());
return
dataBuilder
.
toString
();
}
/**
* 发送xml数据,获取返回结果
*
* @param requestUrl
* @param requestMethod
* @param xmlStr
* @return
*/
public
static
Map
<
String
,
Object
>
httpXmlRequest
(
String
requestUrl
,
String
requestMethod
,
String
xmlStr
)
{
// 将解析结果存储在HashMap中
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
try
{
HttpsURLConnection
urlCon
=
(
HttpsURLConnection
)
(
new
URL
(
requestUrl
)).
openConnection
();
urlCon
.
setDoInput
(
true
);
urlCon
.
setDoOutput
(
true
);
// 设置请求方式(GET/POST)
urlCon
.
setRequestMethod
(
requestMethod
);
if
(
"GET"
.
equalsIgnoreCase
(
requestMethod
))
{
urlCon
.
connect
();
}
urlCon
.
setRequestProperty
(
"Content-Length"
,
String
.
valueOf
(
xmlStr
.
getBytes
().
length
));
urlCon
.
setUseCaches
(
false
);
// 设置为gbk可以解决服务器接收时读取的数据中文乱码问题
if
(
null
!=
xmlStr
)
{
OutputStream
outputStream
=
urlCon
.
getOutputStream
();
outputStream
.
write
(
xmlStr
.
getBytes
(
"UTF-8"
));
outputStream
.
flush
();
outputStream
.
close
();
}
InputStream
inputStream
=
urlCon
.
getInputStream
();
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
inputStream
,
"UTF-8"
);
// 读取输入流
SAXReader
reader
=
new
SAXReader
();
Document
document
=
reader
.
read
(
inputStreamReader
);
// 得到xml根元素
Element
root
=
document
.
getRootElement
();
// 得到根元素的所有子节点
@SuppressWarnings
(
"unchecked"
)
List
<
Element
>
elementList
=
root
.
elements
();
// 遍历所有子节点
for
(
Element
e
:
elementList
)
{
map
.
put
(
e
.
getName
(),
e
.
getText
());
}
log
.
info
(
"微信查询返回结果:"
+
map
.
toString
());
inputStreamReader
.
close
();
inputStream
.
close
();
inputStream
=
null
;
urlCon
.
disconnect
();
}
catch
(
MalformedURLException
e
)
{
log
.
error
(
e
.
getMessage
());
}
catch
(
IOException
e
)
{
log
.
error
(
e
.
getMessage
());
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
}
return
map
;
}
/**
* 生成预支付XML
*
* @param WepayPrePayReq
* @param partnerKey
* @return
*/
public
static
String
getPrePayXml
(
WepayPrePayReq
WepayPrePayReq
,
String
partnerKey
)
{
getPrePaySign
(
WepayPrePayReq
,
partnerKey
);
// 生成预支付请求签名
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"<xml><appid>"
).
append
(
WepayPrePayReq
.
getAppid
()).
append
(
"</appid>"
);
sb
.
append
(
"<body>"
).
append
(
WepayPrePayReq
.
getBody
()).
append
(
"</body>"
);
sb
.
append
(
"<device_info>"
).
append
(
WepayPrePayReq
.
getDeviceInfo
()).
append
(
"</device_info>"
);
sb
.
append
(
"<mch_id>"
).
append
(
WepayPrePayReq
.
getMchId
()).
append
(
"</mch_id>"
);
sb
.
append
(
"<nonce_str>"
).
append
(
WepayPrePayReq
.
getNonceStr
()).
append
(
"</nonce_str>"
);
sb
.
append
(
"<notify_url>"
).
append
(
WepayPrePayReq
.
getNotifyUrl
()).
append
(
"</notify_url>"
);
// if (WeiXinTradeTypeEnum.NATIVE.name().equals(WepayPrePayReq.getTradeType())) {
// sb.append("<product_id>").append(WepayPrePayReq.getProductId()).append("</product_id>");
// } else if (WeiXinTradeTypeEnum.JSAPI.name().equals(WepayPrePayReq.getTradeType())) {
// sb.append("<openid>").append(WepayPrePayReq.getOpenid()).append("</openid>");
// }
sb
.
append
(
"<out_trade_no>"
).
append
(
WepayPrePayReq
.
getOutTradeNo
()).
append
(
"</out_trade_no>"
);
sb
.
append
(
"<spbill_create_ip>"
).
append
(
WepayPrePayReq
.
getSpbillCreateIp
()).
append
(
"</spbill_create_ip>"
);
sb
.
append
(
"<time_start>"
).
append
(
WepayPrePayReq
.
getTimeStart
()).
append
(
"</time_start>"
);
sb
.
append
(
"<time_expire>"
).
append
(
WepayPrePayReq
.
getTimeExpire
()).
append
(
"</time_expire>"
);
sb
.
append
(
"<total_fee>"
).
append
(
WepayPrePayReq
.
getTotalFee
()).
append
(
"</total_fee>"
);
// sb.append("<trade_type>").append(WepayPrePayReq.getTradeType().name()).append("</trade_type>");
sb
.
append
(
"<sign>"
).
append
(
WepayPrePayReq
.
getSign
()).
append
(
"</sign>"
);
sb
.
append
(
"</xml>"
);
return
sb
.
toString
();
}
/**
* 微信拼接签名参数
*
* @param appid 公众账号ID
* @param mch_id 商户号
* @param device_info 设备号
* @param trade_type 交易类型
* @param prePay 预支付返回Map
* @param partnerKey 签名EY
* @return
*/
public
static
String
geWeiXintPrePaySign
(
String
appid
,
String
mch_id
,
String
device_info
,
String
trade_type
,
Map
<
String
,
Object
>
prePay
,
String
partnerKey
)
{
Map
<
String
,
Object
>
preParams
=
new
HashMap
<
String
,
Object
>();
if
(!
StringUtil
.
isEmpty
(
prePay
.
get
(
"return_code"
)))
{
preParams
.
put
(
"return_code"
,
prePay
.
get
(
"return_code"
));
}
if
(!
StringUtil
.
isEmpty
(
prePay
.
get
(
"return_msg"
)))
{
preParams
.
put
(
"return_msg"
,
prePay
.
get
(
"return_msg"
));
}
if
(!
StringUtil
.
isEmpty
(
prePay
.
get
(
"appid"
)))
{
preParams
.
put
(
"appid"
,
appid
);
}
if
(!
StringUtil
.
isEmpty
(
prePay
.
get
(
"mch_id"
)))
{
preParams
.
put
(
"mch_id"
,
mch_id
);
}
if
(!
StringUtil
.
isEmpty
(
prePay
.
get
(
"device_info"
)))
{
preParams
.
put
(
"device_info"
,
device_info
);
}
if
(!
StringUtil
.
isEmpty
(
prePay
.
get
(
"nonce_str"
)))
{
preParams
.
put
(
"nonce_str"
,
prePay
.
get
(
"nonce_str"
));
}
if
(!
StringUtil
.
isEmpty
(
prePay
.
get
(
"result_code"
)))
{
preParams
.
put
(
"result_code"
,
prePay
.
get
(
"result_code"
));
}
if
(
"FAIL"
.
equals
(
prePay
.
get
(
"result_code"
)))
{
if
(!
StringUtil
.
isEmpty
(
prePay
.
get
(
"err_code"
)))
{
preParams
.
put
(
"err_code"
,
prePay
.
get
(
"err_code"
));
}
if
(!
StringUtil
.
isEmpty
(
prePay
.
get
(
"err_code_des"
)))
{
preParams
.
put
(
"err_code_des"
,
prePay
.
get
(
"err_code_des"
));
}
}
if
(!
StringUtil
.
isEmpty
(
prePay
.
get
(
"trade_type"
)))
{
preParams
.
put
(
"trade_type"
,
trade_type
);
}
if
(!
StringUtil
.
isEmpty
(
prePay
.
get
(
"prepay_id"
)))
{
preParams
.
put
(
"prepay_id"
,
prePay
.
get
(
"prepay_id"
));
}
if
(!
StringUtil
.
isEmpty
(
prePay
.
get
(
"code_url"
)))
{
preParams
.
put
(
"code_url"
,
prePay
.
get
(
"code_url"
));
}
String
argPreSign
=
getStringByMap
(
preParams
)
+
"&key="
+
partnerKey
;
String
preSign
=
MD5Util
.
encode
(
argPreSign
).
toUpperCase
();
return
preSign
;
}
public
static
boolean
notifySign
(
Map
<
String
,
String
>
result
,
String
sign
,
String
partnerKey
)
{
String
argNotifySign
=
getStringByStringMap
(
result
)
+
"&key="
+
partnerKey
;
String
notifySign
=
MD5Util
.
encode
(
argNotifySign
).
toUpperCase
();
if
(
notifySign
.
equals
(
sign
))
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 获取预支付请求签名
*
* @param WepayPrePayReq
* @param partnerKey
* @return
*/
private
static
void
getPrePaySign
(
WepayPrePayReq
WepayPrePayReq
,
String
partnerKey
)
{
Map
<
String
,
Object
>
prePayMap
=
new
HashMap
<
String
,
Object
>();
prePayMap
.
put
(
"appid"
,
WepayPrePayReq
.
getAppid
());
// 公众账号ID
prePayMap
.
put
(
"mch_id"
,
WepayPrePayReq
.
getMchId
());
// 商户号
prePayMap
.
put
(
"device_info"
,
WepayPrePayReq
.
getDeviceInfo
());
prePayMap
.
put
(
"nonce_str"
,
WepayPrePayReq
.
getNonceStr
());
// 随机字符串
prePayMap
.
put
(
"body"
,
WepayPrePayReq
.
getBody
());
// 商品描述
prePayMap
.
put
(
"out_trade_no"
,
WepayPrePayReq
.
getOutTradeNo
());
// 商户订单号
prePayMap
.
put
(
"total_fee"
,
WepayPrePayReq
.
getTotalFee
());
// 总金额
prePayMap
.
put
(
"spbill_create_ip"
,
WepayPrePayReq
.
getSpbillCreateIp
());
// 终端IP
prePayMap
.
put
(
"time_start"
,
WepayPrePayReq
.
getTimeStart
());
// 开始时间
prePayMap
.
put
(
"time_expire"
,
WepayPrePayReq
.
getTimeExpire
());
// 截止时间
prePayMap
.
put
(
"notify_url"
,
WepayPrePayReq
.
getNotifyUrl
());
// 接收财付通通知的URL
// prePayMap.put("trade_type", WepayPrePayReq.getTradeType().name()); // 交易类型
// if (WeiXinTradeTypeEnum.NATIVE.name().equals(WepayPrePayReq.getTradeType())) {
// prePayMap.put("product_id", WepayPrePayReq.getProductId()); // 商品ID
// } else if (WeiXinTradeTypeEnum.JSAPI.name().equals(WepayPrePayReq.getTradeType())) {
// prePayMap.put("openid", WepayPrePayReq.getOpenid()); // openid
// }
String
argPreSign
=
getStringByMap
(
prePayMap
)
+
"&key="
+
partnerKey
;
String
preSign
=
MD5Util
.
encode
(
argPreSign
).
toUpperCase
();
WepayPrePayReq
.
setSign
(
preSign
);
}
/**
* 根据Map获取排序拼接后的字符串
*
* @param map
* @return
*/
public
static
String
getStringByMap
(
Map
<
String
,
Object
>
map
)
{
SortedMap
<
String
,
Object
>
smap
=
new
TreeMap
<
String
,
Object
>(
map
);
StringBuffer
sb
=
new
StringBuffer
();
for
(
Map
.
Entry
<
String
,
Object
>
m
:
smap
.
entrySet
())
{
sb
.
append
(
m
.
getKey
()).
append
(
"="
).
append
(
m
.
getValue
()).
append
(
"&"
);
}
sb
.
delete
(
sb
.
length
()
-
1
,
sb
.
length
());
return
sb
.
toString
();
}
public
static
String
getStringByStringMap
(
Map
<
String
,
String
>
map
)
{
SortedMap
<
String
,
Object
>
smap
=
new
TreeMap
<
String
,
Object
>(
map
);
StringBuffer
sb
=
new
StringBuffer
();
for
(
Map
.
Entry
<
String
,
Object
>
m
:
smap
.
entrySet
())
{
sb
.
append
(
m
.
getKey
()).
append
(
"="
).
append
(
m
.
getValue
()).
append
(
"&"
);
}
sb
.
delete
(
sb
.
length
()
-
1
,
sb
.
length
());
return
sb
.
toString
();
}
/**
* 解析微信发来的请求(XML)
*
* @param inputStream
* @return
* @throws Exception
*/
@SuppressWarnings
(
"unchecked"
)
public
static
Map
<
String
,
String
>
parseXml
(
InputStream
inputStream
)
throws
Exception
{
if
(
inputStream
==
null
)
{
return
null
;
}
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
// 将解析结果存储在HashMap中
SAXReader
reader
=
new
SAXReader
();
// 读取输入流
Document
document
=
reader
.
read
(
inputStream
);
Element
root
=
document
.
getRootElement
();
// 得到xml根元素
List
<
Element
>
elementList
=
root
.
elements
();
// 得到根元素的所有子节点
for
(
Element
e
:
elementList
)
{
// 遍历所有子节点
map
.
put
(
e
.
getName
(),
e
.
getText
());
}
inputStream
.
close
();
// 释放资源
inputStream
=
null
;
return
map
;
}
/**
* 订单查询
*
* @param outTradeNo
* @return
*/
public
static
Map
<
String
,
Object
>
orderQuery
(
String
outTradeNo
,
String
appId
,
String
MchId
,
String
partnerKey
)
{
Random
random
=
new
Random
();
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"appid"
,
appId
);
paramMap
.
put
(
"mch_id"
,
MchId
);
String
nonce_str
=
""
;
for
(
int
i
=
0
;
i
<
31
;
i
++)
{
nonce_str
+=
random
.
nextInt
(
10
);
}
paramMap
.
put
(
"nonce_str"
,
nonce_str
);
paramMap
.
put
(
"out_trade_no"
,
outTradeNo
);
String
signStr
=
getStringByMap
(
paramMap
)
+
"&key="
+
partnerKey
;
paramMap
.
put
(
"sign"
,
MD5Util
.
encode
(
signStr
).
toUpperCase
());
Set
<
String
>
ks
=
paramMap
.
keySet
();
StringBuilder
sb
=
new
StringBuilder
(
"<xml>"
);
for
(
String
key
:
ks
)
{
sb
.
append
(
"<"
+
key
+
">"
+
paramMap
.
get
(
key
)
+
"</"
+
key
+
">"
);
}
sb
.
append
(
"</xml>"
);
Map
<
String
,
Object
>
resultMap
=
httpXmlRequest
(
"https://api.mch.weixin.qq.com/pay/orderquery"
,
"POST"
,
sb
.
toString
());
return
resultMap
;
}
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/controller/PayController.java
View file @
37864a81
...
@@ -27,7 +27,7 @@ import java.math.BigDecimal;
...
@@ -27,7 +27,7 @@ import java.math.BigDecimal;
* @date 2021/7/9 12:29
* @date 2021/7/9 12:29
*/
*/
@RestController
@RestController
@RequestMapping
(
"
pay
"
)
@RequestMapping
(
"
dragon
"
)
public
class
PayController
{
public
class
PayController
{
@Autowired
@Autowired
private
IDragonOrdersService
dragonOrdersService
;
private
IDragonOrdersService
dragonOrdersService
;
...
@@ -36,8 +36,8 @@ public class PayController {
...
@@ -36,8 +36,8 @@ public class PayController {
* 电脑网页支付宝支付
* 电脑网页支付宝支付
* @return
* @return
*/
*/
@PostMapping
(
"/
web/ali
pay"
)
@PostMapping
(
"/pay"
)
@ApiOperation
(
"
支付宝web
支付"
)
@ApiOperation
(
"
Dragon
支付"
)
@ApiResponse
(
code
=
200
,
message
=
"接口返回对象参数"
)
@ApiResponse
(
code
=
200
,
message
=
"接口返回对象参数"
)
@ApiImplicitParams
({
@ApiImplicitParams
({
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"payType"
,
value
=
"支付类型:alipay,wepay,iappay"
,
example
=
"alipay"
),
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"payType"
,
value
=
"支付类型:alipay,wepay,iappay"
,
example
=
"alipay"
),
...
@@ -51,8 +51,9 @@ public class PayController {
...
@@ -51,8 +51,9 @@ public class PayController {
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"notifyUrl"
,
value
=
"通知url"
,
example
=
"pay.zhengzai.tv"
),
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"notifyUrl"
,
value
=
"通知url"
,
example
=
"pay.zhengzai.tv"
),
})
})
public
ResponseDto
<
DragonPayBaseRespDto
>
webAlipay
(
public
ResponseDto
<
DragonPayBaseRespDto
>
webAlipay
(
@RequestParam
(
value
=
"payType"
)
@NotNull
(
message
=
"支付类型不能为空"
)
BigDecimal
payType
,
@RequestParam
(
value
=
"payType"
)
@NotNull
(
message
=
"支付类型不能为空"
)
String
payType
,
@RequestParam
(
value
=
"deviceFrom"
)
@NotNull
(
message
=
"设备来源不能为空"
)
BigDecimal
deviceFrom
,
@RequestParam
(
value
=
"deviceFrom"
)
@NotNull
(
message
=
"设备来源不能为空"
)
String
deviceFrom
,
@RequestParam
(
value
=
"openId"
)
@NotNull
(
message
=
"微信支付openId不能为空"
)
String
openId
,
@RequestParam
(
value
=
"type"
)
@NotNull
(
message
=
"业务类型不能为空"
)
String
type
,
@RequestParam
(
value
=
"type"
)
@NotNull
(
message
=
"业务类型不能为空"
)
String
type
,
@RequestParam
(
value
=
"price"
)
@NotNull
(
message
=
"支付金额不能为空"
)
BigDecimal
price
,
@RequestParam
(
value
=
"price"
)
@NotNull
(
message
=
"支付金额不能为空"
)
BigDecimal
price
,
@RequestParam
(
value
=
"name"
)
@NotNull
(
message
=
"订单名称不能为空"
)
String
name
,
@RequestParam
(
value
=
"name"
)
@NotNull
(
message
=
"订单名称不能为空"
)
String
name
,
...
@@ -67,6 +68,9 @@ public class PayController {
...
@@ -67,6 +68,9 @@ public class PayController {
@RequestParam
(
value
=
"createDate"
,
required
=
false
)
String
createDate
,
@RequestParam
(
value
=
"createDate"
,
required
=
false
)
String
createDate
,
@RequestParam
(
value
=
"expireTime"
,
required
=
false
)
String
expireTime
){
@RequestParam
(
value
=
"expireTime"
,
required
=
false
)
String
expireTime
){
DragonPayBaseReqDto
dragonPayBaseReqDto
=
new
DragonPayBaseReqDto
();
DragonPayBaseReqDto
dragonPayBaseReqDto
=
new
DragonPayBaseReqDto
();
dragonPayBaseReqDto
.
setPayType
(
payType
);
dragonPayBaseReqDto
.
setDeviceFrom
(
deviceFrom
);
dragonPayBaseReqDto
.
setOpenId
(
openId
);
dragonPayBaseReqDto
.
setType
(
type
);
dragonPayBaseReqDto
.
setType
(
type
);
dragonPayBaseReqDto
.
setPrice
(
price
);
dragonPayBaseReqDto
.
setPrice
(
price
);
dragonPayBaseReqDto
.
setName
(
name
);
dragonPayBaseReqDto
.
setName
(
name
);
...
@@ -74,49 +78,49 @@ public class PayController {
...
@@ -74,49 +78,49 @@ public class PayController {
dragonPayBaseReqDto
.
setOrderCode
(
orderCode
);
dragonPayBaseReqDto
.
setOrderCode
(
orderCode
);
dragonPayBaseReqDto
.
setClientIp
(
clientIp
);
dragonPayBaseReqDto
.
setClientIp
(
clientIp
);
dragonPayBaseReqDto
.
setNotifyUrl
(
notifyUrl
);
dragonPayBaseReqDto
.
setNotifyUrl
(
notifyUrl
);
return
dragonOrdersService
.
alipay
(
dragonPayBaseReqDto
);
return
dragonOrdersService
.
dragonPay
(
dragonPayBaseReqDto
);
}
/**
* 手机网页支付宝支付
* @return
*/
@PostMapping
(
"/wap/alipay"
)
@ApiOperation
(
"支付宝wap支付"
)
@ApiResponse
(
code
=
200
,
message
=
"接口返回对象参数"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"type"
,
value
=
"支付类型:TICKET,PRODUCT,COST,MBEANS,LIVE,VIDEO,VIP,CLUB,STRAWBERRY"
,
example
=
"TICKET"
),
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"price"
,
value
=
"支付金额"
,
example
=
"0.1"
),
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"name"
,
value
=
"订单名称"
,
example
=
"测试订单001"
),
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"detail"
,
value
=
"订单描述"
,
example
=
"测试订单001"
),
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"orderCode"
,
value
=
"订单编号"
,
example
=
"ORDER0001"
),
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"clientIp"
,
value
=
"客户端ip"
,
example
=
"127.0.0.1"
),
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"notifyUrl"
,
value
=
"通知url"
,
example
=
"pay.zhengzai.tv"
),
})
public
ResponseDto
<
DragonPayBaseRespDto
>
wapAlipay
(
@RequestParam
(
value
=
"type"
)
@NotNull
(
message
=
"支付类型不能为空"
)
String
type
,
@RequestParam
(
value
=
"price"
)
@NotNull
(
message
=
"支付金额不能为空"
)
BigDecimal
price
,
@RequestParam
(
value
=
"name"
)
@NotNull
(
message
=
"订单名称不能为空"
)
String
name
,
@RequestParam
(
value
=
"detail"
)
@NotNull
(
message
=
"订单描述不能为空"
)
String
detail
,
@RequestParam
(
value
=
"orderCode"
)
@NotNull
(
message
=
"订单编号不能为空"
)
String
orderCode
,
@RequestParam
(
value
=
"clientIp"
)
@NotNull
(
message
=
"客户端ip不能为空"
)
String
clientIp
,
@RequestParam
(
value
=
"notifyUrl"
)
@NotNull
(
message
=
"通知Url不能为空"
)
String
notifyUrl
,
@RequestParam
(
value
=
"returnUrl"
,
required
=
false
)
String
returnUrl
,
@RequestParam
(
value
=
"quitUrl"
,
required
=
false
)
String
quitUrl
,
@RequestParam
(
value
=
"showUrl"
,
required
=
false
)
String
showUrl
,
@RequestParam
(
value
=
"code"
,
required
=
false
)
String
code
,
@RequestParam
(
value
=
"createDate"
,
required
=
false
)
String
createDate
,
@RequestParam
(
value
=
"expireTime"
,
required
=
false
)
String
expireTime
){
DragonPayBaseReqDto
dragonPayBaseReqDto
=
new
DragonPayBaseReqDto
();
dragonPayBaseReqDto
.
setType
(
type
);
dragonPayBaseReqDto
.
setPrice
(
price
);
dragonPayBaseReqDto
.
setName
(
name
);
dragonPayBaseReqDto
.
setDetail
(
detail
);
dragonPayBaseReqDto
.
setOrderCode
(
orderCode
);
dragonPayBaseReqDto
.
setClientIp
(
clientIp
);
dragonPayBaseReqDto
.
setNotifyUrl
(
notifyUrl
);
return
dragonOrdersService
.
alipay
(
dragonPayBaseReqDto
);
}
}
// /**
// * 手机网页支付宝支付
// * @return
// */
// @PostMapping("/wap/alipay")
// @ApiOperation("支付宝wap支付")
// @ApiResponse(code = 200, message = "接口返回对象参数")
// @ApiImplicitParams({
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "type", value = "支付类型:TICKET,PRODUCT,COST,MBEANS,LIVE,VIDEO,VIP,CLUB,STRAWBERRY", example = "TICKET"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "price", value = "支付金额", example = "0.1"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "name", value = "订单名称", example = "测试订单001"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "detail", value = "订单描述", example = "测试订单001"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderCode", value = "订单编号", example = "ORDER0001"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "clientIp", value = "客户端ip", example = "127.0.0.1"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "notifyUrl", value = "通知url", example = "pay.zhengzai.tv"),
// })
// public ResponseDto<DragonPayBaseRespDto> wapAlipay(@RequestParam(value = "type") @NotNull(message = "支付类型不能为空") String type,
// @RequestParam(value = "price") @NotNull(message = "支付金额不能为空") BigDecimal price,
// @RequestParam(value = "name") @NotNull(message = "订单名称不能为空") String name,
// @RequestParam(value = "detail") @NotNull(message = "订单描述不能为空") String detail,
// @RequestParam(value = "orderCode") @NotNull(message = "订单编号不能为空") String orderCode,
// @RequestParam(value = "clientIp") @NotNull(message = "客户端ip不能为空") String clientIp,
// @RequestParam(value = "notifyUrl") @NotNull(message = "通知Url不能为空") String notifyUrl,
// @RequestParam(value = "returnUrl",required = false) String returnUrl,
// @RequestParam(value = "quitUrl",required = false) String quitUrl,
// @RequestParam(value = "showUrl",required = false) String showUrl,
// @RequestParam(value = "code",required = false) String code,
// @RequestParam(value = "createDate",required = false) String createDate,
// @RequestParam(value = "expireTime",required = false) String expireTime){
// DragonPayBaseReqDto dragonPayBaseReqDto = new DragonPayBaseReqDto();
// dragonPayBaseReqDto.setType(type);
// dragonPayBaseReqDto.setPrice(price);
// dragonPayBaseReqDto.setName(name);
// dragonPayBaseReqDto.setDetail(detail);
// dragonPayBaseReqDto.setOrderCode(orderCode);
// dragonPayBaseReqDto.setClientIp(clientIp);
// dragonPayBaseReqDto.setNotifyUrl(notifyUrl);
// return dragonOrdersService.alipay(dragonPayBaseReqDto);
// }
//
// /**
// /**
// * 电脑网页微信支付
// * 电脑网页微信支付
// * @return
// * @return
...
@@ -124,10 +128,39 @@ public class PayController {
...
@@ -124,10 +128,39 @@ public class PayController {
// @PostMapping("/web/wepay")
// @PostMapping("/web/wepay")
// @ApiOperation("微信web支付")
// @ApiOperation("微信web支付")
// @ApiResponse(code = 200, message = "接口返回对象参数")
// @ApiResponse(code = 200, message = "接口返回对象参数")
// public DragonPayBaseRespDto webWepay(){
// @ApiImplicitParams({
// return null;
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "type", value = "支付类型:TICKET,PRODUCT,COST,MBEANS,LIVE,VIDEO,VIP,CLUB,STRAWBERRY", example = "TICKET"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "price", value = "支付金额", example = "0.1"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "name", value = "订单名称", example = "测试订单001"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "detail", value = "订单描述", example = "测试订单001"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "orderCode", value = "订单编号", example = "ORDER0001"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "clientIp", value = "客户端ip", example = "127.0.0.1"),
// @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "notifyUrl", value = "通知url", example = "pay.zhengzai.tv"),
// })
// public ResponseDto<DragonPayBaseRespDto> webWepay(@RequestParam(value = "type") @NotNull(message = "支付类型不能为空") String type,
// @RequestParam(value = "price") @NotNull(message = "支付金额不能为空") BigDecimal price,
// @RequestParam(value = "name") @NotNull(message = "订单名称不能为空") String name,
// @RequestParam(value = "detail") @NotNull(message = "订单描述不能为空") String detail,
// @RequestParam(value = "orderCode") @NotNull(message = "订单编号不能为空") String orderCode,
// @RequestParam(value = "clientIp") @NotNull(message = "客户端ip不能为空") String clientIp,
// @RequestParam(value = "notifyUrl") @NotNull(message = "通知Url不能为空") String notifyUrl,
// @RequestParam(value = "returnUrl",required = false) String returnUrl,
// @RequestParam(value = "quitUrl",required = false) String quitUrl,
// @RequestParam(value = "showUrl",required = false) String showUrl,
// @RequestParam(value = "code",required = false) String code,
// @RequestParam(value = "createDate",required = false) String createDate,
// @RequestParam(value = "expireTime",required = false) String expireTime){
// DragonPayBaseReqDto dragonPayBaseReqDto = new DragonPayBaseReqDto();
// dragonPayBaseReqDto.setType(type);
// dragonPayBaseReqDto.setPrice(price);
// dragonPayBaseReqDto.setName(name);
// dragonPayBaseReqDto.setDetail(detail);
// dragonPayBaseReqDto.setOrderCode(orderCode);
// dragonPayBaseReqDto.setClientIp(clientIp);
// dragonPayBaseReqDto.setNotifyUrl(notifyUrl);
// return dragonOrdersService.wepay(dragonPayBaseReqDto);
// }
// }
//
//
//
// /**
// /**
...
...
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/service/impl/DragonOrdersServiceImpl.java
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
service
.
impl
;
package
com
.
liquidnet
.
service
.
dragon
.
service
.
impl
;
import
com.liquidnet.commons.lang.util.IDGenerator
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.base.SqlMapping
;
import
com.liquidnet.service.dragon.channel.strategy.PayChannelStrategyContext
;
import
com.liquidnet.service.dragon.channel.alipay.req.AlipayTradePayReq
;
import
com.liquidnet.service.dragon.channel.alipay.util.AlipayUtil
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseRespDto
;
import
com.liquidnet.service.dragon.entity.DragonOrders
;
import
com.liquidnet.service.dragon.service.IDragonOrdersService
;
import
com.liquidnet.service.dragon.service.IDragonOrdersService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.connection.stream.MapRecord
;
import
org.springframework.data.redis.connection.stream.MapRecord
;
import
org.springframework.data.redis.connection.stream.StreamRecords
;
import
org.springframework.data.redis.connection.stream.StreamRecords
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.Map
;
@Slf4j
@Service
@Service
public
class
DragonOrdersServiceImpl
implements
IDragonOrdersService
{
public
class
DragonOrdersServiceImpl
implements
IDragonOrdersService
{
@Autowired
@Autowired
StringRedisTemplate
stringRedisTemplate
;
StringRedisTemplate
stringRedisTemplate
;
@Value
(
"liquidnet.dragon.alipay-gataway-url"
)
private
String
alipayGatewayUrl
;
@Autowired
private
PayChannelStrategyContext
payChannelStrategyContext
;
@Override
@Override
public
void
sendRedisQueue
()
{
public
void
sendRedisQueue
()
{
...
@@ -42,81 +36,7 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
...
@@ -42,81 +36,7 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
}
}
@Override
@Override
public
ResponseDto
<
DragonPayBaseRespDto
>
alipay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
AlipayTradePayReq
alipayTradePayReq
=
new
AlipayTradePayReq
();
return
payChannelStrategyContext
.
getStrategy
(
dragonPayBaseReqDto
.
getPayType
()).
dragonPay
(
dragonPayBaseReqDto
);
alipayTradePayReq
.
setProductCode
(
"QUICK_WAP_PAY"
);
alipayTradePayReq
.
setTotalAmount
(
dragonPayBaseReqDto
.
getPrice
());
alipayTradePayReq
.
setSubject
(
dragonPayBaseReqDto
.
getName
());
alipayTradePayReq
.
setBody
(
dragonPayBaseReqDto
.
getDetail
());
//dragon中支付编号
alipayTradePayReq
.
setOutTradeNo
(
IDGenerator
.
payCode
());
alipayTradePayReq
.
setTimeExpire
(
dragonPayBaseReqDto
.
getExpireTime
());
Map
<
String
,
Object
>
result
=
AlipayUtil
.
tradeWapPay
(
alipayTradePayReq
);
DragonPayBaseRespDto
respDto
=
new
DragonPayBaseRespDto
();
respDto
.
setCode
(
alipayTradePayReq
.
getOutTradeNo
());
respDto
.
setOrder_code
(
dragonPayBaseReqDto
.
getOrderCode
());
DragonPayBaseRespDto
.
PayData
payData
=
new
DragonPayBaseRespDto
.
PayData
();
payData
.
setRedirectUrl
(
alipayGatewayUrl
+
result
.
get
(
"body"
));
respDto
.
setPay_data
(
payData
);
//支付订单持久化
this
.
buildPayOrders
(
dragonPayBaseReqDto
,
respDto
);
return
ResponseDto
.
success
(
respDto
);
}
private
DragonOrders
buildPayOrders
(
DragonPayBaseReqDto
dragonPayBaseReqDto
,
DragonPayBaseRespDto
respDto
){
DragonOrders
orders
=
new
DragonOrders
();
// orders.setMid();
orders
.
setStatus
(
Integer
.
valueOf
(
DragonConstant
.
PayStatusEnum
.
STATUS_UNPAID
.
getCode
()));
orders
.
setCode
(
respDto
.
getCode
());
orders
.
setType
(
dragonPayBaseReqDto
.
getType
());
orders
.
setPrice
(
dragonPayBaseReqDto
.
getPrice
());
orders
.
setName
(
dragonPayBaseReqDto
.
getName
());
orders
.
setDetail
(
dragonPayBaseReqDto
.
getDetail
());
orders
.
setOrderCode
(
dragonPayBaseReqDto
.
getOrderCode
());
orders
.
setClientIp
(
dragonPayBaseReqDto
.
getClientIp
());
orders
.
setNotifyUrl
(
dragonPayBaseReqDto
.
getNotifyUrl
());
orders
.
setPaymentType
(
DragonConstant
.
PayTypeEnum
.
PAYMENT_TYPE_APP_IAP
.
getCode
());
// orders.setPaymentId();
orders
.
setPaymentAt
(
LocalDateTime
.
now
());
// orders.setFinishedAt();
orders
.
setCreatedAt
(
LocalDateTime
.
now
());
// orders.setUpdatedAt();
// 修改退款订单
boolean
insertResult
=
sendMySqlRedis
(
SqlMapping
.
get
(
"dragon_orders.insert"
),
new
Object
[]{
orders
.
getStatus
(),
orders
.
getCode
(),
orders
.
getType
()
,
orders
.
getPrice
(),
orders
.
getName
(),
orders
.
getDetail
()
,
orders
.
getOrderCode
(),
orders
.
getClientIp
()
,
orders
.
getNotifyUrl
(),
orders
.
getPaymentType
(),
orders
.
getPaymentId
(),
orders
.
getPaymentAt
()
,
orders
.
getFinishedAt
(),
orders
.
getCreatedAt
()
,
orders
.
getUpdatedAt
()}
);
return
orders
;
}
/**
* 给 REDIS 队列发送消息 数据库相关
*
* @param sql sql语句
* @param data 需要操作的数据
* @return
*/
private
boolean
sendMySqlRedis
(
String
sql
,
Object
[]
data
)
{
try
{
LinkedList
<
String
>
sqls
=
new
LinkedList
<>();
sqls
.
add
(
sql
);
LinkedList
<
Object
[]>
sqlsData
=
new
LinkedList
();
sqlsData
.
add
(
data
);
String
sqlData
=
SqlMapping
.
gets
(
sqls
,
sqlsData
);
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"message"
,
sqlData
);
MapRecord
<
String
,
String
,
String
>
record
=
StreamRecords
.
mapBacked
(
map
).
withStreamKey
(
DragonConstant
.
MysqlRedisQueueEnum
.
DRAGON_PAY_KEY
.
getCode
());
stringRedisTemplate
.
opsForStream
().
add
(
record
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
}
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/utils/MqHandleUtil.java
0 → 100644
View file @
37864a81
package
com
.
liquidnet
.
service
.
dragon
.
utils
;
import
com.liquidnet.service.base.SqlMapping
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.connection.stream.MapRecord
;
import
org.springframework.data.redis.connection.stream.StreamRecords
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: MqHandleUtil
* @Package com.liquidnet.service.dragon.utils
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/7/10 16:23
*/
@Component
public
class
MqHandleUtil
{
@Autowired
StringRedisTemplate
stringRedisTemplate
;
/**
* 给 REDIS 队列发送消息 数据库相关
*
* @param sql sql语句
* @param data 需要操作的数据
* @return
*/
public
boolean
sendMySqlRedis
(
String
sql
,
Object
[]
data
)
{
try
{
LinkedList
<
String
>
sqls
=
new
LinkedList
<>();
sqls
.
add
(
sql
);
LinkedList
<
Object
[]>
sqlsData
=
new
LinkedList
();
sqlsData
.
add
(
data
);
String
sqlData
=
SqlMapping
.
gets
(
sqls
,
sqlsData
);
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"message"
,
sqlData
);
MapRecord
<
String
,
String
,
String
>
record
=
StreamRecords
.
mapBacked
(
map
).
withStreamKey
(
DragonConstant
.
MysqlRedisQueueEnum
.
DRAGON_PAY_KEY
.
getCode
());
stringRedisTemplate
.
opsForStream
().
add
(
record
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
}
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