1.获取部门成员 请求方式: GET( HTTPS ) 请求地址: https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=ACCESS_TOKENdepartment_id=DEPARTMENT_IDfetch_child=FETCH_CHILD 参数说明: 参数 必须 说明 acces
1.获取部门成员
请求方式:GET(HTTPS)
请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID&fetch_child=FETCH_CHILD
参数说明:
权限说明:
应用须拥有指定部门的查看权限。
返回结果:
{ "errcode": 0, "errmsg": "ok", "userlist": [ { "userid": "zhangsan", "name": "张三", "department": [1, 2], "open_userid": "xxxxxx" } ] }
参数说明:
2.代码示例
获取Token方法见 https://www.jb51.net/article/245491.htm
2.1 appsetting截图
2.2 返回值实体
public class GetUserByDepartmentResult { /// <summary> /// 错误编号 /// </summary> public int errcode { get; set; } /// <summary> /// 错误信息 /// </summary> public string errmsg { get; set; } /// <summary> /// 用户集合 /// </summary> public List<UserList> userlist { get;set;} } public class UserList { /// <summary> /// 用户ID /// </summary> public int userid { get; set; } /// <summary> /// 名称 /// </summary> public int name { get; set; } /// <summary> /// 部门列表 /// </summary> public string[] department { get; set; } }
2.3 获取部门信息方法
/// <summary> /// 获取用户通过部门id /// </summary> /// <param name="token">企业微信Token</param> /// <param name="department_id">部门id</param> /// <returns></returns> public static GetUserByDepartmentResult GetUserByDepartment(string token,int department_id) { //构造请求链接 var requestBuild = GlobalContext.Configuration["Wx:GetUserByDepartment"]; requestBuild = string.Format(requestBuild, token, department_id); using (var wxClient = GlobalContext.httpClientFactory.CreateClient("WxClient")) { var httpResponse = wxClient.GetAsync(requestBuild).Result; var result= JsonConvert.DeserializeObject<GetUserByDepartmentResult>( httpResponse.Content.ReadAsStringAsync().Result ); return result; } }
2.4 调用(作为下拉被调用)
public List<UserList> GetUserByDepartment() { List<UserList> userLists = new List<UserList>(); var (token, issuccess) = ApplicationContext.GetToken(); var result = ApplicationContext.GetUserByDepartment(token, 334); if(result.errcode == 0) { userLists = result.userlist; } return userLists; }
到此这篇关于.NET Core实现企业微信获取部门成员的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持易盾网络。