Пример #1
0
        /// <summary>
        /// 获取部门成员
        /// </summary>
        /// <param name="departmentId"></param>
        /// <param name="fetchchild"></param>
        /// <returns></returns>
        public UserListEntity GetSimpleUserList(string departmentId, int fetchchild)
        {
            var            token   = IsExistAccess_Token();
            string         url     = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=" + token.access_token + "&department_id=" + departmentId + "&fetch_child=" + fetchchild;
            UserListEntity account = new UserListEntity();

            account = HttpGet(url).ToObject <UserListEntity>();
            return(account);
        }
Пример #2
0
        /// <summary>
        /// 同步员工
        /// </summary>
        /// <param name="keyword">关键字</param>
        /// <returns></returns>
        public ActionResult SyncMember()
        {
            //获取微信部门数据
            UserListEntity wXUserList = GetSimpleUserList("1", 1);

            if (wXUserList.errcode != 0)
            {
                return(Fail("微信接口错误码" + wXUserList.errcode + ",错误信息" + wXUserList.errmsg));
            }
            else
            {
                Dictionary <string, string> dir = new Dictionary <string, string>();
                foreach (var item in wXUserList.userlist)
                {
                    dir.Add(item.userid, item.name);
                }
                //获取当前
                var data = userIBLL.GetAllList();
                foreach (var item in data)
                {
                    WeChatUserEntity userEntity = new WeChatUserEntity();
                    if (string.IsNullOrEmpty(item.F_DepartmentId) || string.IsNullOrEmpty(item.F_Mobile))
                    {
                        continue;
                    }
                    if (dir.ContainsKey(item.F_Account))
                    {
                        if (dir[item.F_Account] != item.F_RealName)
                        {
                            userEntity.name   = item.F_RealName;
                            userEntity.mobile = item.F_Mobile;
                            userEntity.userid = item.F_Account;
                            userEntity.enable = 1;
                            if (item.F_DepartmentId != null)
                            {
                                var departmentEntity = departmentIBLL.GetEntity(item.F_DepartmentId);
                                userEntity.department = new List <int> {
                                    departmentEntity == null ? 0 : departmentEntity.F_EnCode.ToInt()
                                };
                            }
                            else
                            {
                                var companyEntity = companyIBLL.GetEntity(item.F_CompanyId);
                                userEntity.department = new List <int> {
                                    companyEntity == null ? 0 : companyEntity.F_EnCode.ToInt()
                                };
                            }
                            //更新微信部门成员
                            //var res = UpdateWXUser(userEntity);
                            //if (res.errcode != 0)
                            //{
                            //    item.F_Description = "微信接口错误码" + res.errcode + ",错误信息" + res.errmsg;
                            //    userIBLL.SaveEntity(item.F_UserId, item);
                            //    return Fail("微信接口错误码" + res.errcode + ",错误信息" + res.errmsg);
                            //    //continue;
                            //}
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        userEntity.name   = item.F_RealName;
                        userEntity.mobile = item.F_Mobile;
                        userEntity.userid = item.F_Account;
                        userEntity.enable = 1;
                        if (item.F_DepartmentId != null)
                        {
                            var departmentEntity = departmentIBLL.GetEntity(item.F_DepartmentId);
                            userEntity.department = new List <int> {
                                departmentEntity == null ? 0 : departmentEntity.F_EnCode.ToInt()
                            };
                        }
                        else
                        {
                            var companyEntity = companyIBLL.GetEntity(item.F_CompanyId);
                            userEntity.department = new List <int> {
                                companyEntity == null ? 0 : companyEntity.F_EnCode.ToInt()
                            };
                        }
                        //创建微部门成员
                        var res = CreateWXUser(userEntity);
                        if (res.errcode != 0)
                        {
                            item.F_Description = "微信接口错误码" + res.errcode + ",错误信息" + res.errmsg;
                            userIBLL.SaveEntity(item.F_UserId, item);
                            //return Fail("微信接口错误码" + res.errcode + ",错误信息" + res.errmsg);
                            continue;
                        }
                    }
                }
                return(Success(""));
            }
        }