From 03c88d092219f591132129e935903361c5fcd10d Mon Sep 17 00:00:00 2001 From: graywolf Date: Fri, 24 Sep 2021 09:32:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1=E5=9B=BE?= =?UTF-8?q?=E6=96=87=E6=8E=A8=E9=80=81=E4=B8=8D=E5=88=86=E5=89=B2=E6=96=87?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/top/misec/push/AbstractPush.java | 4 ++-- .../java/top/misec/push/impl/DingTalkPush.java | 2 +- .../java/top/misec/push/impl/WeComAppPush.java | 16 ++++------------ 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/top/misec/push/AbstractPush.java b/src/main/java/top/misec/push/AbstractPush.java index d09cb9c..b0fb267 100644 --- a/src/main/java/top/misec/push/AbstractPush.java +++ b/src/main/java/top/misec/push/AbstractPush.java @@ -60,7 +60,7 @@ public AbstractPush() { public final PushResult doPush(PushMetaInfo metaInfo, String content) { String url = generatePushUrl(metaInfo); assert null != url : "推送URL不能为空"; - List pushList = segmentation(content); + List pushList = segmentation(metaInfo,content); PushResult pushResult = PushResult.success(); for (String pushItemContent : pushList) { String pushContent = generatePushBody(metaInfo, pushItemContent); @@ -131,7 +131,7 @@ protected String generatePushBody(final PushMetaInfo metaInfo, final String cont * @param pushBody 消息内容 * @return 分割结果,默认不分割 */ - protected List segmentation(String pushBody) { + protected List segmentation(PushMetaInfo metaInfo,String pushBody) { return Collections.singletonList(pushBody); } diff --git a/src/main/java/top/misec/push/impl/DingTalkPush.java b/src/main/java/top/misec/push/impl/DingTalkPush.java index 2606c57..30a940c 100644 --- a/src/main/java/top/misec/push/impl/DingTalkPush.java +++ b/src/main/java/top/misec/push/impl/DingTalkPush.java @@ -49,7 +49,7 @@ protected String generatePushBody(PushMetaInfo metaInfo, String content) { } @Override - protected List segmentation(String pushBody) { + protected List segmentation(PushMetaInfo metaInfo,String pushBody) { if (StringUtils.isBlank(pushBody)) { return Collections.emptyList(); } diff --git a/src/main/java/top/misec/push/impl/WeComAppPush.java b/src/main/java/top/misec/push/impl/WeComAppPush.java index 50d503b..65b0079 100644 --- a/src/main/java/top/misec/push/impl/WeComAppPush.java +++ b/src/main/java/top/misec/push/impl/WeComAppPush.java @@ -52,12 +52,11 @@ protected String generatePushUrl(PushMetaInfo metaInfo) { @Override protected String generatePushBody(PushMetaInfo metaInfo, String content) { content = content.replaceAll("\r\n\r", "").replaceAll("\n\n\n","\n").replaceAll("\n\n","\n"); - String Mediaid = metaInfo.getMediaid(); - WeComMessageSendRequest request = new WeComMessageSendRequest(); request.setToUser(metaInfo.getToUser()); request.setAgentId(metaInfo.getAgentId()); - if (Mediaid == null || Mediaid.length() <= 0){ + //System.out.println(StringUtils.isBlank(metaInfo.getMediaid())); + if (StringUtils.isBlank(metaInfo.getMediaid())){ request.setMsgType("text"); WeComMessageSendRequest.Text text = new WeComMessageSendRequest.Text(); text.setContent(content); @@ -72,24 +71,17 @@ protected String generatePushBody(PushMetaInfo metaInfo, String content) { Articles.setThumb_media_id(metaInfo.getMediaid()); WeComMessageSendRequest.Mpnews Mpnews = new WeComMessageSendRequest.Mpnews(); Mpnews.setArticles(Collections.singletonList(Articles)); - request.setMpnews(Mpnews); - } - - - - return GsonUtils.toJson(request); } @Override - protected List segmentation(String pushBody) { + protected List segmentation(PushMetaInfo metaInfo,String pushBody) { if (StringUtils.isBlank(pushBody)) { return Collections.emptyList(); } - - if (pushBody.length() > WE_COM_APP_MESSAGE_MAX_LENGTH) { + if (pushBody.length() > WE_COM_APP_MESSAGE_MAX_LENGTH && StringUtils.isBlank(metaInfo.getMediaid())) { log.info("推送内容长度[{}]大于最大长度[{}]进行分割处理", pushBody.length(), WE_COM_APP_MESSAGE_MAX_LENGTH); List pushContent = Arrays.stream(splitStringByLength(pushBody, WE_COM_APP_MESSAGE_MAX_LENGTH)).collect(Collectors.toList()); log.info("分割数量:{}", pushContent.size());