git项目webhook-starter
已经封装发布到中央仓库,可直接使用
a java SDK for wework webhook robot
一个企业微信webhook机器人javaSDK,配置好webhook地址之后就可以快速方便发送消息,摒弃了各种参数的拼接,用面向对象的方式来优雅的发送提醒
现在已经支持:
io.github.mazixi
webhook-starter
1.0.0
可以配置一个或者多个,默认以第一个生效。或者手动修改webhook地址
spring:
message:
webHookList:
- https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxx
- https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxx
@Autowired
private MessageService messageService;
WebHookMessage webHookMessage = WebHookMessage.buildText("这是一个文本信息");
messageService.send(webHookMessage);
// networkImage 和 localImage 均可,格式可支持jpg&png
String networkImageUrl = "http://www.image.com/dog.jpg";
String localImageFilePath = "/home/image/cat.png";
WebHookMessage imageMessage =
WebHookMessage.buildImageMessage(networkImageUrl);
messageService.send(imageMessage);
// networkImage 和 localImage 均可,格式可支持jpg&png
String networkImageUrl = "http://www.image.com/dog.jpg";
Article article = new Article()
.setTitle("这是卡片的标题")
.setUrl("http://www.google.com/这是点击的链接地址")
.setPicUrl(networkImageUrl)
.setDescription("这是描述文字");
WebHookMessage articleMessage =
WebHookMessage.buildNewsMessage(article);
messageService.send(articleMessage);
MarkdownBuffer markdownBuffer = new MarkdownBuffer();
markdownBuffer
.h2("H2").nextLine()
.h3("H3").nextLine()
.quote("quote").quoteEnd()
.green("greenText").nextLine()
.orange("orangeText").nextLine()
.gray("grayText").nextLine()
.code("single line code").nextLine()
.link("link title","line URL").nextLine();
WebHookMessage markDownMessage =
WebHookMessage.buildMarkDownMessage(markdownBuffer);
messageService.send(markDownMessage);