6
0
Fork 0

Merge branch 'release/0.3.8'

master 0.3.8
nishengli 2 years ago
commit 97a31c2228
  1. 2
      pom.xml
  2. 55
      src/main/java/com/tsl3060/open/extend/core/ApiClient.java
  3. 9
      src/main/java/com/tsl3060/open/extend/core/Config.java

@ -6,7 +6,7 @@
<groupId>com.tsl3060.open.extend</groupId>
<artifactId>tsl-open-sdk-java-wanshun</artifactId>
<version>0.3.7</version>
<version>0.3.8</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

@ -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);
}
}

@ -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;

Loading…
Cancel
Save