public List <User> GetDeptUserList(Dept dept) { List <User> ulist = new List <User>(); IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/listbypage"); OapiUserListRequest request = new OapiUserListRequest(); request.DepartmentId = dept.DeptID; request.SetHttpMethod("GET"); request.Offset = 0; request.Size = 100; OapiUserListResponse execute = client.Execute(request, DdOper.AccessToken); if (execute.Userlist != null && execute.Userlist.Count > 0) { execute.Userlist.ForEach(p => { if (p.Active) { ulist.Add(new User { DdId = p.Userid, UserName = p.Name, DeptId = p.Department, Avatar = p.Avatar, IsLeader = p.IsLeader, DepartName = dept.DeptName });; } }); } return(ulist); }
/// <summary> /// 获取钉钉部门下的用户列表 /// </summary> /// <param name="token"></param> /// <param name="departmentId"></param> /// <returns></returns> public virtual List <OapiUserListResponse.UserlistDomain> UserSimplelistResponse(string token, long departmentId) { DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/list"); OapiUserListRequest request = new OapiUserListRequest(); request.DepartmentId = departmentId; request.SetHttpMethod("GET"); OapiUserListResponse response = client.Execute(request, token); if (response.Errcode != 0) { Console.WriteLine("错误原因:【" + response.Errmsg + "】"); } return(response.Userlist); }
/// <summary> /// 获取一个部门的用户列表 /// </summary> /// <param name="repuestParams"></param> /// <returns></returns> public List <Emplayee> GetOneDepEmplayee(RequestParams repuestParams) { IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/list"); OapiUserListRequest request = new OapiUserListRequest(); request.DepartmentId = repuestParams.DepId; request.Offset = repuestParams.OffSet; request.Size = repuestParams.Size; request.SetHttpMethod("GET"); OapiUserListResponse response = client.Execute(request, TooUtil.GetAccessToken()); if (response.Errcode == 0 && response.Userlist != null && response.Userlist.Count > 0) { response.Userlist.ForEach(u => { Emplayee emplayee = new Emplayee(); emplayee.EmpUserId = u.Userid; emplayee.EmpName = u.Name; emplayee.EmpUnionid = u.Unionid; emplayee.EmpMobile = u.Mobile; emplayee.EmpTel = u.Tel; emplayee.EmpWorkPlace = u.WorkPlace; emplayee.EmpRemark = u.Remark; emplayee.EmpOrder = u.Order; emplayee.EmpIsAdmin = u.IsAdmin; emplayee.EmpIsBoss = u.IsBoss; emplayee.EmpIsHide = u.IsHide; emplayee.EmpIsLeader = u.IsLeader; emplayee.EmpActive = u.Active; emplayee.EmpDepartmentIdsStr = u.Department; emplayee.EmpPosition = u.Position; emplayee.EmpEmail = u.Email; emplayee.EmpAvatar = u.Avatar; emplayee.EmpJobNumber = u.Jobnumber; emplayee.EmpExtattr = u.Extattr; if (empList.All <Emplayee>(k => k.EmpUserId != emplayee.EmpUserId)) { empList.Add(emplayee); } }); } if (response.HasMore) { GetOneDepEmplayee(repuestParams); } return(empList); }