From 8d94fae1c4cb360c12db83f98338cbd26be72608 Mon Sep 17 00:00:00 2001 From: nishengli Date: Wed, 27 Sep 2023 14:37:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0notifyRun?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tsl3060/open/extend/core/ApiClient.java | 52 ++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) 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..9f5624f 100644 --- a/src/main/java/com/tsl3060/open/extend/core/ApiClient.java +++ b/src/main/java/com/tsl3060/open/extend/core/ApiClient.java @@ -196,30 +196,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 +241,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 +250,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); + } }