当前位置: 首页 > news >正文

钉钉群机器人-发送群消息

1、钉钉群创建机器人

添加完成后,要记住 Webhook 路径;

2、机器人接入文档网址

自定义机器人接入 - 钉钉开放平台

3、JAVA代码



import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class DingDingSendMsgUtils {
/**
* 超时时间
*/
private static final int timeout = 10000;

/**
* 每个群开通的自定义机器人有webhook,后期可更换或写在配置文件作为参数传入
*/
private static final String webhook = "";

/**
* 自定义关键词,安全设置,后期可更换或写在配置文件作为参数传入
*/
private static final String CUSTOM_KEYWORDS = "退款失败:";

/**
* 提示@所有人
* 文本
* @param msg 通知消息
*/
public static void sendMessageTextAtAll(String msg) {
try{
DingTalkClient client = new DefaultDingTalkClient(webhook);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("text");
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
text.setContent( CUSTOM_KEYWORDS + msg);
request.setText(text);
OapiRobotSendResponse response = client.execute(request);
log.info("response="+response);
}catch (Exception e){
e.printStackTrace();
}
}
/**
* 提示@所有人
* 图文
* @param msg 通知消息
* @param chargingNumber 订单编号
* @param userName 用户名称
* @param payMoney 支付金额
* @param refundMoney 退款金额
*/
public static void sendMessageMarkdownAtAll(String msg,String chargingNumber,String userName,String payMoney,String refundMoney) {
try{
DingTalkClient client = new DefaultDingTalkClient(webhook);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
markdown.setTitle(CUSTOM_KEYWORDS);
markdown.setText("> ### "+msg+"\n" +
"> ###### 订单号:"+chargingNumber+" \n" +
"> ###### 用户名称:"+userName+" \n" +
"> ###### 支付金额:"+payMoney+"元 \n" +
"> ###### 退款金额:"+refundMoney+"元 \n ");
// "> ![screenshot](https://easycharg-station.oss-cn-shanghai.aliyuncs.com/2023/2023/07/05/24df5a45ed374a04a81d6035a6408f02.png)\n" +
// "> ###### \n");
request.setMarkdown(markdown);
OapiRobotSendResponse response = client.execute(request);
log.info("response="+response);
}catch (Exception e){
e.printStackTrace();
}
}
}

结果

http://www.lryc.cn/news/294478.html

相关文章:

  • OceanBase 4.2.2 GA 发布,全新特性快速预览!
  • IP代理類型詳解 | 基於網路協議、匿名性、IP來源
  • uniapp中使用EelementPlus
  • Swift Vapor 教程(查询数据、插入数据)
  • QT自用,勿点
  • 计组学习笔记2024/2/5
  • Redis(三)(实战篇)
  • MacOS系统电脑远程桌面控制windows系统电脑【内网穿透】
  • Verilog实现2进制码与BCD码的互相转换
  • Codeforces Round 901 (Div. 2) C. Jellyfish and Green Apple (思维)
  • K8s 集群可观测性-数据分流最佳实践
  • muduo库的模拟实现——工具部分
  • SpringBoot接入微信公众号【服务号】
  • 2023 英特尔On技术创新大会直播 |探索视觉AI的无限可能
  • 安卓视图基础
  • 电路设计(10)——超温报警电路的proteus仿真
  • gerrit(1) | gerrit 简介
  • 计算机视觉实战项目3(图像分类+目标检测+目标跟踪+姿态识别+车道线识别+车牌识别+无人机检测+A*路径规划+单目测距与测速+行人车辆计数等)
  • redis(5)
  • Postgresql体系结构
  • 【Rust】——rust前言与安装rust
  • 基于SpringBoot的家电销售展示网页的设计与实现
  • 【Qt】—— 项⽬⽂件解析
  • 【Linux】静态库和动态库
  • LeetCode 0292.Nim 游戏:脑筋急转弯
  • ctfshow-web1~10-WP
  • 集合问题(并查集)
  • Ubuntu文件系统结构
  • vue element 组件 form深层 :prop 验证失效问题解决
  • 前端开发:入门(一)