贷款网站源码下载,免费游戏源码资源网,wordpress鼠标跟随,网络规划设计师教程电子版2023文章目录 一、钉钉机器人配置1#xff09;添加机器人2#xff09;添加自定义机器人3#xff09;设置机器人参数4#xff09;添加机器人完成 二、依赖导入三、工具类封装四、关键字推送消息测试类1#xff09;测试类2#xff09;程序输出结果#xff1a;3#xff09;通知… 文章目录 一、钉钉机器人配置1添加机器人2添加自定义机器人3设置机器人参数4添加机器人完成 二、依赖导入三、工具类封装四、关键字推送消息测试类1测试类2程序输出结果3通知结果 五、加签推送消息测试类1修改机器人配置为加签2测试类3程序输出结果4通知结果 一、钉钉机器人配置
1添加机器人 2添加自定义机器人 3设置机器人参数 4添加机器人完成
注意完成后复制出链接方便后续测试使用
Webhook链接组成 https:// baseUrl access_token
例如https://oapi.dingtalk.com/robot/send?access_token82995******45d84 二、依赖导入
!--dingding-sdk--
dependencygroupIdcom.aliyun/groupIdartifactIdalibaba-dingtalk-service-sdk/artifactIdversion2.0.0/version
/dependency三、工具类封装
Slf4j
public class DingDingUtils {public static void send(String url, String msg) {try {//创建钉钉客户端DingTalkClient client new DefaultDingTalkClient(url);//构建自定义机器人请求OapiRobotSendRequest request new OapiRobotSendRequest();//设置固定为文字版信息类型request.setMsgtype(text);//构建自定义机器人文字类型请求OapiRobotSendRequest.Text text new OapiRobotSendRequest.Text();//调用封装文本信息。text.setContent(msg);request.setText(text);//构建自定义机器人人范围请求OapiRobotSendRequest.At at new OapiRobotSendRequest.At();//明确为 true。通知时所有人at.setIsAtAll(true);request.setAt(at);OapiRobotSendResponse response client.execute(request);log.info(发送完成返回值{}, response.getBody());} catch (ApiException e) {log.error(钉钉接口调用异常, e);}}}四、关键字推送消息测试类
1测试类
Test
void sendTextTest() {// 钉钉群机器人id号String url https://oapi.dingtalk.com/robot/send?access_token8299504a4255a****************ae4aae697441995f45d84;// hello,为关键字String msg hello, 大家好;DingDingUtils.send(url, msg);
}2程序输出结果 3通知结果 五、加签推送消息测试类
1修改机器人配置为加签 2测试类
Test
void sendTextTest2() throws Exception {Long timestamp System.currentTimeMillis();String secret SECb2f83dd75fdc0b2***********c50f33ebd36102327e44a8;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);System.out.println(sign);// 钉钉群机器人id号String baseUrl https://oapi.dingtalk.com/robot/send?access_token8299504a4255a****************ae4aae697441995f45d84;String msg 这是一条加签测试的消息;String fullUrl String.format(baseUrl timestamp%ssign%s, timestamp, sign);DingDingUtils.send(fullUrl, msg);
}
3程序输出结果 4通知结果