The SDK provides a high-level API for sending various message types via WeCom robot webhooks. You can send Markdown, plain text, articles, news, or images (via Base64 or InputStream).
Use WorkWeChatApi.webhookApi().send("robot_key", body) to dispatch the message.
// 发 markdown
WebhookBody markdownBody=WebhookMarkdownBody.from("这里为markdown消息");
// 发纯文本
WebhookBody textBody=WebhookTextBody.from("这里为纯文本");
// 发图文
WebhookArticle article=new WebhookArticle("这里为标题","这里为图文链接")
.picurl("这里为封面图链接")
.description("这里为摘要信息");
WebhookBody newsBody=WebhookNewsBody.from(Collections.singletonList(article));
// 从base64发图片
String base64="图片base64";
String md5="图片base64的md5";
WebhookBody imageBody1=WebhookImageBody.from(base64,md5);
// 从流发送图片
String path="C:\\Users\\Administrator\\Desktop\\0.png";
InputStream inputStream=Files.newInputStream(Paths.get(path));
WebhookBody imageBody2=WebhookImageBody.from(inputStream);
// Send the message
WeComResponse weComResponse=WorkWeChatApi.webhookApi().send("机器人key",markdownBody);
Assertions.assertTrue(weComResponse.isSuccessful());