文章目录
- 钉钉群内自定义机器人发送消息功能实现
-
- 1、设置webhook自定义机器人
- [2、查看官方文档,使用open api](#2、查看官方文档,使用open api)
- 3、编写业务代码
- 4、发送成功结果如下
钉钉群内自定义机器人发送消息功能实现
1、设置webhook自定义机器人

设置关键词

添加完成后,获得改机器人的webhook,复制保存

2、查看官方文档,使用open api
https://open.dingtalk.com/document/orgapp/custom-bot-send-message-type

post请求的路径就是咱们刚才创建机器人所获得的webhook!!!
3、编写业务代码
java
private void sendDingDing(PoMaster poMaster){
if(poMaster.getTotalPrice().doubleValue() > 2000){
String url = "你的webhook";
JSONObject msg = new JSONObject();
//定义发送消息类型
msg.set("msgtype", "text");
msg.set("text", new JSONObject().set("content","采购单" + poMaster.getId() + ",需要您的审核@18212345678"));
msg.set("at", new JSONObject().set("atMobiles", new JSONArray().set("18212345678")));
//在群中@所有人
// msg.set("at", new JSONObject().set("isAtAll", true));
String json = JSONUtil.toJsonStr(msg);
String result = HttpRequest.post(url).body(json).execute().body();
log.debug("采购单{},发送邮件审核成功", poMaster.getId());
} else {
log.debug("采购单{},未达到下线金额,不用审核", poMaster.getId());
}
}
4、发送成功结果如下
