MCPcopy Create free account
hub / github.com/OreosLab/bili / DingTalkPush

Class DingTalkPush

src/main/java/top/misec/push/impl/DingTalkPush.java:23–86  ·  view source on GitHub ↗

钉钉机器人. @author itning @since 2021/3/22 19:15

Source from the content-addressed store, hash-verified

21 * @since 2021/3/22 19:15
22 */
23@Slf4j
24public class DingTalkPush extends AbstractPush {
25
26 private final int DING_TALK_MESSAGE_MAX_LENGTH = 15000;
27
28 @Override
29 protected String generatePushUrl(PushMetaInfo metaInfo) {
30 return metaInfo.getToken();
31 }
32
33 @Override
34 protected boolean checkPushStatus(JsonObject jsonObject) {
35 if (jsonObject == null) {
36 return false;
37 }
38 JsonElement errcode = jsonObject.get("errcode");
39 JsonElement errmsg = jsonObject.get("errmsg");
40 if (null == errcode || null == errmsg) {
41 return false;
42 }
43 return errcode.getAsInt() == 0 && "ok".equals(errmsg.getAsString());
44 }
45
46 @Override
47 protected String generatePushBody(PushMetaInfo metaInfo, String content) {
48 return new Gson().toJson(new MessageModel(content));
49 }
50
51 @Override
52 protected List<String> segmentation(PushMetaInfo metaInfo,String pushBody) {
53 if (StringUtils.isBlank(pushBody)) {
54 return Collections.emptyList();
55 }
56
57 if (pushBody.length() > DING_TALK_MESSAGE_MAX_LENGTH) {
58 log.info("推送内容长度[{}]大于最大长度[{}]进行分割处理", pushBody.length(), DING_TALK_MESSAGE_MAX_LENGTH);
59 List<String> pushContent = Arrays.stream(splitStringByLength(pushBody, DING_TALK_MESSAGE_MAX_LENGTH)).collect(Collectors.toList());
60 log.info("分割数量:{}", pushContent.size());
61 return pushContent;
62 }
63
64 return Collections.singletonList(pushBody);
65 }
66
67 @Getter
68 static class MessageModel {
69 private final String msgtype = "text";
70 private final String title = "BILIBILI-HELPER任务简报";
71 private final Text text;
72
73 public MessageModel(String content) {
74 this.text = new Text(content);
75 }
76 }
77
78 @Getter
79 static class Text {
80 private final String content;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…