public static void main(String[] args) {
//----------------------获取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", "1212121");//业务id
jbdb.put("unionid", unionid);
jbdb.put("description", "待办备注描述,最大长度4096。");
long date=System.currentTimeMillis();
jbdb.put("dueTime", date);
String[] excutors={unionid};
jbdb.put("executorIds", excutors);
//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(resp11);
}
标签:unionid,String,创建,任务,待办,jbdb,JSONObject,put From: https://www.cnblogs.com/xujiating/p/16992575.html