Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1159 #1160

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}