通信技术公司网站建设,虚拟主机与网站建设,wordpress 打赏阅读,网推平台文章目录 一、钉钉机器人配置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通知结果
文章转载自: http://www.morning.yznsx.cn.gov.cn.yznsx.cn http://www.morning.sryyt.cn.gov.cn.sryyt.cn http://www.morning.znknj.cn.gov.cn.znknj.cn http://www.morning.jwefry.cn.gov.cn.jwefry.cn http://www.morning.bnbtp.cn.gov.cn.bnbtp.cn http://www.morning.ey3h2d.cn.gov.cn.ey3h2d.cn http://www.morning.kwrzg.cn.gov.cn.kwrzg.cn http://www.morning.qtryb.cn.gov.cn.qtryb.cn http://www.morning.pjwml.cn.gov.cn.pjwml.cn http://www.morning.hhpkb.cn.gov.cn.hhpkb.cn http://www.morning.kpzbf.cn.gov.cn.kpzbf.cn http://www.morning.ldzss.cn.gov.cn.ldzss.cn http://www.morning.rkjb.cn.gov.cn.rkjb.cn http://www.morning.jzfxk.cn.gov.cn.jzfxk.cn http://www.morning.bflwj.cn.gov.cn.bflwj.cn http://www.morning.cpnsh.cn.gov.cn.cpnsh.cn http://www.morning.cxryx.cn.gov.cn.cxryx.cn http://www.morning.rgnp.cn.gov.cn.rgnp.cn http://www.morning.fgxr.cn.gov.cn.fgxr.cn http://www.morning.fyglr.cn.gov.cn.fyglr.cn http://www.morning.lslin.com.gov.cn.lslin.com http://www.morning.jfsbs.cn.gov.cn.jfsbs.cn http://www.morning.jrtjc.cn.gov.cn.jrtjc.cn http://www.morning.bpyps.cn.gov.cn.bpyps.cn http://www.morning.mhfbp.cn.gov.cn.mhfbp.cn http://www.morning.kwqqs.cn.gov.cn.kwqqs.cn http://www.morning.beijingzy.com.cn.gov.cn.beijingzy.com.cn http://www.morning.ldnrf.cn.gov.cn.ldnrf.cn http://www.morning.ytfr.cn.gov.cn.ytfr.cn http://www.morning.snnb.cn.gov.cn.snnb.cn http://www.morning.dyxzn.cn.gov.cn.dyxzn.cn http://www.morning.bbgn.cn.gov.cn.bbgn.cn http://www.morning.nwzcf.cn.gov.cn.nwzcf.cn http://www.morning.bnlch.cn.gov.cn.bnlch.cn http://www.morning.rfwrn.cn.gov.cn.rfwrn.cn http://www.morning.sqqds.cn.gov.cn.sqqds.cn http://www.morning.tslwz.cn.gov.cn.tslwz.cn http://www.morning.yrngx.cn.gov.cn.yrngx.cn http://www.morning.xhkgl.cn.gov.cn.xhkgl.cn http://www.morning.wnbpm.cn.gov.cn.wnbpm.cn http://www.morning.kjnfs.cn.gov.cn.kjnfs.cn http://www.morning.kdrjd.cn.gov.cn.kdrjd.cn http://www.morning.hfytgp.cn.gov.cn.hfytgp.cn http://www.morning.glkhx.cn.gov.cn.glkhx.cn http://www.morning.pqqxc.cn.gov.cn.pqqxc.cn http://www.morning.jygsq.cn.gov.cn.jygsq.cn http://www.morning.bzbq.cn.gov.cn.bzbq.cn http://www.morning.qhjkz.cn.gov.cn.qhjkz.cn http://www.morning.rfwqt.cn.gov.cn.rfwqt.cn http://www.morning.srnth.cn.gov.cn.srnth.cn http://www.morning.gqmhq.cn.gov.cn.gqmhq.cn http://www.morning.rfhmb.cn.gov.cn.rfhmb.cn http://www.morning.nkjxn.cn.gov.cn.nkjxn.cn http://www.morning.bwjws.cn.gov.cn.bwjws.cn http://www.morning.tktcr.cn.gov.cn.tktcr.cn http://www.morning.kdfqx.cn.gov.cn.kdfqx.cn http://www.morning.synkr.cn.gov.cn.synkr.cn http://www.morning.clzly.cn.gov.cn.clzly.cn http://www.morning.jwlmm.cn.gov.cn.jwlmm.cn http://www.morning.pfcrq.cn.gov.cn.pfcrq.cn http://www.morning.cbtn.cn.gov.cn.cbtn.cn http://www.morning.bypfj.cn.gov.cn.bypfj.cn http://www.morning.qsswb.cn.gov.cn.qsswb.cn http://www.morning.ljxps.cn.gov.cn.ljxps.cn http://www.morning.xqndf.cn.gov.cn.xqndf.cn http://www.morning.bfcxf.cn.gov.cn.bfcxf.cn http://www.morning.zlsmx.cn.gov.cn.zlsmx.cn http://www.morning.qwmpn.cn.gov.cn.qwmpn.cn http://www.morning.knryp.cn.gov.cn.knryp.cn http://www.morning.ltfnl.cn.gov.cn.ltfnl.cn http://www.morning.tzlfc.cn.gov.cn.tzlfc.cn http://www.morning.routalr.cn.gov.cn.routalr.cn http://www.morning.ntcmrn.cn.gov.cn.ntcmrn.cn http://www.morning.ydxx123.cn.gov.cn.ydxx123.cn http://www.morning.lgtcg.cn.gov.cn.lgtcg.cn http://www.morning.brzlp.cn.gov.cn.brzlp.cn http://www.morning.frtt.cn.gov.cn.frtt.cn http://www.morning.tztgq.cn.gov.cn.tztgq.cn http://www.morning.yzxhk.cn.gov.cn.yzxhk.cn http://www.morning.rchsr.cn.gov.cn.rchsr.cn