当前位置:网站首页>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 :
边栏推荐
- 口袋奇兵点评
- [cloud native database] what to do when encountering slow SQL (Part 1)?
- Three talking about exception -- error handling
- Solution: Compression Technology (original version and sequel version)
- Verification failed, please check your call back website. You can follow the instructions
- We sincerely invite young creators to share with investors and entrepreneurs how to make choices in life in the metauniverse
- Redis database persistence
- 题解:《你的飞碟在这儿》、《哥德巴赫猜想》
- [USACO05JAN]Watchcow S(欧拉回路)
- 代码实现MNLM
猜你喜欢

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

基于ssm+jsp框架实现的学生选课信息管理系统【源码+数据库】

Web基础

三翼鸟两周年:羽翼渐丰,腾飞指日可待

刚好1000粉丝,记录一下
![[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology](/img/a7/44609a5acf25021f1fca566c3d8c90.png)
[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology

Node.js通过ODBC访问PostgreSQL数据库

de4000h存储安装配置
![[indomitable medal activity] life goes on and writing goes on](/img/c1/54e3f1b37db25af3f1998b39da301b.png)
[indomitable medal activity] life goes on and writing goes on

混沌工程平台 ChaosBlade-Box 新版重磅发布
随机推荐
Operation tutorial: how does easydss convert MP4 on demand files into RTSP video streams?
Nohup command
linux下清理系统缓存并释放内存
文件的下载与图片的预览
Fundamentals of machine learning (II) -- division of training set and test set
TVOC, VOC, VOCs gas detection + Solution
SSL证书的分类有哪些?如何选择合适的SSL证书?
Common options of tcpdump command: Three
Origin绘制热重TG和微分热重DTG曲线
Qt入门-制作一个简易的计算器
三翼鸟两周年:羽翼渐丰,腾飞指日可待
互联网常见34个术语解释
A better database client management tool than Navicat
D language, possible 'string plug-ins'
uniapp小程序 subPackages分包配置
Astro learning notes
Qt-制作一个简单的计算器-实现四则运算
EasyDSS点播服务分享时间出错如何修改?
Can automatically update the universal weekly report template, you can use it with your hand!
Skillfully use SSH to get through the Internet restrictions