当前位置:网站首页>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 :
边栏推荐
- de4000h存储安装配置
- 【蓝桥杯选拔赛真题43】Scratch航天飞行 少儿编程scratch蓝桥杯选拔赛真题讲解
- 研究表明“气味相投”更易成为朋友
- What are the classifications of SSL certificates? How to choose the appropriate SSL certificate?
- uniapp小程序 subPackages分包配置
- Qt新项目_MyNotepad++
- 石子合并板子【区间DP】(普通石子合并 & 环形石子合并)
- Research shows that "congenial" is more likely to become friends
- 记忆函数的性能优化
- We sincerely invite young creators to share with investors and entrepreneurs how to make choices in life in the metauniverse
猜你喜欢

Integral link, inertia link and proportion link in Simulink

错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”

Answer: can the audio be set to on by default during easydss video on demand?

Origin绘制热重TG和微分热重DTG曲线

伙伴云表格强势升级!Pro版,更非凡!

Three methods of finding LCA of the nearest common ancestor

Countermeasures for the failure of MMPV billing period caused by negative inventory of materials in SAP mm

ensp简单入门

解答:EasyDSS视频点播时音频是否可以设置为默认开启?

中文姓名提取(玩具代码——准头太小,权当玩闹)
随机推荐
【OpenGL】笔记二十九、高级光照(镜面高光)
Astro learning notes
D如何检查null
Crowncad (crown CAD), the first fully independent 3D CAD platform based on Cloud Architecture in China
mysql ---- Oracle中的rownum转换成MySQL
Halcon extract orange (Orange)
Countermeasures for the failure of MMPV billing period caused by negative inventory of materials in SAP mm
We sincerely invite young creators to share with investors and entrepreneurs how to make choices in life in the metauniverse
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
qt中uic的使用
I did it with two lines of code. As a result, my sister had a more ingenious way
Answer: can the audio be set to on by default during easydss video on demand?
Which do you choose between Alibaba P7 with an annual salary of 900000 and deputy department level cadres?
最近公共祖先LCA的三种求法
错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”
Winter vacation daily question - lucky numbers in the matrix
Achievements in science and Technology (27)
TVOC, VOC, VOCs gas detection + Solution
使用BLoC 构建 Flutter的页面实例
Solve "sub number integer", "jump happily", "turn on the light"