记得上下班打卡 | 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
a1631329
Commit
a1631329
authored
Apr 08, 2022
by
zhengfuxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
开发苹果支付。
parent
b1468aa8
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
266 additions
and
5 deletions
+266
-5
ApplePayRefundDto.java
...a/com/liquidnet/service/dragon/dto/ApplePayRefundDto.java
+13
-0
DragonPayBaseReqDto.java
...com/liquidnet/service/dragon/dto/DragonPayBaseReqDto.java
+3
-0
IDragonOrdersService.java
...iquidnet/service/dragon/service/IDragonOrdersService.java
+1
-0
liquidnet-service-dragon-dev.yml
...-config/liquidnet-config/liquidnet-service-dragon-dev.yml
+3
-0
liquidnet-service-dragon.yml
...-bus-config/liquidnet-config/liquidnet-service-dragon.yml
+3
-1
PayNotifyController.java
...uidnet/service/dragon/controller/PayNotifyController.java
+72
-4
DragonOrdersServiceImpl.java
.../service/dragon/service/impl/DragonOrdersServiceImpl.java
+74
-0
ApplepayUtils.java
...ava/com/liquidnet/service/dragon/utils/ApplepayUtils.java
+97
-0
No files found.
liquidnet-bus-api/liquidnet-service-dragon-api/src/main/java/com/liquidnet/service/dragon/dto/ApplePayRefundDto.java
0 → 100644
View file @
a1631329
package
com
.
liquidnet
.
service
.
dragon
.
dto
;
import
lombok.Data
;
import
java.io.Serializable
;
@Data
public
class
ApplePayRefundDto
implements
Serializable
{
private
static
final
long
serialVersionUID
=
5272393180371552646L
;
private
String
productId
;
}
liquidnet-bus-api/liquidnet-service-dragon-api/src/main/java/com/liquidnet/service/dragon/dto/DragonPayBaseReqDto.java
View file @
a1631329
...
@@ -36,6 +36,9 @@ public class DragonPayBaseReqDto implements Serializable, Cloneable{
...
@@ -36,6 +36,9 @@ public class DragonPayBaseReqDto implements Serializable, Cloneable{
private
String
showUrl
;
private
String
showUrl
;
private
String
returnUrl
;
private
String
returnUrl
;
private
String
authCode
;
private
String
authCode
;
private
String
receiptData
;
//苹果的stransactionId
private
String
transactionId
;
@Override
@Override
public
String
toString
(){
public
String
toString
(){
...
...
liquidnet-bus-api/liquidnet-service-dragon-api/src/main/java/com/liquidnet/service/dragon/service/IDragonOrdersService.java
View file @
a1631329
...
@@ -15,4 +15,5 @@ public interface IDragonOrdersService {
...
@@ -15,4 +15,5 @@ public interface IDragonOrdersService {
DragonPayOrderQueryRespDto
checkOrderStatusByCode
(
String
code
);
DragonPayOrderQueryRespDto
checkOrderStatusByCode
(
String
code
);
boolean
manulNotify
(
String
code
);
boolean
manulNotify
(
String
code
);
void
dragonNotifyApple
(
DragonPayBaseReqDto
dragonPayBaseReqDto
);
}
}
liquidnet-bus-config/liquidnet-config/liquidnet-service-dragon-dev.yml
View file @
a1631329
...
@@ -38,4 +38,7 @@ liquidnet:
...
@@ -38,4 +38,7 @@ liquidnet:
certs-path
:
/data/certs/dragon/unionpay/test
certs-path
:
/data/certs/dragon/unionpay/test
certs-prefix
:
acp_test
certs-prefix
:
acp_test
pfx-pwd
:
'
520360'
pfx-pwd
:
'
520360'
apple
:
urlVerify
:
https://sandbox.itunes.apple.com/verifyReceipt
liquidnet-bus-config/liquidnet-config/liquidnet-service-dragon.yml
View file @
a1631329
...
@@ -142,4 +142,6 @@ acpsdk:
...
@@ -142,4 +142,6 @@ acpsdk:
# 验签中级证书路径(银联提供)
# 验签中级证书路径(银联提供)
middleCertPath
:
${liquidnet.dragon.unionpay.certs-path}/${liquidnet.dragon.unionpay.certs-prefix}_middle.cer
middleCertPath
:
${liquidnet.dragon.unionpay.certs-path}/${liquidnet.dragon.unionpay.certs-prefix}_middle.cer
# 验签根证书路径(银联提供)
# 验签根证书路径(银联提供)
rootCertPath
:
${liquidnet.dragon.unionpay.certs-path}/${liquidnet.dragon.unionpay.certs-prefix}_root.cer
rootCertPath
:
${liquidnet.dragon.unionpay.certs-path}/${liquidnet.dragon.unionpay.certs-prefix}_root.cer
\ No newline at end of file
apple
:
urlVerify
:
${liquidnet.dragon.apple.urlVerify}
\ No newline at end of file
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/controller/PayNotifyController.java
View file @
a1631329
package
com
.
liquidnet
.
service
.
dragon
.
controller
;
package
com
.
liquidnet
.
service
.
dragon
.
controller
;
import
com.liquidnet.commons.lang.util.IDGenerator
;
import
com.liquidnet.commons.lang.util.StringUtil
;
import
com.liquidnet.service.dragon.dto.DragonPayBaseReqDto
;
import
com.liquidnet.service.dragon.service.IDragonOrdersService
;
import
com.liquidnet.service.dragon.service.IDragonOrdersService
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiResponse
;
import
io.swagger.annotations.ApiResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.constraints.NotNull
;
import
java.math.BigDecimal
;
/**
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @author AnJiabin <anjiabin@zhengzai.tv>
...
@@ -41,4 +43,70 @@ public class PayNotifyController {
...
@@ -41,4 +43,70 @@ public class PayNotifyController {
public
String
dragonNotify
(
@PathVariable
(
"payType"
)
String
payType
,
@PathVariable
(
"deviceFrom"
)
String
deviceFrom
,
HttpServletRequest
request
,
HttpServletResponse
respone
)
throws
Exception
{
public
String
dragonNotify
(
@PathVariable
(
"payType"
)
String
payType
,
@PathVariable
(
"deviceFrom"
)
String
deviceFrom
,
HttpServletRequest
request
,
HttpServletResponse
respone
)
throws
Exception
{
return
dragonOrdersService
.
dragonNotify
(
request
,
payType
,
deviceFrom
);
return
dragonOrdersService
.
dragonNotify
(
request
,
payType
,
deviceFrom
);
}
}
/**
* 苹果内购
*/
@PostMapping
(
"/apple/purchase"
)
@ApiOperation
(
"苹果内购回调"
)
@ApiResponse
(
code
=
200
,
message
=
"接口返回对象参数"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"payType"
,
value
=
"支付类型:alipay,wepay,unionpay,applepay"
,
example
=
"unionpay"
),
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"deviceFrom"
,
value
=
"设备来源:web,wap,app,js,apple,micropay,innerPurchase"
,
example
=
"wap"
),
@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
=
"orderId"
,
value
=
"订单id"
,
example
=
"orderId"
),
@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
=
"devdragon.zhengzai.tv"
),
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"createDate"
,
value
=
"订单创建时间"
,
example
=
"2021-11-10 13:00:00"
),
@ApiImplicitParam
(
type
=
"form"
,
required
=
true
,
dataType
=
"String"
,
name
=
"expireTime"
,
value
=
"订单过期时间"
,
example
=
"1000"
),
@ApiImplicitParam
(
type
=
"form"
,
required
=
false
,
dataType
=
"String"
,
name
=
"authCode"
,
value
=
"付款码"
,
example
=
"1000"
),
})
public
String
dragonNotifyApple
(
@RequestParam
(
value
=
"payType"
)
@NotNull
(
message
=
"支付类型不能为空"
)
String
payType
,
@RequestParam
(
value
=
"deviceFrom"
)
@NotNull
(
message
=
"设备来源不能为空"
)
String
deviceFrom
,
@RequestParam
(
value
=
"openId"
,
required
=
false
)
String
openId
,
@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
=
"orderId"
,
required
=
false
)
String
orderId
,
@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
=
"showUrl"
,
required
=
false
)
String
showUrl
,
@RequestParam
(
value
=
"createDate"
,
required
=
true
)
String
createDate
,
@RequestParam
(
value
=
"expireTime"
,
required
=
true
)
String
expireTime
,
@RequestParam
(
value
=
"authCode"
,
required
=
false
)
String
authCode
)
throws
Exception
{
long
startTime
=
System
.
currentTimeMillis
();
DragonPayBaseReqDto
dragonPayBaseReqDto
=
DragonPayBaseReqDto
.
getNew
();
dragonPayBaseReqDto
.
setPayType
(
payType
);
dragonPayBaseReqDto
.
setDeviceFrom
(
deviceFrom
);
dragonPayBaseReqDto
.
setType
(
type
);
dragonPayBaseReqDto
.
setPrice
(
price
);
dragonPayBaseReqDto
.
setAuthCode
(
authCode
);
if
(
StringUtil
.
isNotNull
(
name
)&&
name
.
length
()>=
32
){
name
=
name
.
substring
(
0
,
32
);
}
dragonPayBaseReqDto
.
setName
(
name
);
dragonPayBaseReqDto
.
setDetail
(
"正在现场"
);
dragonPayBaseReqDto
.
setOrderCode
(
orderCode
);
if
(
orderId
!=
null
)
{
dragonPayBaseReqDto
.
setOrderId
(
orderId
);
}
dragonPayBaseReqDto
.
setClientIp
(
clientIp
);
dragonPayBaseReqDto
.
setNotifyUrl
(
notifyUrl
);
dragonPayBaseReqDto
.
setReturnUrl
(
returnUrl
);
dragonPayBaseReqDto
.
setShowUrl
(
showUrl
);
dragonPayBaseReqDto
.
setCreateDate
(
createDate
);
dragonPayBaseReqDto
.
setExpireTime
(
expireTime
);
dragonPayBaseReqDto
.
setCode
(
IDGenerator
.
payCode
());
/* return dragonOrdersService.dragonNotify(request,payType,deviceFrom);*/
return
null
;
}
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/service/impl/DragonOrdersServiceImpl.java
View file @
a1631329
package
com
.
liquidnet
.
service
.
dragon
.
service
.
impl
;
package
com
.
liquidnet
.
service
.
dragon
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.liquidnet.common.exception.LiquidnetServiceException
;
import
com.liquidnet.common.exception.LiquidnetServiceException
;
import
com.liquidnet.commons.lang.util.IDGenerator
;
import
com.liquidnet.commons.lang.util.IDGenerator
;
import
com.liquidnet.commons.lang.util.StringUtil
;
import
com.liquidnet.commons.lang.util.StringUtil
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.base.ResponseDto
;
import
com.liquidnet.service.dragon.biz.DragonServiceCommonBiz
;
import
com.liquidnet.service.dragon.channel.strategy.PayChannelStrategyContext
;
import
com.liquidnet.service.dragon.channel.strategy.PayChannelStrategyContext
;
import
com.liquidnet.service.dragon.channel.strategy.biz.DragonPayBiz
;
import
com.liquidnet.service.dragon.channel.strategy.biz.DragonPayBiz
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
import
com.liquidnet.service.dragon.constant.DragonConstant
;
...
@@ -13,17 +16,29 @@ import com.liquidnet.service.dragon.dto.DragonPayBaseReqDto;
...
@@ -13,17 +16,29 @@ 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.dto.DragonPayOrderQueryRespDto
;
import
com.liquidnet.service.dragon.dto.DragonPayOrderQueryRespDto
;
import
com.liquidnet.service.dragon.service.IDragonOrdersService
;
import
com.liquidnet.service.dragon.service.IDragonOrdersService
;
import
com.liquidnet.service.dragon.utils.ApplepayUtils
;
import
com.liquidnet.service.dragon.utils.DataUtils
;
import
com.liquidnet.service.dragon.utils.DataUtils
;
import
lombok.extern.slf4j.Slf4j
;
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.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
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
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
@Slf4j
@Slf4j
@Service
@Service
public
class
DragonOrdersServiceImpl
implements
IDragonOrdersService
{
public
class
DragonOrdersServiceImpl
implements
IDragonOrdersService
{
@Value
(
"${apple.urlVerify}"
)
private
String
appleUrl
;
@Autowired
@Autowired
StringRedisTemplate
stringRedisTemplate
;
StringRedisTemplate
stringRedisTemplate
;
...
@@ -35,6 +50,8 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
...
@@ -35,6 +50,8 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
@Autowired
@Autowired
private
DragonPayBiz
dragonPayBiz
;
private
DragonPayBiz
dragonPayBiz
;
@Autowired
private
DragonServiceCommonBiz
dragonServiceCommonBiz
;
@Override
@Override
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
public
ResponseDto
<
DragonPayBaseRespDto
>
dragonPay
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
...
@@ -74,4 +91,61 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
...
@@ -74,4 +91,61 @@ public class DragonOrdersServiceImpl implements IDragonOrdersService {
//通知商户
//通知商户
return
dragonPayBiz
.
sendNotify
(
dragonPayBiz
.
buildPayNotifyReqBo
(
ordersDto
));
return
dragonPayBiz
.
sendNotify
(
dragonPayBiz
.
buildPayNotifyReqBo
(
ordersDto
));
}
}
/**
* 苹果支付
* @param dragonPayBaseReqDto
*/
@Override
public
void
dragonNotifyApple
(
DragonPayBaseReqDto
dragonPayBaseReqDto
)
{
//1 调用苹果查询结果
String
verifyResult
=
buyAppVerify
(
dragonPayBaseReqDto
.
getReceiptData
());
if
(
verifyResult
==
null
)
{
// 苹果服务器没有返回验证结果
log
.
info
(
"苹果支付,app调用,查不到订单信息"
);
}
else
{
JSONObject
job
=
JSONObject
.
parseObject
(
verifyResult
);
String
states
=
job
.
getString
(
"status"
);
if
(
states
.
equals
(
"0"
)){
// 前端所提供的收据是有效的 验证成功
String
r_receipt
=
job
.
getString
(
"receipt"
);
JSONObject
returnJson
=
JSONObject
.
parseObject
(
r_receipt
);
String
in_app
=
returnJson
.
getString
(
"in_app"
);
JSONObject
in_appJson
=
JSONObject
.
parseObject
(
in_app
.
substring
(
1
,
in_app
.
length
()
-
1
));
String
product_id
=
in_appJson
.
getString
(
"product_id"
);
String
transaction_id
=
in_appJson
.
getString
(
"transaction_id"
);
// 订单号
//如果单号一致 则开始处理逻辑
if
(
dragonPayBaseReqDto
.
getTransactionId
().
equals
(
transaction_id
)){
String
[]
moneys
=
product_id
.
split
(
"\\."
);
//实际支付金额
//此处开始业务逻辑
}
}
else
{
}
}
//2 插入支付该支付的东西(预支付的东西)//dragon_orders
dragonServiceCommonBiz
.
buildPayOrders
(
dragonPayBaseReqDto
,
null
);
}
public
String
buyAppVerify
(
String
receipt
)
{
try
{
SortedMap
<
String
,
Object
>
parameters
=
new
TreeMap
<>();
parameters
.
put
(
"receipt-data"
,
receipt
);
String
data
=
JSON
.
toJSONString
(
parameters
);
HttpPost
httpost
=
new
HttpPost
(
appleUrl
);
httpost
.
setEntity
(
new
StringEntity
(
data
,
"UTF-8"
));
CloseableHttpResponse
response
=
ApplepayUtils
.
getInstance
().
getHttpClient
().
execute
(
httpost
);
HttpEntity
entity
=
response
.
getEntity
();
//接受到返回信息
String
returnDate
=
EntityUtils
.
toString
(
response
.
getEntity
(),
"UTF-8"
);
EntityUtils
.
consume
(
entity
);
log
.
info
(
"苹果支付完成后查询{} "
,
returnDate
);
}
catch
(
Exception
e
){
log
.
error
(
e
.
getMessage
());
}
return
null
;
}
}
}
liquidnet-bus-service/liquidnet-service-dragon/liquidnet-service-dragon-impl/src/main/java/com/liquidnet/service/dragon/utils/ApplepayUtils.java
0 → 100644
View file @
a1631329
package
com
.
liquidnet
.
service
.
dragon
.
utils
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.config.Registry
;
import
org.apache.http.config.RegistryBuilder
;
import
org.apache.http.conn.socket.ConnectionSocketFactory
;
import
org.apache.http.conn.socket.PlainConnectionSocketFactory
;
import
org.apache.http.conn.ssl.SSLConnectionSocketFactory
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.DefaultHttpRequestRetryHandler
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.TrustManager
;
import
javax.net.ssl.X509TrustManager
;
import
java.security.cert.CertificateException
;
import
java.security.cert.X509Certificate
;
public
class
ApplepayUtils
{
private
static
class
TrustAnyTrustManager
implements
X509TrustManager
{
public
void
checkClientTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
}
public
void
checkServerTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
}
public
X509Certificate
[]
getAcceptedIssuers
()
{
return
new
X509Certificate
[]
{};
}
}
private
CloseableHttpClient
httpClient
;
private
static
ApplepayUtils
instance
=
new
ApplepayUtils
();
// 池化管理
private
static
PoolingHttpClientConnectionManager
poolConnManager
=
null
;
public
ApplepayUtils
()
{
}
public
static
ApplepayUtils
getInstance
()
{
return
instance
;
}
public
CloseableHttpClient
getHttpClient
()
{
try
{
if
(
httpClient
==
null
)
{
/* SSLContext sslcontext = SSLContexts.custom()
.loadKeyMaterial(keyStore, merchantId.toCharArray())
.build();
*/
SSLContext
sslcontext
=
SSLContext
.
getInstance
(
"SSL"
);
sslcontext
.
init
(
null
,
new
TrustManager
[]
{
new
TrustAnyTrustManager
()
},
new
java
.
security
.
SecureRandom
());
SSLConnectionSocketFactory
sslsf
=
new
SSLConnectionSocketFactory
(
sslcontext
,
SSLConnectionSocketFactory
.
getDefaultHostnameVerifier
());
// 配置同时支持 HTTP 和 HTPPS
Registry
<
ConnectionSocketFactory
>
socketFactoryRegistry
=
RegistryBuilder
.<
ConnectionSocketFactory
>
create
().
register
(
"http"
,
PlainConnectionSocketFactory
.
getSocketFactory
()).
register
(
"https"
,
sslsf
).
build
();
// 初始化连接管理器
poolConnManager
=
new
PoolingHttpClientConnectionManager
(
socketFactoryRegistry
);
poolConnManager
.
setMaxTotal
(
4000
);
// 同时最多连接数
// 设置最大路由
poolConnManager
.
setDefaultMaxPerRoute
(
2000
);
// 初始化httpClient
httpClient
=
getConnection
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
httpClient
;
}
public
static
CloseableHttpClient
getConnection
()
{
RequestConfig
config
=
RequestConfig
.
custom
().
setConnectTimeout
(
5000
).
setConnectionRequestTimeout
(
5000
).
setSocketTimeout
(
5000
).
build
();
CloseableHttpClient
httpClient
=
HttpClients
.
custom
()
// 设置连接池管理
.
setConnectionManager
(
poolConnManager
)
.
setDefaultRequestConfig
(
config
)
// 设置重试次数
.
setRetryHandler
(
new
DefaultHttpRequestRetryHandler
(
2
,
false
)).
build
();
return
httpClient
;
}
public
static
void
main
(
String
[]
args
)
{
}
}
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