pull/1160/head
shikaibin 2 years ago
parent 292dd9ad59
commit 34d95d3fc8

@ -17,7 +17,7 @@
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;
@ -25,8 +25,7 @@ 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;
@ -137,9 +136,31 @@ public class LarkSendMessageHandler implements SendMessageHandler {
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;
}
}

@ -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;
@ -64,7 +66,12 @@ public class WeChatSendMessageHandler extends AbstractRobotSendMessageHandler {
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);
}
@ -90,4 +97,21 @@ public class WeChatSendMessageHandler extends AbstractRobotSendMessageHandler {
private String content;
}
/**
* WeChat robot response.
*/
@Data
static class WeChatRobotResponse {
/**
* Error code
*/
private Long errcode;
/**
* Error message
*/
private String errmsg;
}
}

Loading…
Cancel
Save