public classMarkdownTest {public void sendMessage() throwsException {
String WEBHOOK_TOKEN= "https://oapi.dingtalk.com/robot/send?access_token=xxxxxx";
String DING= "";
String MARK_DOWN_ATX2= "## ";
String MARK_DOWN_ATX3= "### ";
String MARK_DOWN_ATX4= "#### ";
String MARK_DOWN_COLON= " : ";
String MARK_DOWN_LINEFEED= "
";
String MARK_DOWN_IS_RED= "%s";
String MARK_DOWN_EMAIL1= "> ";//通知钉钉群
StringBuilder resultText = newStringBuilder();
resultText.append(MARK_DOWN_ATX2).append("项目名").append(MARK_DOWN_COLON).append(projectappid).append(MARK_DOWN_LINEFEED);
resultText.append(MARK_DOWN_ATX4).append("单元测试覆盖率").append(MARK_DOWN_COLON).append(String.format(MARK_DOWN_IS_RED, total_covered_instructions)).append(MARK_DOWN_LINEFEED);
String DING_URL= WEBHOOK_TOKEN;
DingTalkClient client= newDefaultDingTalkClient(DING_URL);
OapiRobotSendRequest request= newOapiRobotSendRequest();
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown= newOapiRobotSendRequest.Markdown();
markdown.setTitle("jacoco代码扫描");
markdown.setText(resultText.toString());
request.setMarkdown(markdown);try{
OapiRobotSendResponse response=client.execute(request);if(response.isSuccess()) {
LOGGER.info(String.format("### 钉钉通知已发送成功, msg:%s", msgText));//System.out.println("send message ok");
} else{
LOGGER.error(response.getErrmsg());
}
}catch(com.taobao.api.ApiException e) {
String errorMsg= "### 发送钉钉通知异常";
LOGGER.error(errorMsg, e);throw newApiException(errorMsg);
}
}
}catch(NumberFormatException e) {
e.printStackTrace();
}
}
}