using System; using System.Collections.Generic; using System.Text; using BP.DA; using BP.Tools; namespace BP.GPM.WeiXin { /// /// 部门下的人员 /// public class UserList { #region 属性. /// /// 返回码 /// public int errcode { get; set; } /// /// 对返回码的文本描述内容 /// public string errmsg { get; set; } /// /// 成员列表 /// public List userlist { get; set; } #endregion 属性. /// /// 初始化部门信息 /// public UserList() { } /// /// 部门ID /// /// public UserList(string deptID) { //获取token. string access_token = BP.GPM.WeiXin.WeiXinEntity.getAccessToken(); string url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=" + access_token + "&department_id=" + deptID + "&status=0"; //获得信息. string str = DataType.ReadURLContext(url); UserList userList = BP.Tools.FormatToJson.ParseFromJson(str); //赋值. this.errcode = userList.errcode; this.errmsg = userList.errmsg; this.userlist = userList.userlist; } } /// /// 部门人员详情 /// public class UserEntity { #region 属性. /// /// 成员UserID。对应管理端的帐号 /// public string userid { get; set; } /// /// 成员名称 /// public string name { get; set; } /// /// 成员所属部门 /// public object department { get; set; } /// /// 职位信息 /// public string position { get; set; } /// /// 手机号码 /// public string mobile { get; set; } /// /// 性别。0表示未定义,1表示男性,2表示女性 /// public string gender { get; set; } /// /// 邮箱 /// public string email { get; set; } /// /// 微信号 /// public string weixinid { get; set; } /// /// 头像url。注:如果要获取小图将url最后的"/0"改成"/64"即可 /// public string avatar { get; set; } /// /// 关注状态: 1=已关注,2=已冻结,4=未关注 /// public string status { get; set; } /// /// 扩展属性 /// public string extattr { get; set; } #endregion 属性. /// /// 获取指定部门下 指定手机号的人员 /// /// 部门编号 /// 手机号 /// public UserEntity(string deptID, string tel = null) { string access_token = BP.GPM.WeiXin.WeiXinEntity.getAccessToken(); string url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token= " + access_token + "&department_id=" + deptID + "&status=0"; //读取数据. string str = DataType.ReadURLContext(url); //获得用户列表. UserList users = FormatToJson.ParseFromJson(str); //从用户列表里找到tel的人员信息,并返回. foreach (UserEntity user in users.userlist) { if (user.mobile.Equals(tel)) { this.userid = user.userid; this.name = user.name; this.department = user.department; this.position = user.position; this.mobile = user.mobile; this.gender = user.gender; this.email = user.email; this.weixinid = user.weixinid; this.avatar = user.avatar; this.status = user.status; this.extattr = user.extattr; } } throw new Exception("err@该部门下查无此人."); } } /// /// 简写的User /// public class User { public int ErrCode { get; set; } public string ErrMsg { get; set; } public string UserId { get; set; } public string DeviceId { get; set; } } }