|
|
@ -21,6 +21,7 @@ import java.io.IOException; |
|
|
|
import java.text.DateFormat; |
|
|
|
import java.text.DateFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
|
|
|
public class ApiClient { |
|
|
|
public class ApiClient { |
|
|
|
|
|
|
|
|
|
|
@ -140,6 +141,8 @@ public class ApiClient { |
|
|
|
.post(requestBody) |
|
|
|
.post(requestBody) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
OkHttpClient.Builder builder = new OkHttpClient.Builder(); |
|
|
|
OkHttpClient.Builder builder = new OkHttpClient.Builder(); |
|
|
|
|
|
|
|
//设置连接超时时间
|
|
|
|
|
|
|
|
builder.connectTimeout(this.config.getTimeout(), TimeUnit.MILLISECONDS); |
|
|
|
OkHttpClient okHttpClient = builder.build(); |
|
|
|
OkHttpClient okHttpClient = builder.build(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Call call = okHttpClient.newCall(request); |
|
|
|
Call call = okHttpClient.newCall(request); |
|
|
@ -196,30 +199,19 @@ public class ApiClient { |
|
|
|
|
|
|
|
|
|
|
|
private NotifyMapRouter notifyMapRouter; |
|
|
|
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) { |
|
|
|
if (notifyMapRouter == null) { |
|
|
|
notifyMapRouter = new NotifyMapRouter(this.notifyListener); |
|
|
|
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()); |
|
|
|
ISecure iSecure = getSecureTool().getSecure(notifyRequest.getSignType()); |
|
|
|
if (!iSecure.verifyNotify(notifyRequest)) { |
|
|
|
if (!iSecure.verifyNotify(notifyRequest)) { |
|
|
@ -252,7 +244,6 @@ public class ApiClient { |
|
|
|
notifyAnswerResponse.setSign(signStr); |
|
|
|
notifyAnswerResponse.setSign(signStr); |
|
|
|
//解析完成
|
|
|
|
//解析完成
|
|
|
|
if (accept.contains("application/json")) { |
|
|
|
if (accept.contains("application/json")) { |
|
|
|
|
|
|
|
|
|
|
|
return JSON.toJSONString(notifyAnswerResponse); |
|
|
|
return JSON.toJSONString(notifyAnswerResponse); |
|
|
|
} else if (accept.contains("application/xml")) { |
|
|
|
} else if (accept.contains("application/xml")) { |
|
|
|
//返回XML格式
|
|
|
|
//返回XML格式
|
|
|
@ -262,4 +253,32 @@ public class ApiClient { |
|
|
|
return ""; |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|