• 企业微信发消息通知-java


    git项目webhook-starter
    已经封装发布到中央仓库,可直接使用

    webhook robot

    a java SDK for wework webhook robot

    介绍(introduction)

    一个企业微信webhook机器人javaSDK,配置好webhook地址之后就可以快速方便发送消息,摒弃了各种参数的拼接,用面向对象的方式来优雅的发送提醒
    现在已经支持:

    • 文本消息
    • 图片消息
    • 文本卡片消息
    • 图文消息(批量)
    • markdown消息

    使用方法(quick start)

    1.添加maven依赖(import maven dependency)

            
                io.github.mazixi
                webhook-starter
                1.0.0
            
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.配置webhook地址(add webhook api)

    可以配置一个或者多个,默认以第一个生效。或者手动修改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
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    3.注入MessageService并且发送消息

            @Autowired
            private MessageService messageService;
    
    • 1
    • 2
    • 1.发送普通文本消息
            WebHookMessage webHookMessage = WebHookMessage.buildText("这是一个文本信息");
            messageService.send(webHookMessage);
    
    • 1
    • 2
    • 2.发送图片消息
            // 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);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 3.发送图文卡片消息
            // 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);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 4.发送markdown消息
            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);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
  • 相关阅读:
    2023前端大厂高频面试题之CSS篇(2)
    香草酸豌豆白蛋白1b纳米粒Vanillic Acid-PA1b|汉黄芩苷牛血清白蛋白纳米粒Wogonoside-BSA|科研试剂
    机器学习--整体整理
    YOLOv9理性解读 | 网络结构&损失函数&耗时评估
    2024年云服务器ECS价格表出炉——阿里云
    linux-Too many open files排查及修复
    善用浏览器的一些调试技巧
    C++实战学习:输出类的抽象和实现详解
    C. Good String(暴力枚举)
    编程题练习@9-13
  • 原文地址:https://blog.csdn.net/liumingzhe1/article/details/126215640