钉钉调用新版待办任务
前言
今天公司通知需求需要使用钉钉的待办任务,查了下API发现待办任务在上个月的时候更新了接口,旧版的使用不了,而新版的接口也还没有教程,故写了这篇文章。
这里是API链接 钉钉新增待办任务
一、准备工作
首先要在钉钉开发者后台创建一个应用,然后开放待办任务下的所有权限。
然后要下载钉钉jar包,我用的是21年八九月的包,在maven上没法自动导入,这里提供下载链接。
链接:https://pan.baidu.com/s/1YG3l8THirXVtrhgHWZbLwQ 提取码:qqs5接着是新版待办要使用的sdk,这里使用maven导入就可以。
<dependency><groupId>com.aliyun</groupId><artifactId>dingtalk</artifactId><version>1.1.96</version></dependency>
二、代码部分
1.前置方法
下面是封装好的小组件,用于获取Token等
AppKey和AppSecret
/*** 获取钉钉token* @param appKey AppKey* @param appSecret AppSecret* @return token字符串*/public static String getToken(String appKey, String appSecret) {//token两小时更新一次DingTalkClient getTokenclient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");OapiGettokenRequest request = new OapiGettokenRequest();request.setAppkey(appKey);request.setAppsecret(appSecret);request.setHttpMethod("GET");OapiGettokenResponse response = null;try {response = getTokenclient.execute(request);} catch (ApiException e) {e.printStackTrace();}return response.getAccessToken();}/*** 通过手机号获取用户的userId* @param mobile 手机号* @param appKey AppKey* @param appSecret AppSecret* @return userId*/public static String getUserId (String mobile, String appKey, String appSecret) {//获取用户uridDingTalkClient getUridClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/getbymobile");OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest();req.setMobile(mobile);OapiV2UserGetbymobileResponse rsp = null;try {rsp = getUridClient.execute(req, getToken(appKey, appSecret));} catch (ApiException e) {e.printStackTrace();}return rsp.getResult().getUserid();}/*** 通过userid获取用户对象* @param userId userid* @param appKey AppKey* @param appSecret AppSecret* @return 用户对象*/public static OapiV2UserGetResponse.UserGetResponse getUserInfo (String userId, String appKey, String appSecret) {//获取用户uridDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");OapiV2UserGetRequest req = new OapiV2UserGetRequest();req.setUserid(userId);req.setLanguage("zh_CN");OapiV2UserGetResponse rsp = null;try {rsp = client.execute(req, getToken(appKey, appSecret));} catch (ApiException e) {e.printStackTrace();}return rsp.getResult();}
2.核心方法
根据手机号发送待办任务
public static void sendWorkRecordByMobile (String mobile, String title, String context, Long date, String appKey, String appSecret) {String unionId = getUserInfo(getUserId(mobile, appKey, appSecret), appKey, appSecret).getUnionid();com.aliyun.dingtalktodo_1_0.Client client = null;try {client = createClient();} catch (Exception e) {e.printStackTrace();}CreateTodoTaskHeaders createTodoTaskHeaders = new CreateTodoTaskHeaders();createTodoTaskHeaders.xAcsDingtalkAccessToken = getToken(appKey, appSecret);CreateTodoTaskRequest.CreateTodoTaskRequestNotifyConfigs notifyConfigs = new CreateTodoTaskRequest.CreateTodoTaskRequestNotifyConfigs().setDingNotify("1");
// CreateTodoTaskRequest.CreateTodoTaskRequestDetailUrl detailUrl = new CreateTodoTaskRequest.CreateTodoTaskRequestDetailUrl()
// // app内打开的链接
// .setAppUrl("https://www.dingtalk.com")
// // pc端打开的链接
// .setPcUrl("https://www.dingtalk.com");CreateTodoTaskRequest createTodoTaskRequest = new CreateTodoTaskRequest()// 待办标题.setSubject(title).setCreatorId(unionId)// 待办内容.setDescription(context)// 截止时间,使用时间戳.setDueTime(date)// 接收消息的人.setExecutorIds(java.util.Arrays.asList(unionId))
// .setDetailUrl(detailUrl).setIsOnlyShowExecutor(true)// 紧急程度,分4档,此处为2档普通.setPriority(20).setNotifyConfigs(notifyConfigs);try {client.createTodoTaskWithOptions(unionId, createTodoTaskRequest, createTodoTaskHeaders, new RuntimeOptions());} catch (TeaException err) {if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {// err 中含有 code 和 message 属性,可帮助开发定位问题System.out.println(err.message);}} catch (Exception _err) {TeaException err = new TeaException(_err.getMessage(), _err);if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {// err 中含有 code 和 message 属性,可帮助开发定位问题System.out.println(err.message);}}}
注意:新版发送待办使用的是unionid而不是userid
调用方法
sendWorkRecordByMobile("手机号", "待办测试", "待办内容", "截止时间戳", AppKey, AppSecret);
钉钉调用新版待办任务相关推荐
- java消息推送怎么实现_调用钉钉接口实现机器人推送消息
一.摘要 现实交易中为了能及时了解发明者量化机器人交易状态,有时候我们需要将机器人所执行的交易结果发送到微信.邮箱.短信等等.但每天上百条各种各样的信息,使得对这些信息已经不敏感,导致重要的信息不能及 ...
- 钉钉考勤接口python3.6调用
钉钉考勤接口调用 import requests import jsonappkey = "appkey" appsecret = "appsecret" de ...
- 钉钉考勤接口调用与OA系统数据对接(多线程版)
钉钉考勤接口调用与OA系统数据对接(多线程版) 公司由原来的指纹打卡更换为钉钉打卡,需要钉钉和现有的OA考勤数据对接(合并钉钉打卡数据和OA上的请假,外出,出差数据),因为人数增减单线程定时任务数据抓 ...
- 调用钉钉api报错:机器人发送签名过期;solution:签名生成时间和发送时间请保持在 timestampms 以内
背景 以往没有出现问题的钉钉消息推送,今天突然出现了问题提示: description:机器人发送签名过期;solution:签名生成时间和发送时间请保持在 timestampms 以内 解决方法 将 ...
- 钉钉通知-调用钉钉发送企业内部消息开发
首先,我们要明确需求:自己的系统需要发送通知消息到用户,接收消息用户为同一企业内的人员,选用短信可能涉及到费用问题,故可以选用钉钉或者企业微信,在此我使用钉钉进行发送消息. 调用钉钉发送企业内部消息: ...
- 钉钉考勤接口调用与OA系统数据对接
钉钉考勤接口调用与OA系统数据对接 公司由原来的指纹打卡更换为钉钉打卡,需要钉钉和现有的OA考勤数据对接(合并钉钉打卡数据和OA上的请假,外出,出差数据) 1.查看钉钉接口文档 https://din ...
- WinForm开发钉钉(1) 调用机器人发送消息到钉钉群
此文章借鉴钉钉系列教程http://blog.csdn.net/wxbluethink/article/details/77435242,增加自己的理解,记录钉钉通过调用机器人发送消息到钉钉群. 环境 ...
- C# 调用钉钉接口进行发送企业通知消息,适应于网页版
前期资料如怎么配置,怎么创建应用 参考:http://blog.csdn.net/xxdddail/article/category/6776456 感谢原作者 Oa效果图如下: 引用: TopSDK ...
- js调用扫描仪(Web Twain Scan)-兼容Chrome、Edge、360、Firefox、IE、钉钉、企业微信等
js调用扫描仪(Web Twain Scan) -兼容Chrome.Edge.360.Firefox.IE.钉钉.企业微信等 前言 测试使用说明 example 相关地址 前言 琼羽中间件,旨在实现兼 ...
最新文章
- VS快捷键大全(总结了一些记忆的口诀)
- vue项目中的tab页实现
- 递归行为时间复杂度估算
- 通过Dapr实现一个简单的基于.net的微服务电商系统(十八)——服务保护之多级缓存...
- java连接zookeeper_java 学习笔记(四) java连接ZooKeeper
- deepin启动盘无法引导安装_deepin 无法启动问题解决
- 「管理数学基础」3.3 凸分析:凸函数的极值和凸规划
- macOS Big Sur无法完成安装 Big Sur为什么安装不了?
- 用户空间缺页异常pte_handle_fault()分析--(上)【转】
- AT89C51中断模板(宏定义)
- 怀旧服服务器一般什么时候维护,魔兽世界怀旧服9月16日重启维护结束时间 9.16怀旧服登录不了游戏解决方法_蚕豆网新闻...
- 2021-03-15
- arcEngine开发之IMapControl接口
- SpringCloud 微服务工具集v1.1
- Hark的数据结构与算法练习之珠排序
- 区块链基础与网络安全
- Springboot项目 logging level配置
- 学生机房管理服务器系统,学生机房管理助手
- 永磁无刷电机及其驱动技术_PDF.rar
- java 鱼刺图_Java JSR-133 因果关系中 6.3.1的例子为什么会出现r1==r2==1呢?
热门文章
- BZOJ5473: 仙人掌
- FileNotFoundError: [Errno 2] No such file or directory: ‘ETHZ/eth01/images/image_00000001_2021-10-29
- 基因家族分析③:linux下hmmer的安装与使用
- 计算机通讯技术核心期刊有哪些,通信技术专业的核心期刊有哪些
- Android开发——简单计算器实现
- 一句话木马的工作原理
- SIM900A模块开发:通过GPRS连接OneNet平台发送GPS信息
- 如何理解Redis中的事务
- 基于springboot+vue个人博客搭建
- send sendto ,recv recvfrom有什么区别