Skip to content

Dinger 2.0 快速使用Dinger

Jaemon edited this page Dec 26, 2020 · 1 revision

将Dinger组件快速集成到现有springboot项目中

1. 引入依赖

<dependency>
    <groupId>com.github.answerail</groupId>
    <artifactId>dinger-spring-boot-starter</artifactId>
    <version>${dinger.version}</version>
</dependency>

dinger.version版本号取值

2. 配置文件配置

2.1 使用钉钉群机器人配置

spring:
  dinger:
    project-id: ${spring.application.name}
    dingers:
      # 使用钉钉机器人, 请根据自己机器人配置信息进行修改
      dingtalk:
        tokenId: 87dbeb7bc28894c3ycyl3d12457228ad309966275b5f427cd85f9025ebb520cf
        secret: AEQ74a9039ai01f2ljm017b90ycye9asg6335f97c658ff37ff371ec8120581c7f09

2.2 使用企业群机器人配置

spring:
  dinger:
    project-id: ${spring.application.name}
    dingers:
      # 使用企业微信机器人, 请根据自己机器人配置信息进行修改
      wetalk:
        token-id: 32865206-7082-46l5-8j39-2m7ycy6d868

3. 使用Dinger

@Component
public class AppInit implements InitializingBean {
    @Autowired
    private DingerSender dingerSender;
    @Override
    public void afterPropertiesSet() throws Exception {
        // 发送text类型消息
        dingerSender.send(
                MessageSubType.TEXT,
                DingerRequest.request("Hello World, Hello Dinger")
        );

        // 发送markdown类型消息
        dingerSender.send(
                MessageSubType.MARKDOWN,
                DingerRequest.request("Hello World, Hello Dinger", "启动通知")
        );
    }
}
Clone this wiki locally