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

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();

}

}

}

结果

相关推荐
m0_6658151012 小时前
联核科技AGV无人叉车的应用场景有哪些?
人工智能·科技·机器人·自动化·自动驾驶
放羊郎19 小时前
7. 机器人记录数据集(具身智能机器人套件)
机器人·lerobot·lekiwi
IT猿手2 天前
基于多目标向日葵优化算法(Multi-objective Sunflower Optimization,MOSFO)的移动机器人路径规划研究,MATLAB代码
算法·机器学习·matlab·机器人
sxstj2 天前
基于Android 的 PID 控制巡线机器人
android·机器人
十年一梦实验室2 天前
【QWEN】机器人控制器的控制周期越短精度越高吗
人工智能·机器人
放羊郎2 天前
8. 机器人模型训练与评估(具身智能机器人套件)
人工智能·深度学习·机器人·lerobot·lekiwi
宏集科技工业物联网2 天前
应用案例 | 精准控制,高效运行—宏集智能控制系统助力SCARA机器人极致性能
机器人·运动控制·工业控制·工业自动化·工业pc
天天讯通2 天前
语音机器人和deepseek怎么结合使用
机器人
闪电球2 天前
Manus通用任务智能体工作流程拆解分析
人工智能·机器人·llm
HH予2 天前
六足仿生机器人地形自适应步态规划研究
机器人