钉钉开发者通讯录管理api开放接口Java工具类
关于钉钉一起分享
package com.dingtalk.util;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.*;
import com.dingtalk.api.response.*;
import com.taobao.api.ApiException;
import java.util.List;
/**
* @author: liufeng
* @CreateDate: 2022/06/20
*/
public class DingTxlUtils {
/*** 使用范围 :A-企业内部应用 B- 第三方企业应用 C - 第三方个人应用 ***/
/************************** 通讯录管理---用户管理 ************************************/
/**
* 使用范围 :AB
* 查询用户详情
* @param access_token
* @param userId
* @param language
* @return
*/
public static OapiV2UserGetResponse.UserGetResponse getUserGetResponse(String access_token, String userId, String language) {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
OapiV2UserGetRequest req = new OapiV2UserGetRequest();
req.setUserid(userId);
if (null != language) {
req.setLanguage(language);
}
OapiV2UserGetResponse rsp = client.execute(req, access_token);
if (rsp.getErrcode() != 0L) {
return null;
}
return rsp.getResult();
} catch (ApiException e) {
e.printStackTrace();
}
return null;
}
/**
* 使用范围 :AB
* 获取部门用户基础信息
*
* @param access_token
* @param req
* @return
*/
public static List<OapiUserListsimpleResponse.ListUserSimpleResponse> getListUserSimpleResponse(
String access_token, OapiUserListsimpleRequest req) {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/user/listsimple");
OapiUserListsimpleResponse rsp = client.execute(req, access_token);
if (rsp.getErrcode() != 0L) {
return null;
}
OapiUserListsimpleResponse.PageResult response = rsp.getResult();
List<OapiUserListsimpleResponse.ListUserSimpleResponse> list = response.getList();
Boolean hasMore = response.getHasMore();
Long cursor = response.getNextCursor();
//是否还有更多的数据
while (hasMore) {
req.setCursor(cursor);
OapiUserListsimpleResponse rsp2 = client.execute(req, access_token);
if (rsp2.isSuccess() && rsp2.getErrcode().