当前位置:网站首页>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 :
边栏推荐
- Memory management 01 - link script
- 研究表明“气味相投”更易成为朋友
- Halcon extract orange (Orange)
- Professor of Shanghai Jiaotong University: he Yuanjun - bounding box (containment / bounding box)
- 题解:《你的飞碟在这儿》、《哥德巴赫猜想》
- 如何设置Qt手工布局
- Unity skframework framework (XVII), freecameracontroller God view / free view camera control script
- Daily practice of C language --- monkeys divide peaches
- 2022零代码/低代码开发白皮书【伙伴云出品】附下载
- Can automatically update the universal weekly report template, you can use it with your hand!
猜你喜欢

研究表明“气味相投”更易成为朋友

Why is the default of switch followed by break?

2022零代码/低代码开发白皮书【伙伴云出品】附下载

Integral link, inertia link and proportion link in Simulink

Unity skframework framework (XIX), POI points of interest / information points

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!

Can automatically update the universal weekly report template, you can use it with your hand!

Web Foundation

Countermeasures for the failure of MMPV billing period caused by negative inventory of materials in SAP mm
![Unity small map production [2]](/img/d6/9d6556d37525b9986b74133f2a7aaa.jpg)
Unity small map production [2]
随机推荐
[USACO05JAN]Watchcow S(欧拉回路)
OpenFOAM:lduMatrix&lduAddressing
Clean up system cache and free memory under Linux
Redis数据库持久化
D为何链接不了dll
[youcans' image processing learning course] general contents
Unity skframework framework (XIX), POI points of interest / information points
你的 Sleep 服务会梦到服务网格外的 bookinfo 吗
如何设置Qt手工布局
二、帧模式 MPLS 操作
[Unity]使用GB2312,打包后程序不正常解决方案
Bridge of undirected graph
Drawing Nyquist diagram with MATLAB
Winter vacation daily question - lucky numbers in the matrix
量子三体问题: Landau Fall
Android kotlin material design technology points
Partner cloud form strong upgrade! Pro version, more extraordinary!
rxjs Observable 自定义 Operator 的开发技巧
Find love for speed in F1 delta time Grand Prix
693. 行程排序(map + 拓扑)