钉钉待办任务的创建
//----------------------获取accesstoken------
String appkey="dingythexhoab0d1nkq3";
String appsecret="AEySJvyiaKQ3b-9dF36Md3gSE5TsoN0uDu6Pe-6dFWSxO-QxzDIus31jYK0kGFO2";
String url = "https://oapi.dingtalk.com/gettoken?appkey="+appkey+"&appsecret="+appsecret;
JSONObject resp= JwtHttpUtil.httpRequest(url, "GET", null,null);
String accesstoken=resp.get("access_token").toString();
System.out.println(accesstoken);
//----------------------获取用户的unionid------
JSONObject jb=new JSONObject();
jb.put("userid", "16575012482877410");
String url1 = "https://oapi.dingtalk.com/topapi/v2/user/get?access_token="+accesstoken;
JSONObject resp1= JwtHttpUtil.httpRequest(url1, "POST", jb.toString(),null);
JSONObject result=(JSONObject) resp1.get("result");
String unionid=(String) result.get("unionid");
System.out.println(unionid);
//----------------------创建待办任务------
JSONObject jbdb=new JSONObject();
jbdb.put("subject", "test");//待办标题,最大长度1024
jbdb.put("sourceId", UUID.randomUUID());//业务id
jbdb.put("creatorId", unionid);//创建者的unionid
jbdb.put("description", "待办备注描述,最大长度4096。");//待办备注描述,最大长度4096
long date=System.currentTimeMillis();
jbdb.put("dueTime", date);//截止时间
String[] excutors={unionid};
jbdb.put("executorIds", excutors);//执行者的unionId
String[] participantIds={unionid};
jbdb.put("participantIds", participantIds);//参与者的unionId
JSONObject detailUrl=new JSONObject();
detailUrl.put("appUrl", "http://10.182.21.11:8080/jeecg");//APP端详情页url跳转地址
detailUrl.put("pcUrl", "http://10.182.21.11:8080/jeecg");//PC端详情页url跳转地址
jbdb.put("detailUrl", detailUrl);//详情页url跳转地址,如果不传,默认为个人待办
jbdb.put("isOnlyShowExecutor", true);//生成的待办是否仅展示在执行者的待办列表中。
jbdb.put("priority", 30);//优先级,取值:10:较低20:普通30:紧急40:非常紧急
//JSONObject notifyConfigs=new JSONObject();//待办通知配置
//notifyConfigs.put("dingNotify", "1");
//jbdb.put("notifyConfigs", notifyConfigs);
// 创建待办
// String createdburl="https://api.dingtalk.com/v1.0/todo/users/"+unionid+"/tasks";
// JSONObject resp11= JwtHttpUtil.httpRequest(createdburl, "POST", jbdb.toString(),accesstoken);
// System.out.println((String) resp11.get("id"));
// System.out.println(resp11);
//删除待办
//String id=(String) resp11.get("id");
// String taskid="taskbfbad02e99d457313a1b851ca8ce1c4f";
// String deletetask="https://api.dingtalk.com/v1.0/todo/users/"+unionid+"/tasks/"+taskid+"";
// JSONObject deleteresp= JwtHttpUtil.httpRequest(deletetask, "DELETE", jbdb.toString(),accesstoken);
// System.out.println(deleteresp);
//更新待办内容
// String taskid="task5d45b90dadead3eec1767eb01897be82";
// String updatetask="https://api.dingtalk.com/v1.0/todo/users/"+unionid+"/tasks/"+taskid+"";
// JSONObject jbdbupdate=new JSONObject();
// jbdbupdate.put("subject", "String");//待办标题
// jbdbupdate.put("description", "String");//待办描述
// JSONObject updateresp= JwtHttpUtil.httpRequest(updatetask, "PUT", jbdbupdate.toString(),accesstoken);
// System.out.println(updateresp);
//更新待办执行者状态
// String taskid="taskbffab368b06e8d7051cc63852c889b9c";
// String updatetask="https://api.dingtalk.com/v1.0/todo/users/"+unionid+"/tasks/"+taskid+"/executorStatus";
// JSONObject jupdate=new JSONObject();
// JSONArray jsarry=new JSONArray();
// JSONObject jbdbupdate=new JSONObject();
// jbdbupdate.put("id", unionid); //用户的uoionid
// jbdbupdate.put("isDone", true);//是否完成
// jsarry.add(jbdbupdate);
// jupdate.put("executorStatusList", jsarry);
// JSONObject updateresp= JwtHttpUtil.httpRequest(updatetask, "PUT", jupdate.toString(),accesstoken);
// System.out.println(updateresp);
//查询企业中用户待办列表
String query="https://api.dingtalk.com/v1.0/todo/users/"+unionid+"/org/tasks/query";
JSONObject jbdbquery=new JSONObject();
jbdbquery.put("isDone", false);
JSONObject resp11= JwtHttpUtil.httpRequest(query, "POST", jbdbquery.toString(),accesstoken);
System.out.println(resp11);