网站建设验收合同模板,没网站做推广,网站基础模块建设,十大国际展览公司前言
钉钉作为一款企业级通讯工具#xff0c;具有广泛的应用场景#xff0c;包括但不限于团队协作、任务提醒、工作汇报等。
通过Spring Boot应用程序整合钉钉实现消息推送#xff0c;我们可以实现以下功能#xff1a;
实时向指定用户或群组发送消息通知。自定义消息内容…前言
钉钉作为一款企业级通讯工具具有广泛的应用场景包括但不限于团队协作、任务提醒、工作汇报等。
通过Spring Boot应用程序整合钉钉实现消息推送我们可以实现以下功能
实时向指定用户或群组发送消息通知。自定义消息内容和格式满足不同业务需求。监控和提醒功能的实现提高工作效率和沟通效果。
在接下来的部分我们将逐步介绍如何在Spring Boot中配置和调用钉钉消息推送API以实现消息推送功能。
钉钉群安装机器人
电脑端登录钉钉选择一个群聊进行如下的操作 注复制生成的签名串后续将会用到! 复制出来的结果如下 SEC1cc02e7xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 勾选协议点击完成即可
接下来节将会出现如下配置 注复制Webhook地址后续将使用该地址向钉钉群推送消息 地址如下 https://oapi.dingtalk.com/robot/send?access_token89742c23bdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 到此位置经过以上步骤钉钉群安装机器人完成了。 集成钉钉消息推送功能
引入依赖
在项目pom.xml文件中引入依赖当前版本1.0.3.RELEASE dependencygroupIdcn.snowheart/groupIdartifactIdspring-boot-dingtalk-robot-starter/artifactIdversion1.0.3.RELEASE/version/dependency配置WebHook地址
在application.yml配置文件中配置钉钉机器人的WebHook地址
dingtalk:robot:prefix: https://oapi.dingtalk.com/robot/sendaccess-token: 89742c23bdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsecret:secret-enabled: truesecret-token: SEC1cc02e7xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx功能测试
RestController
RequestMapping
Slf4j
public class DingTalkController {Autowiredprivate DingTalkRobotClient dingTalkRobotClient;/*** 测试发送文本消息*/GetMapping(/sendMsg)public void sendMessage() {DingTalkResponse response dingTalkRobotClient.sendMessage(new TextMessage(公众号小小开发者!));Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());}}启动项目访问http://127.0.0.1:8080/sendMsg 即可发送 其他相关测试
普通文本通知 /*** 普通文本通知*/GetMapping(/sendTextMessage)public void sendTextMessage() {DingTalkResponse response dingTalkRobotClient.sendTextMessage(new TextMessage(业务处理异常:构建TextMessage对象发布!));Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);response dingTalkRobotClient.sendTextMessage(业务处理异常构建普通字符串发布!);Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);response dingTalkRobotClient.sendTextMessage(业务处理异常通知指定人!, new String[]{17767145153});Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);response dingTalkRobotClient.sendTextMessage(业务处理异常通知群内所有人!, true);Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);}访问http://127.0.0.1:8080/sendTextMessage 超链接文本 /*** 超链接文本*/GetMapping(/sendLinkMessage)public void sendLinkMessage() {DingTalkResponse response dingTalkRobotClient.sendLinkMessage(new LinkMessage(业务处理异常AAAAAA,BBBBBB,CCCCCC,DDDDDD));Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);
}访问http://127.0.0.1:8080/sendLinkMessage Markdown文本推送 private static final String markDownDemoText 业务报警:标题 # 一级标题\n ## 二级标题\n ### 三级标题\n #### 四级标题\n ##### 五级标题\n ###### 六级标题\n;/*** markdown文本推送*/GetMapping(/sendMarkdownMessage)public void sendMarkdownMessage() {// 构建 markdown 对象用法DingTalkResponse response dingTalkRobotClient.sendMarkdownMessage(new MarkdownMessage(业务处理异常钉钉markdown消息支持的语法,markDownDemoText));Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);// 不构建对象response dingTalkRobotClient.sendMarkdownMessage(业务处理异常钉钉markdown消息支持的语法,markDownDemoText);Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);// 发送给指定人response dingTalkRobotClient.sendMarkdownMessage(业务处理异常钉钉markdown消息支持的语法,markDownDemoText, new String[]{19087690186});Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);//发送给全体人response dingTalkRobotClient.sendMarkdownMessage(业务处理异常钉钉markdown消息支持的语法,markDownDemoText, true);Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);}访问http://127.0.0.1:8080/sendMarkdownMessage ActionCard 业务推送 /*** ActionCard业务推送*/GetMapping(/sendActionCardMessage)public void sendActionCardMessage() {DingTalkResponse response dingTalkRobotClient.sendActionCardMessage(new ActionCardMessage(业务报警:This is title, \n **Apple Store** 的设计正从原来满满的科技感走向生活化而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划));Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);response dingTalkRobotClient.sendActionCardMessage(业务报警:This is title, \n **Apple Store** 的设计正从原来满满的科技感走向生活化而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划);Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);response dingTalkRobotClient.sendActionCardMessage(业务报警:This is title, \n **Apple Store** 的设计正从原来满满的科技感走向生活化而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划,HideAvatarType.HIDE);Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);response dingTalkRobotClient.sendActionCardMessage(业务报警:This is title, \n **Apple Store** 的设计正从原来满满的科技感走向生活化而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划,ActionCardButton.defaultReadButton(https://www.dingtalk.com));Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);response dingTalkRobotClient.sendActionCardMessage(业务报警:This is title, \n **Apple Store** 的设计正从原来满满的科技感走向生活化而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划,HideAvatarType.HIDE,ActionCardButton.defaultReadButton(https://www.dingtalk.com));Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);}访问http://127.0.0.1:8080/sendActionCardMessage FeedCard 消息推送 /*** FeedCard 消息推送* throws InterruptedException*/GetMapping(/sendFeedCardMessage)public void sendFeedCardMessage() {ArrayListFeedCardMessageItem items new ArrayList();items.add(new FeedCardMessageItem(业务处理异常:成为架构师的路上看这一篇文章就足够了因为……,http://mp.weixin.qq.com/s/CPUaB60pue0Zf3fUL9xqvw,https://mmbiz.qpic.cn/mmbiz_jpg/YriaiaJPb26VMtfgPvTsM9amH5hf3pmTbf40ia6OLE845icrDb0vt4AsMnTyva5mMMpwwxnkVR5UjCEI8ADvSic1qWQ/640));items.add(new FeedCardMessageItem(业务处理异常:想成为一名Web开发者你应该学习Node.js而不是PHP,http://mp.weixin.qq.com/s/x8dm9e7gwLXSEzxE6sQYow,https://mmbiz.qpic.cn/mmbiz_jpg/YriaiaJPb26VND0Q0hSBOoyVkr9cXQrFjWI7hOzax1IxIibqanXYD4W8nyeYX5iaicjgiaqia7ly94iawOsGwehbKGwGsA/640));DingTalkResponse response dingTalkRobotClient.sendFeedCardMessage(new FeedCardMessage(items));Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);response dingTalkRobotClient.sendFeedCardMessage(items);Assert.assertEquals(response.getErrcode().longValue(), 0L);log.info(response.toString());ThreadUtil.sleep(3000);}访问http://127.0.0.1:8080/sendFeedCardMessage 总结
通过本文的介绍我们深入了解了如何使用Spring Boot应用集成钉钉实现消息的推送实现了实时消息通知和提醒功能在实际应用中钉钉消息推送功能可以帮助企业提高内部沟通效率及时传达重要信息和通知提升团队协作和工作效率。
希望本文对您了解和应用钉钉消息推送功能有所帮助如果你觉得本文对你有帮助请点赞分享让更多人受益
源码获取 本文代码获取方式 后台回复【消息推送】即可获取!
文章转载自: http://www.morning.zhiheliuxue.com.gov.cn.zhiheliuxue.com http://www.morning.ykwbx.cn.gov.cn.ykwbx.cn http://www.morning.bxqtq.cn.gov.cn.bxqtq.cn http://www.morning.kfldw.cn.gov.cn.kfldw.cn http://www.morning.ttryd.cn.gov.cn.ttryd.cn http://www.morning.btcgq.cn.gov.cn.btcgq.cn http://www.morning.china-cj.com.gov.cn.china-cj.com http://www.morning.bxgpy.cn.gov.cn.bxgpy.cn http://www.morning.hxwhyjh.com.gov.cn.hxwhyjh.com http://www.morning.syglx.cn.gov.cn.syglx.cn http://www.morning.phzrq.cn.gov.cn.phzrq.cn http://www.morning.gslz.com.cn.gov.cn.gslz.com.cn http://www.morning.hhxwr.cn.gov.cn.hhxwr.cn http://www.morning.gdgylp.com.gov.cn.gdgylp.com http://www.morning.xjmyq.com.gov.cn.xjmyq.com http://www.morning.qxgmp.cn.gov.cn.qxgmp.cn http://www.morning.tgdys.cn.gov.cn.tgdys.cn http://www.morning.lpmdy.cn.gov.cn.lpmdy.cn http://www.morning.jmwrj.cn.gov.cn.jmwrj.cn http://www.morning.hcqpc.cn.gov.cn.hcqpc.cn http://www.morning.zpstm.cn.gov.cn.zpstm.cn http://www.morning.zxqyd.cn.gov.cn.zxqyd.cn http://www.morning.tzzxs.cn.gov.cn.tzzxs.cn http://www.morning.27asw.cn.gov.cn.27asw.cn http://www.morning.nqyfm.cn.gov.cn.nqyfm.cn http://www.morning.sooong.com.gov.cn.sooong.com http://www.morning.rmpkn.cn.gov.cn.rmpkn.cn http://www.morning.ccffs.cn.gov.cn.ccffs.cn http://www.morning.nqdkx.cn.gov.cn.nqdkx.cn http://www.morning.hbhnh.cn.gov.cn.hbhnh.cn http://www.morning.rptdz.cn.gov.cn.rptdz.cn http://www.morning.tgfsr.cn.gov.cn.tgfsr.cn http://www.morning.clndl.cn.gov.cn.clndl.cn http://www.morning.frpb.cn.gov.cn.frpb.cn http://www.morning.dcccl.cn.gov.cn.dcccl.cn http://www.morning.hnhgb.cn.gov.cn.hnhgb.cn http://www.morning.kxqmh.cn.gov.cn.kxqmh.cn http://www.morning.kzqpn.cn.gov.cn.kzqpn.cn http://www.morning.fhrt.cn.gov.cn.fhrt.cn http://www.morning.prqdr.cn.gov.cn.prqdr.cn http://www.morning.hxrfb.cn.gov.cn.hxrfb.cn http://www.morning.rkhhl.cn.gov.cn.rkhhl.cn http://www.morning.qlznd.cn.gov.cn.qlznd.cn http://www.morning.kgtyj.cn.gov.cn.kgtyj.cn http://www.morning.qckwj.cn.gov.cn.qckwj.cn http://www.morning.rlbc.cn.gov.cn.rlbc.cn http://www.morning.xpqdf.cn.gov.cn.xpqdf.cn http://www.morning.trqsm.cn.gov.cn.trqsm.cn http://www.morning.bcnsl.cn.gov.cn.bcnsl.cn http://www.morning.plpqf.cn.gov.cn.plpqf.cn http://www.morning.fdhwh.cn.gov.cn.fdhwh.cn http://www.morning.lylkh.cn.gov.cn.lylkh.cn http://www.morning.gmmyn.cn.gov.cn.gmmyn.cn http://www.morning.lnrhk.cn.gov.cn.lnrhk.cn http://www.morning.rkqqf.cn.gov.cn.rkqqf.cn http://www.morning.rlxnc.cn.gov.cn.rlxnc.cn http://www.morning.rcwbc.cn.gov.cn.rcwbc.cn http://www.morning.wphzr.cn.gov.cn.wphzr.cn http://www.morning.jytrb.cn.gov.cn.jytrb.cn http://www.morning.wanjia-sd.com.gov.cn.wanjia-sd.com http://www.morning.ccffs.cn.gov.cn.ccffs.cn http://www.morning.zdgp.cn.gov.cn.zdgp.cn http://www.morning.bojkosvit.com.gov.cn.bojkosvit.com http://www.morning.ywpwq.cn.gov.cn.ywpwq.cn http://www.morning.bpmtj.cn.gov.cn.bpmtj.cn http://www.morning.wnzgm.cn.gov.cn.wnzgm.cn http://www.morning.ksggl.cn.gov.cn.ksggl.cn http://www.morning.trsfm.cn.gov.cn.trsfm.cn http://www.morning.jrhmh.cn.gov.cn.jrhmh.cn http://www.morning.ruyuaixuexi.com.gov.cn.ruyuaixuexi.com http://www.morning.bgpch.cn.gov.cn.bgpch.cn http://www.morning.xjkfb.cn.gov.cn.xjkfb.cn http://www.morning.qfkdt.cn.gov.cn.qfkdt.cn http://www.morning.jyznn.cn.gov.cn.jyznn.cn http://www.morning.wgtnz.cn.gov.cn.wgtnz.cn http://www.morning.nfdty.cn.gov.cn.nfdty.cn http://www.morning.xpwdf.cn.gov.cn.xpwdf.cn http://www.morning.nysjb.cn.gov.cn.nysjb.cn http://www.morning.qrcsb.cn.gov.cn.qrcsb.cn http://www.morning.znlhc.cn.gov.cn.znlhc.cn