Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ishikaibin committed Apr 14, 2023
1 parent 292dd9a commit 34d95d3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@

package cn.hippo4j.message.platform;

import cn.hippo4j.common.toolkit.Singleton;
import cn.hippo4j.common.toolkit.*;
import cn.hippo4j.common.toolkit.http.HttpUtil;
import cn.hippo4j.message.dto.NotifyConfigDTO;
import cn.hippo4j.message.enums.NotifyPlatformEnum;
import cn.hippo4j.message.enums.NotifyTypeEnum;
import cn.hippo4j.message.service.SendMessageHandler;
import cn.hippo4j.message.request.AlarmNotifyRequest;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.toolkit.FileUtil;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -137,9 +136,31 @@ private String getReceives(String receives) {
private void execute(String secretKey, String text) {
String serverUrl = LARK_BOT_URL + secretKey;
try {
HttpUtil.postJson(serverUrl, text);
String responseBody = HttpUtil.postJson(serverUrl, text);
LarkRobotResponse response = JSONUtil.parseObject(responseBody, LarkRobotResponse.class);
Assert.isTrue(response != null, "Response is null.");
if (response.getCode() != 0) {
log.error("Lark failed to send message, reason : {}", response.msg);
}
} catch (Exception ex) {
log.error("Lark failed to send message", ex);
}
}

/**
* Lark robot response.
*/
@Data
static class LarkRobotResponse {

/**
* code
*/
private Long code;

/**
* message
*/
private String msg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package cn.hippo4j.message.platform;

import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.common.toolkit.FileUtil;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.Singleton;
import cn.hippo4j.common.toolkit.http.HttpUtil;
import cn.hippo4j.message.enums.NotifyPlatformEnum;
Expand Down Expand Up @@ -64,7 +66,12 @@ protected void execute(RobotMessageExecuteDTO robotMessageExecuteDTO) {
Markdown markdown = new Markdown();
markdown.setContent(robotMessageExecuteDTO.getText());
weChatReq.setMarkdown(markdown);
HttpUtil.post(serverUrl, weChatReq);
String responseBody = HttpUtil.post(serverUrl, weChatReq);
WeChatRobotResponse response = JSONUtil.parseObject(responseBody, WeChatRobotResponse.class);
Assert.isTrue(response != null, "Response is null.");
if (response.getErrcode() != 0) {
log.error("WeChat failed to send message, reason : {}", response.errmsg);
}
} catch (Exception ex) {
log.error("WeChat failed to send message", ex);
}
Expand All @@ -90,4 +97,21 @@ public static class Markdown {

private String content;
}

/**
* WeChat robot response.
*/
@Data
static class WeChatRobotResponse {

/**
* Error code
*/
private Long errcode;

/**
* Error message
*/
private String errmsg;
}
}

0 comments on commit 34d95d3

Please sign in to comment.