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

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

}

}

}

结果

相关推荐
神仙别闹4 小时前
基于单片机的六足机器人控制系统设计
单片机·嵌入式硬件·机器人
南山二毛19 小时前
机器人控制器开发(传感器层——奥比大白相机适配)
数码相机·机器人
房开民1 天前
使用海康机器人相机SDK实现基本参数配置(C语言示例)
c语言·数码相机·机器人
南山二毛1 天前
机器人控制器开发(导航算法——导航栈关联坐标系)
人工智能·架构·机器人
猫头虎2 天前
2025最新超详细FreeRTOS入门教程:第一章 FreeRTOS移植到STM32
stm32·单片机·嵌入式硬件·机器人·硬件架构·freertos·嵌入式实时数据库
xwz小王子2 天前
Nature Machine Intelligence 基于强化学习的磁性微型机器人自主三维位置控制
机器人·微型机器人
IoT砖家涂拉拉2 天前
从“找新家”到“走向全球”,布尔云携手涂鸦智能开启机器人新冒险
人工智能·机器人·ai助手·ai智能体·ai机器人
纪元A梦2 天前
贪心算法应用:机器人路径平滑问题详解
贪心算法·机器人
陈敬雷-充电了么-CEO兼CTO2 天前
具身智能模拟器:解决机器人实机训练场景局限与成本问题的创新方案
大数据·人工智能·机器学习·chatgpt·机器人·具身智能
KlipC2 天前
特斯拉“宏图计划4.0”发布!马斯克:未来80%价值来自机器人
机器人