🆕 #3725【企业微信】 增加markdown_v2的消息类型支持
This commit is contained in:
@@ -70,6 +70,23 @@ public interface WxCpGroupRobotService {
|
|||||||
*/
|
*/
|
||||||
void sendMarkdown(String webhookUrl, String content) throws WxErrorException;
|
void sendMarkdown(String webhookUrl, String content) throws WxErrorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送markdown_v2类型的消息
|
||||||
|
*
|
||||||
|
* @param content markdown内容,最长不超过4096个字节,必须是utf8编码
|
||||||
|
* @throws WxErrorException 异常
|
||||||
|
*/
|
||||||
|
void sendMarkdownV2(String content) throws WxErrorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送markdown_v2类型的消息
|
||||||
|
*
|
||||||
|
* @param webhookUrl webhook地址
|
||||||
|
* @param content markdown内容,最长不超过4096个字节,必须是utf8编码
|
||||||
|
* @throws WxErrorException 异常
|
||||||
|
*/
|
||||||
|
void sendMarkdownV2(String webhookUrl, String content) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送image类型的消息
|
* 发送image类型的消息
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ public class WxCpGroupRobotServiceImpl implements WxCpGroupRobotService {
|
|||||||
this.sendMarkdown(this.getWebhookUrl(), content);
|
this.sendMarkdown(this.getWebhookUrl(), content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMarkdownV2(String content) throws WxErrorException {
|
||||||
|
this.sendMarkdownV2(this.getWebhookUrl(), content);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendImage(String base64, String md5) throws WxErrorException {
|
public void sendImage(String base64, String md5) throws WxErrorException {
|
||||||
this.sendImage(this.getWebhookUrl(), base64, md5);
|
this.sendImage(this.getWebhookUrl(), base64, md5);
|
||||||
@@ -70,6 +75,14 @@ public class WxCpGroupRobotServiceImpl implements WxCpGroupRobotService {
|
|||||||
.toJson());
|
.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMarkdownV2(String webhookUrl, String content) throws WxErrorException {
|
||||||
|
this.cpService.postWithoutToken(webhookUrl, new WxCpGroupRobotMessage()
|
||||||
|
.setMsgType(GroupRobotMsgType.MARKDOWN_V2)
|
||||||
|
.setContent(content)
|
||||||
|
.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendImage(String webhookUrl, String base64, String md5) throws WxErrorException {
|
public void sendImage(String webhookUrl, String base64, String md5) throws WxErrorException {
|
||||||
this.cpService.postWithoutToken(webhookUrl, new WxCpGroupRobotMessage()
|
this.cpService.postWithoutToken(webhookUrl, new WxCpGroupRobotMessage()
|
||||||
|
|||||||
@@ -252,6 +252,12 @@ public class WxCpGroupRobotMessage implements Serializable {
|
|||||||
messageJson.add("markdown", text);
|
messageJson.add("markdown", text);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case MARKDOWN_V2: {
|
||||||
|
JsonObject text = new JsonObject();
|
||||||
|
text.addProperty("content", this.getContent());
|
||||||
|
messageJson.add("markdown_v2", text);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case IMAGE: {
|
case IMAGE: {
|
||||||
JsonObject text = new JsonObject();
|
JsonObject text = new JsonObject();
|
||||||
text.addProperty("base64", this.getBase64());
|
text.addProperty("base64", this.getBase64());
|
||||||
|
|||||||
@@ -630,6 +630,11 @@ public class WxCpConsts {
|
|||||||
*/
|
*/
|
||||||
public static final String MARKDOWN = "markdown";
|
public static final String MARKDOWN = "markdown";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* markdown_v2消息.
|
||||||
|
*/
|
||||||
|
public static final String MARKDOWN_V2 = "markdown_v2";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图文消息(点击跳转到外链).
|
* 图文消息(点击跳转到外链).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -64,6 +64,51 @@ public class WxCpGroupRobotServiceImplTest {
|
|||||||
robotService.sendMarkdown(content);
|
robotService.sendMarkdown(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test send mark down v2.
|
||||||
|
*
|
||||||
|
* @throws WxErrorException the wx error exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSendMarkDownV2() throws WxErrorException {
|
||||||
|
String content = "# 一、标题\n" +
|
||||||
|
"## 二级标题\n" +
|
||||||
|
"### 三级标题\n" +
|
||||||
|
"# 二、字体\n" +
|
||||||
|
"*斜体*\n" +
|
||||||
|
"\n" +
|
||||||
|
"**加粗**\n" +
|
||||||
|
"# 三、列表 \n" +
|
||||||
|
"- 无序列表 1 \n" +
|
||||||
|
"- 无序列表 2\n" +
|
||||||
|
" - 无序列表 2.1\n" +
|
||||||
|
" - 无序列表 2.2\n" +
|
||||||
|
"1. 有序列表 1\n" +
|
||||||
|
"2. 有序列表 2\n" +
|
||||||
|
"# 四、引用\n" +
|
||||||
|
"> 一级引用\n" +
|
||||||
|
">>二级引用\n" +
|
||||||
|
">>>三级引用\n" +
|
||||||
|
"# 五、链接\n" +
|
||||||
|
"[这是一个链接](https://work.weixin.qq.com/api/doc)\n" +
|
||||||
|
"\n" +
|
||||||
|
"# 六、分割线\n" +
|
||||||
|
"\n" +
|
||||||
|
"---\n" +
|
||||||
|
"# 七、代码\n" +
|
||||||
|
"`这是行内代码`\n" +
|
||||||
|
"```\n" +
|
||||||
|
"这是独立代码块\n" +
|
||||||
|
"```\n" +
|
||||||
|
"\n" +
|
||||||
|
"# 八、表格\n" +
|
||||||
|
"| 姓名 | 文化衫尺寸 | 收货地址 |\n" +
|
||||||
|
"| :----- | :----: | -------: |\n" +
|
||||||
|
"| 张三 | S | 广州 |\n" +
|
||||||
|
"| 李四 | L | 深圳 |";
|
||||||
|
robotService.sendMarkdownV2(content);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test send image.
|
* Test send image.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user