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

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

}

}

}

结果

相关推荐
资源开发与学习2 天前
机器人运动规划源码解析
机器人
hi0_63 天前
机器学习实战(一): 什么是机器学习
人工智能·机器学习·机器人·机器学习实战
大视码垛机3 天前
速度与安全双突破:大视码垛机重构工业自动化新范式
大数据·数据库·人工智能·机器人·自动化·制造
WWZZ20253 天前
视觉SLAM第10讲:后端2(滑动窗口与位子图优化)
c++·人工智能·后端·算法·ubuntu·机器人·自动驾驶
deephub3 天前
机器人逆运动学进阶:李代数、矩阵指数与旋转流形计算
人工智能·机器学习·矩阵·机器人·李群李代数
武子康4 天前
AI-调查研究-76-具身智能 当机器人走进生活:具身智能对就业与社会结构的深远影响
人工智能·程序人生·ai·职场和发展·机器人·生活·具身智能
小鹿清扫日记4 天前
从蛮力清扫到 “会看路”:室外清洁机器人的文明进阶
人工智能·ai·机器人·扫地机器人·具身智能·连合直租·有鹿巡扫机器人
shuidaoyuxing4 天前
机器人防爆的详细讲解
机器人
物联网软硬件开发-轨物科技4 天前
【轨物方案】赋能绿色能源新纪元:轨物科技发布光伏清洁机器人智能控制与运维解决方案
科技·机器人·能源
尤齐4 天前
《机器人抓取:从经典到现代的综述》内容的提取和凝练:
机器人