当前位置:网站首页>Dingtalk send message
Dingtalk send message
2022-07-02 13:45:00 【Fish in the sun】
Dependency package :
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
<version>2.0.0</version>
</dependency>
Code implementation :
package com.sq.proxy.job;
import com.alibaba.fastjson.JSON;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.net.URLEncoder;
import java.util.Arrays;
public class DingTalk3 {
static String webHook = "https://oapi.dingtalk.com/robot/send?access_token=xxx";
public static void main(String[] args_) throws Exception {
Long timestamp = System.currentTimeMillis();
String secret = "SEC6cd99f5d8e817df66c5759c246897b51c6be82a4df8f2ce6b8b39a7adfa3bfff";
String stringToSign = timestamp + "\n" + secret;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)),"UTF-8");
DingTalkClient client = new DefaultDingTalkClient(webHook+"&sign="+sign+"×tamp="+timestamp);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("text");
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
text.setContent(" Test text messages ");
request.setText(text);
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
at.setAtMobiles(Arrays.asList("150xx41","137yyy64"));
// isAtAll If the type is not Boolean, Please upgrade to the latest SDK
at.setIsAtAll(true);
// at.setAtUserIds(Arrays.asList("109929","32099"));
request.setAt(at);
request.setMsgtype("link");
OapiRobotSendRequest.Link link = new OapiRobotSendRequest.Link();
link.setMessageUrl("https://www.dingtalk.com/");
link.setPicUrl("");
link.setTitle(" The train of the times is moving forward ");
link.setText(" This new version is coming out , founder xx Call it mangrove . And before that , Whenever faced with a major upgrade , Product managers will take a code for the occasion , This time, , Why mangroves ");
request.setLink(link);
// request.setMsgtype("markdown");
// OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
// markdown.setTitle(" The weather in Hangzhou ");
// markdown.setText("#### The weather in Hangzhou @156xxxx8827\n" +
// "> 9 degree , The northwest 1 level , The air is good 89, Relative temperature 73%\n\n" +
// "> \n" +
// "> ###### 10 spot 20 Sub release [ The weather ](http://www.thinkpage.cn/) \n");
// request.setMarkdown(markdown);
OapiRobotSendResponse response = client.execute(request);
System.out.println(JSON.toJSON(response));
}
}
common problem :
1: If you want to @ How can someone achieve it ?
1.1 will @ Put the mobile phone number of the person in setAtMobiles In the method
1.2 stay text In the news @ cell-phone number To achieve .
Reference resources :
边栏推荐
- 操作教程:EasyDSS如何将MP4点播文件转化成RTSP视频流?
- D how to check null
- What are eNB, EPC and PGW?
- [Blue Bridge Cup] children's worship circle
- Performance optimization of memory function
- Independent and controllable 3D cloud CAD: crowncad enables innovative design of enterprises
- D为何链接不了dll
- BeanUtils--浅拷贝--实例/原理
- Professor of Shanghai Jiaotong University: he Yuanjun - bounding box (containment / bounding box)
- Explanation: here is your UFO, Goldbach conjecture
猜你喜欢
The 29 year old programmer in Shanghai was sentenced to 10 months for "deleting the database and running away" on the day of his resignation!
代码实现MNLM
Can automatically update the universal weekly report template, you can use it with your hand!
Qt-制作一个简单的计算器-实现四则运算-将结果以对话框的形式弹出来
rxjs Observable 自定义 Operator 的开发技巧
Research shows that "congenial" is more likely to become friends
Gee learning notes 2
What are eNB, EPC and PGW?
Chinese name extraction (toy code - accurate head is too small, right to play)
TVOC, VOC, VOCs gas detection + Solution
随机推荐
2、 Frame mode MPLS operation
Unity small map production [2]
Three talking about exception -- error handling
Daily practice of C language --- monkeys divide peaches
What are eNB, EPC and PGW?
Android kotlin fragment technology point
Redis数据库持久化
[indomitable medal activity] life goes on and writing goes on
Essential for operation and maintenance - Elk log analysis system
【文档树、设置】字体变小
[Blue Bridge Cup] children's worship circle
Dingtalk 发送消息
机器学习基础(二)——训练集和测试集的划分
Countermeasures for the failure of MMPV billing period caused by negative inventory of materials in SAP mm
Pointer from entry to advanced (1)
Winter vacation daily question - lucky numbers in the matrix
nohup命令
Tupang multi-target tracking! BOT sort: robust correlated multi pedestrian tracking
验证失败,请检查您的回电网址。您可以按照指导进行操作
leetcode621. task scheduler