Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
liuxu0511
jeepay
提交
21517577
jeepay
项目概览
liuxu0511
/
jeepay
与 Fork 源项目一致
Fork自
计全科技 / jeepay
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
jeepay
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
21517577
编写于
4月 12, 2018
作者:
C
cbwleft
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
使用RestTemplate替换HttpsURLConnection,并解决商户通知报4XX或者5XX导致无法收到重复通知的问题。
上级
8a195cab
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
63 deletion
+24
-63
xxpay4spring-boot/src/main/java/org/xxpay/boot/XxPayBootAppliaction.java
...ot/src/main/java/org/xxpay/boot/XxPayBootAppliaction.java
+10
-0
xxpay4spring-boot/src/main/java/org/xxpay/boot/service/mq/Mq4PayNotify.java
...src/main/java/org/xxpay/boot/service/mq/Mq4PayNotify.java
+14
-63
未找到文件。
xxpay4spring-boot/src/main/java/org/xxpay/boot/XxPayBootAppliaction.java
浏览文件 @
21517577
...
...
@@ -2,7 +2,10 @@ package org.xxpay.boot;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.web.client.RestTemplate
;
/**
*
...
...
@@ -10,6 +13,13 @@ import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan
(
basePackages
={
"org.xxpay"
})
public
class
XxPayBootAppliaction
{
@Bean
public
RestTemplate
restTemplate
(
RestTemplateBuilder
builder
)
{
// Do any additional configuration here
return
builder
.
build
();
}
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
XxPayBootAppliaction
.
class
,
args
);
}
...
...
xxpay4spring-boot/src/main/java/org/xxpay/boot/service/mq/Mq4PayNotify.java
浏览文件 @
21517577
...
...
@@ -9,6 +9,7 @@ import org.springframework.jms.core.JmsTemplate;
import
org.springframework.jms.core.MessageCreator
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.client.RestTemplate
;
import
org.xxpay.common.util.MyLog
;
import
org.xxpay.boot.service.BaseService
;
...
...
@@ -20,6 +21,7 @@ import javax.net.ssl.X509TrustManager;
import
java.io.BufferedReader
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URI
;
import
java.net.URL
;
import
java.security.cert.CertificateException
;
import
java.security.cert.X509Certificate
;
...
...
@@ -41,6 +43,9 @@ public class Mq4PayNotify extends BaseService {
@Autowired
private
JmsTemplate
jmsTemplate
;
@Autowired
private
RestTemplate
restTemplate
;
private
static
final
MyLog
_log
=
MyLog
.
getLog
(
Mq4PayNotify
.
class
);
...
...
@@ -67,21 +72,6 @@ public class Mq4PayNotify extends BaseService {
});
}
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
[]
{};
}
}
@JmsListener
(
destination
=
MqConfig
.
PAY_NOTIFY_QUEUE_NAME
)
public
void
receive
(
String
msg
)
{
_log
.
info
(
"do notify task, msg={}"
,
msg
);
...
...
@@ -94,57 +84,18 @@ public class Mq4PayNotify extends BaseService {
return
;
}
try
{
StringBuffer
sb
=
new
StringBuffer
();
URL
console
=
new
URL
(
respUrl
);
String
notifyResult
=
""
;
_log
.
info
(
"==>MQ通知业务系统开始[orderId:{}][count:{}][time:{}]"
,
orderId
,
count
,
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
new
Date
()));
if
(
"https"
.
equals
(
console
.
getProtocol
()))
{
SSLContext
sc
=
SSLContext
.
getInstance
(
"SSL"
);
sc
.
init
(
null
,
new
TrustManager
[]
{
new
TrustAnyTrustManager
()
},
new
java
.
security
.
SecureRandom
());
HttpsURLConnection
con
=
(
HttpsURLConnection
)
console
.
openConnection
();
con
.
setSSLSocketFactory
(
sc
.
getSocketFactory
());
con
.
setRequestMethod
(
"POST"
);
con
.
setDoInput
(
true
);
con
.
setDoOutput
(
true
);
con
.
setUseCaches
(
false
);
con
.
setConnectTimeout
(
10
*
1000
);
con
.
setReadTimeout
(
5
*
1000
);
con
.
setRequestProperty
(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
con
.
getInputStream
()),
1024
*
1024
);
while
(
true
)
{
String
line
=
in
.
readLine
();
if
(
line
==
null
)
{
break
;
}
sb
.
append
(
line
);
}
in
.
close
();
}
else
if
(
"http"
.
equals
(
console
.
getProtocol
()))
{
HttpURLConnection
con
=
(
HttpURLConnection
)
console
.
openConnection
();
con
.
setRequestMethod
(
"POST"
);
con
.
setDoInput
(
true
);
con
.
setDoOutput
(
true
);
con
.
setUseCaches
(
false
);
con
.
setConnectTimeout
(
10
*
1000
);
con
.
setReadTimeout
(
5
*
1000
);
con
.
setRequestProperty
(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
con
.
getInputStream
()),
1024
*
1024
);
while
(
true
)
{
String
line
=
in
.
readLine
();
if
(
line
==
null
)
{
break
;
}
sb
.
append
(
line
);
}
in
.
close
();
}
else
{
_log
.
error
(
"not do protocol. protocol=%s"
,
console
.
getProtocol
());
return
;
}
try
{
URI
uri
=
new
URI
(
respUrl
);
notifyResult
=
restTemplate
.
postForObject
(
uri
,
null
,
String
.
class
);
}
catch
(
Exception
e
)
{
_log
.
error
(
e
,
"通知商户系统异常"
);
}
_log
.
info
(
"<==MQ通知业务系统结束[orderId:{}][count:{}][time:{}]"
,
orderId
,
count
,
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
new
Date
()));
// 验证结果
_log
.
info
(
"notify response , OrderID={}"
,
orderId
);
if
(
sb
.
toString
()
.
trim
().
equalsIgnoreCase
(
"success"
)){
if
(
notifyResult
.
trim
().
equalsIgnoreCase
(
"success"
)){
//_log.info("{} notify success, url:{}", _notifyInfo.getBusiId(), respUrl);
//修改订单表
try
{
...
...
@@ -180,7 +131,7 @@ public class Mq4PayNotify extends BaseService {
msgObj
.
put
(
"count"
,
cnt
);
this
.
send
(
msgObj
.
toJSONString
(),
cnt
*
60
*
1000
);
}
_log
.
warn
(
"notify failed. url:{}, response body:{}"
,
respUrl
,
sb
.
toString
());
_log
.
warn
(
"notify failed. url:{}, response body:{}"
,
respUrl
,
notifyResult
.
toString
());
}
catch
(
Exception
e
)
{
_log
.
info
(
"<==MQ通知业务系统结束[orderId:{}][count:{}][time:{}]"
,
orderId
,
count
,
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
new
Date
()));
_log
.
error
(
e
,
"notify exception. url:%s"
,
respUrl
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录