6
0
Fork 0

增加notifyRun

master
nishengli 2 years ago
parent 4c65e9e271
commit 8d94fae1c4
  1. 52
      src/main/java/com/tsl3060/open/extend/core/ApiClient.java

@ -196,30 +196,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 +241,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 +250,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);
}
} }

Loading…
Cancel
Save