diff --git a/pom.xml b/pom.xml
index 7136b62..74dc24b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.tsl3060.open.extend
tsl-open-sdk-java-wanshun
- 0.3.7
+ 0.3.8
8
diff --git a/src/main/java/com/tsl3060/open/extend/core/ApiClient.java b/src/main/java/com/tsl3060/open/extend/core/ApiClient.java
index 6535823..4098ec6 100644
--- a/src/main/java/com/tsl3060/open/extend/core/ApiClient.java
+++ b/src/main/java/com/tsl3060/open/extend/core/ApiClient.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
+import java.util.concurrent.TimeUnit;
public class ApiClient {
@@ -140,6 +141,8 @@ public class ApiClient {
.post(requestBody)
.build();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
+ //设置连接超时时间
+ builder.connectTimeout(this.config.getTimeout(), TimeUnit.MILLISECONDS);
OkHttpClient okHttpClient = builder.build();
try {
Call call = okHttpClient.newCall(request);
@@ -196,30 +199,19 @@ public class ApiClient {
private NotifyMapRouter notifyMapRouter;
+
/**
* 验证回调数据
*
- * @return
+ * @param notifyRequest 回调请求
+ * @param accept 回调接收的类型
+ * @return 返回Body
+ * @throws BadResourceException
*/
- public String notifyRun(String raw, String contentType, String accept) throws BadResourceException {
+ public String notifyRun(NotifyRequest notifyRequest, String accept) throws BadResourceException {
if (notifyMapRouter == null) {
notifyMapRouter = new NotifyMapRouter(this.notifyListener);
}
- if (StrUtil.isEmpty(raw)) {
- throw new BadResourceException("通知内容为空");
- }
-
- NotifyRequest notifyRequest;
- if (contentType.contains("application/json")) {
- notifyRequest = JSON.parseObject(raw, NotifyRequest.class);
- } else if (contentType.contains("application/xml")) {
- //XML格式
- Document document = XmlUtil.parseXml(raw);
- //TODO 对XML解析
- throw new BadResourceException("暂不支持的格式");
- } else {
- throw new BadResourceException("不支持的数据格式");
- }
//验证通知
ISecure iSecure = getSecureTool().getSecure(notifyRequest.getSignType());
if (!iSecure.verifyNotify(notifyRequest)) {
@@ -252,7 +244,6 @@ public class ApiClient {
notifyAnswerResponse.setSign(signStr);
//解析完成
if (accept.contains("application/json")) {
-
return JSON.toJSONString(notifyAnswerResponse);
} else if (accept.contains("application/xml")) {
//返回XML格式
@@ -262,4 +253,32 @@ public class ApiClient {
return "";
}
}
+
+ /**
+ * 验证回调数据
+ *
+ * @return
+ */
+ public String notifyRun(String raw, String contentType, String accept) throws BadResourceException {
+ if (notifyMapRouter == null) {
+ notifyMapRouter = new NotifyMapRouter(this.notifyListener);
+ }
+ if (StrUtil.isEmpty(raw)) {
+ throw new BadResourceException("通知内容为空");
+ }
+
+ NotifyRequest notifyRequest;
+ if (contentType.contains("application/json")) {
+ notifyRequest = JSON.parseObject(raw, NotifyRequest.class);
+ } else if (contentType.contains("application/xml")) {
+ //XML格式
+ Document document = XmlUtil.parseXml(raw);
+ //TODO 对XML解析
+ throw new BadResourceException("暂不支持的格式");
+ } else {
+ throw new BadResourceException("不支持的数据格式");
+ }
+
+ return notifyRun(notifyRequest, accept);
+ }
}
diff --git a/src/main/java/com/tsl3060/open/extend/core/Config.java b/src/main/java/com/tsl3060/open/extend/core/Config.java
index 48663a6..71daaf8 100644
--- a/src/main/java/com/tsl3060/open/extend/core/Config.java
+++ b/src/main/java/com/tsl3060/open/extend/core/Config.java
@@ -19,6 +19,15 @@ public class Config {
private String host = "https://open.tsl3060.com";
private String dataFormat = "yyyy-MM-dd HH:mm:ss";
+ private int timeout = 25000;
+
+ public int getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(int timeout) {
+ this.timeout = timeout;
+ }
public String getPrivateKey() {
return privateKey;