Esempio n. 1
0
        /// <summary>
        /// 获取部门用户ID
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static List <string> GetUserId(string accessToken, string deptId)
        {
            try
            {
                IDingTalkClient client           = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/getDeptMember");
                OapiUserGetDeptMemberRequest req = new OapiUserGetDeptMemberRequest();

                req.DeptId = deptId;
                req.SetHttpMethod("GET");
                OapiUserGetDeptMemberResponse rsp = client.Execute(req, accessToken);

                if (rsp != null && rsp.Errcode == 0)
                {
                    if (rsp.UserIds[0].Length > 0)
                    {
                        return(rsp.UserIds);
                    }
                    else
                    {
                        throw new Exception(rsp.Errmsg);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(null);
        }
Esempio n. 2
0
 /// <summary>
 /// 获取部门用户userid列表
 /// </summary>
 /// <param name="accessToken"></param>
 /// <param name="parentId"></param>
 /// <returns></returns>
 public static List <string> GetDepartmentUserId(string accessToken, string departmentId)
 {
     try
     {
         IDingTalkClient client           = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/getDeptMember");
         OapiUserGetDeptMemberRequest req = new OapiUserGetDeptMemberRequest();
         req.DeptId = departmentId;
         req.SetHttpMethod("GET");
         OapiUserGetDeptMemberResponse response = client.Execute(req, accessToken);
         if (response != null)
         {
             if (response.Errcode == 0)
             {
                 List <string> userlist = new List <string>();
                 if (response.UserIds != null && response.UserIds.Count > 0)
                 {
                     foreach (string userid in response.UserIds)
                     {
                         userlist.Add(userid);
                     }
                 }
                 return(userlist);
             }
             else
             {
                 throw new Exception(response.Errmsg);
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     return(null);
 }
Esempio n. 3
0
        /// <summary>
        /// 获取部门用户userid列表
        /// </summary>
        /// <param name="accessToken">accessToken</param>
        /// <param name="deptId">部门id</param>
        /// <returns></returns>
        public OapiUserGetDeptMemberResponse GetDeptMember(string accessToken, string deptId)
        {
            IDingTalkClient client           = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/getDeptMember");
            OapiUserGetDeptMemberRequest req = new OapiUserGetDeptMemberRequest
            {
                DeptId = deptId
            };

            req.SetHttpMethod("GET");
            OapiUserGetDeptMemberResponse rsp = client.Execute(req, accessToken);

            return(rsp);
        }