Skip to content

Commit

Permalink
企业微信图文推送不分割文本
Browse files Browse the repository at this point in the history
  • Loading branch information
graywolf committed Sep 24, 2021
1 parent f43446a commit 03c88d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/main/java/top/misec/push/AbstractPush.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public AbstractPush() {
public final PushResult doPush(PushMetaInfo metaInfo, String content) {
String url = generatePushUrl(metaInfo);
assert null != url : "推送URL不能为空";
List<String> pushList = segmentation(content);
List<String> pushList = segmentation(metaInfo,content);
PushResult pushResult = PushResult.success();
for (String pushItemContent : pushList) {
String pushContent = generatePushBody(metaInfo, pushItemContent);
Expand Down Expand Up @@ -131,7 +131,7 @@ protected String generatePushBody(final PushMetaInfo metaInfo, final String cont
* @param pushBody 消息内容
* @return 分割结果,默认不分割
*/
protected List<String> segmentation(String pushBody) {
protected List<String> segmentation(PushMetaInfo metaInfo,String pushBody) {
return Collections.singletonList(pushBody);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/top/misec/push/impl/DingTalkPush.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected String generatePushBody(PushMetaInfo metaInfo, String content) {
}

@Override
protected List<String> segmentation(String pushBody) {
protected List<String> segmentation(PushMetaInfo metaInfo,String pushBody) {
if (StringUtils.isBlank(pushBody)) {
return Collections.emptyList();
}
Expand Down
16 changes: 4 additions & 12 deletions src/main/java/top/misec/push/impl/WeComAppPush.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<String> segmentation(String pushBody) {
protected List<String> 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<String> pushContent = Arrays.stream(splitStringByLength(pushBody, WE_COM_APP_MESSAGE_MAX_LENGTH)).collect(Collectors.toList());
log.info("分割数量:{}", pushContent.size());
Expand Down

0 comments on commit 03c88d0

Please sign in to comment.