JAVAmaven项⽬使⽤钉钉SDK获取token、⽤户
本⽂介绍了JAVA maven项⽬使⽤钉钉SDK获取token、⽤户,分享给⼤家,具体如下:
将SDK放⼀个⽂件⾥,记住⽂件地址。D:\eclipse-workspace\项⽬名\模块名\lib
win+r cmd 敲下⾯的命令:
【进⼊相应盘】  D:
【进⼊⽂件地址】  cd D:\eclipse-workspace\项⽬名\模块名
【运⾏命令】  mvn install:install-file -DgroupId=com.dingtalk.api -DartifactId=top-api-sdk-dev -Dversion=ding-open-mc-SNAPSHOT -Dfile=lib/taobao-sdk-java-auto_1479188381469-20200319.jar -Dpackaging=jar -DgeneratePom=true
然后在pom⽂件中增加以下内容:
sdk<!--钉钉⼯具包-->
<dependency>
<groupId>com.dingtalk.api</groupId>
<artifactId>top-api-sdk-dev</artifactId>
<version>ding-open-mc-SNAPSHOT</version>
</dependency>
理解:普通的maven项⽬都会在pom⾥配置好jar,项⽬⾃动从maven中配置的镜像地址(就是⽹上)⾃⼰把jar包下载到你设置的位置
但是有些jar包下载不下来,可以先本地保存,然后像上⾯那样⽤命令把jar包挂到maven设置的jar库⾥去
JAVA后台代码:
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.quest.OapiDepartmentListRequest;
import com.quest.OapiGettokenRequest;
import com.quest.OapiMessageCorpconversationAsyncsendV2Request;
import com.quest.OapiUserSimplelistRequest;
import com.sponse.OapiDepartmentListResponse;
import com.sponse.OapiGettokenResponse;
import com.sponse.OapiMessageCorpconversationAsyncsendV2Response;
import com.sponse.OapiUserSimplelistResponse;
import com.taobao.api.ApiException;
import com.sponse.OapiDepartmentListResponse.Department;
import com.quest.*;
import com.sponse.*;
。。
登录接⼝⽅法(前端传来code){
// 钉钉 /gettoken 获取token,只需填写appkey和appsecret
try {
DingTalkClient client1 = new DefaultDingTalkClient("oapi.dingtalk/gettoken");
OapiGettokenRequest req1 = new OapiGettokenRequest();
req1.setAppkey("xxxxxxxx");
req1.setAppsecret("xxxxxxxx");
req1.setHttpMethod("GET");
OapiGettokenResponse rsp1 = ute(req1);
System.out.Body());
accessToken = AccessToken();
} catch (Exception e) {
//} catch (ApiException e) {
e.printStackTrace();
}
// 钉钉 /user/getuserinfo 获取⽤户userid
try {
DingTalkClient client2 = new DefaultDingTalkClient("oapi.dingtalk/user/getuserinfo");
OapiUserGetuserinfoRequest req2 = new OapiUserGetuserinfoRequest();
req2.setCode(code);//
req2.setHttpMethod("GET");
OapiUserGetuserinfoResponse rsp2 = ute(req2, accessToken);//
System.out.Body());
userId = Userid();
System.out.println("userId:" + userId);
System.out.println("------------------------------------------------------");
} catch (ApiException e) {
e.printStackTrace();
}
// 钉钉 /user/get 获取⽤户详情
try {
DingTalkClient client3 = new DefaultDingTalkClient("oapi.dingtalk/user/get");
OapiUserGetRequest req3 = new OapiUserGetRequest();
req3.setUserid(userId);//
req3.setHttpMethod("GET");
OapiUserGetResponse rsp3 = ute(req3, accessToken);//
System.out.Body());
} catch (ApiException e) {
e.printStackTrace();
}
   // 钉钉获取所有部门列表
  try {
DingTalkClient client4 = new DefaultDingTalkClient("oapi.dingtalk/department/list");
OapiDepartmentListRequest req4 = new OapiDepartmentListRequest();
req4.setHttpMethod("GET");
req4.setId("1");
OapiDepartmentListResponse rsp4 = ute(req4, accessToken);
System.out.println("-----------------获取所有部门列表-----------------");
System.out.Body());
List<Department> departmentList = Department();
System.out.println("-----------------------------------------------------");
   // [{id: xxx, parentid: xxx, ......},{id: xxx, parentid: xxx, ......},{id: xxx, parentid: xxx, ......},{id: xxx, parentid: xxx, ......}]
System.out.(0).getId();
    Long parentid = (0).getParentid();
} catch (ApiException e) {
e.printStackTrace();
} 
}
到此这篇关于JAVA maven项⽬使⽤钉钉SDK获取token、⽤户的⽂章就介绍到这了,更多相关maven 钉钉SDK获取token、⽤户内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。