【钉钉开发者通讯录管理api开放接口Java工具类】

钉钉开发者通讯录管理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().
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值