Exemplo n.º 1
0
 public QyCallResult UpdateMember(string accessToken, Member member)
 {
     return
         (MailListApi.UpdateMember(accessToken, member.Userid, member.Name,
                                   member.Department.ToArray(), member.Position, member.Mobile,
                                   member.Email, member.WeixinId, member.Enable).ToQyCallResult());
 }
Exemplo n.º 2
0
        public WorkJsonResult UpdateDepartment(UpdateDepartmentDto dto)
        {
            dto.AccessToken = GetAccessToken(QyConfig.CorpID, QyConfig.CorpSecret);
            var result = MailListApi.UpdateDepartment(dto.AccessToken, dto.ID, dto.Name, dto.ParentId, dto.Order);

            return(result);
        }
Exemplo n.º 3
0
        public IActionResult OAuth(string code, string state)
        {
            var tokenResult = CommonApi.GetToken(WeixinOptions.CorpId, WeixinOptions.Secret);

            var openInfo = new Senparc.Weixin.QY.AdvancedAPIs.OAuth2.GetUserInfoResult();

            try
            {
                openInfo = OAuth2Api.GetUserId(tokenResult.access_token, code);
            }
            catch (ErrorJsonResultException e) when(e.JsonResult.errcode == Senparc.Weixin.ReturnCode.合法的oauth_code)
            {
                ViewData["Message"] = Newtonsoft.Json.JsonConvert.SerializeObject(e.JsonResult, Newtonsoft.Json.Formatting.Indented);
                return(View());
            }
            //catch (ArgumentNullException e)
            //{
            //    ViewData["Message"] = e.Message;
            //    return View();
            //}

            if (string.IsNullOrEmpty(openInfo.UserId))
            {
                ViewData["Message"] = "非企业人员,考勤功能不可用!";
            }
            else
            {
                //ViewData["Member"] = MailListApi.GetMember(tokenResult.access_token, openInfo.UserId);
                ViewData["DepartmentList"] = MailListApi.GetDepartmentList(tokenResult.access_token);
            }

            return(View());
        }
Exemplo n.º 4
0
        public WorkJsonResult DeleteDepartment(DeleteDepartmentDto dto)
        {
            dto.AccessToken = GetAccessToken(QyConfig.CorpID, QyConfig.CorpSecret);
            var result = MailListApi.DeleteDepartment(dto.AccessToken, dto.ID);

            return(result);
        }
Exemplo n.º 5
0
        public CreateDepartmentResult CreateDepartment(CreateDepartmentDto dto)
        {
            dto.AccessToken = GetAccessToken(QyConfig.CorpID, QyConfig.CorpSecret);
            var result = MailListApi.CreateDepartment(dto.AccessToken, dto.Name, dto.ParentId, dto.Order, dto.ID);

            return(result);
        }
Exemplo n.º 6
0
        public GetDepartmentListResult GetDepartmentList(GetDepartmentListDto dto)
        {
            dto.AccessToken = GetAccessToken(QyConfig.CorpID, QyConfig.CorpSecret);
            var result = MailListApi.GetDepartmentList(dto.AccessToken, dto.ID);

            return(result);
        }
Exemplo n.º 7
0
        public ResultJSON<UserDTO> Get(string id)
        {
            r.CurrentUser = UserName;

            var result = new UserDTO
            {
                WorkInfo = MailListApi.GetMember(option.AccessToken, id)
            };

            var model = r.FirstOrDefault(u => u.UserId == id);
            if (model == null)
            {
                var user = new User
                {
                    Name = result.WorkInfo.name,
                    UserId = result.WorkInfo.userid,
                    AccountName = result.WorkInfo.name
                };
                model = r.Insert(user);
            }

            result.LocalInfo = model;

            return new ResultJSON<UserDTO>
            {
                Code = 0,
                Data = result
            };
        }
Exemplo n.º 8
0
        public TreeNode <DepartmentList> GetTree()
        {
            var result = MailListApi.GetDepartmentList(APP_KEY);
            var tree   = InitTree(result.department);

            return(tree);
        }
Exemplo n.º 9
0
        public WorkJsonResult GetMember(GetMemberDto dto)
        {
            //dto.AccessToken = GetAccessToken(QyConfig.CorpID, QyConfig.CorpSecret);
            var result = MailListApi.GetMember(dto.AccessToken, dto.ID);

            return(result);
        }
Exemplo n.º 10
0
        public WorkJsonResult GetDepartmentMemberInfo(GetDepartmentMemberInfoDto dto)
        {
            //dto.AccessToken = GetAccessToken(QyConfig.CorpID, QyConfig.CorpSecret);
            var result = MailListApi.GetDepartmentMemberInfo(dto.AccessToken, dto.DepartmentId, dto.FetchChild);

            return(result);
        }
Exemplo n.º 11
0
        public List <GetMemberResult> GetListData(int iPage, int iCount, ref int iTotal)
        {
            string strID = Request["DeptId"];
            //Defect #14487 bug修正
            string strSearchCondition = Request["SearchCondition"];

            if (!string.IsNullOrEmpty(strID))
            {
                var lst = MailListApi.GetDepartmentMemberInfo(GetToken(), int.Parse(strID), 1, 0).userlist;//递归的去取子部门下面的成员
                if (!string.IsNullOrEmpty(strSearchCondition))
                {
                    // Defect#15596修正&性能改善
                    strSearchCondition = strSearchCondition.Trim().ToLower();

                    lst = lst.Where(x => x.userid.ToLower().Contains(strSearchCondition) ||
                                    (x.email != null && x.email.ToLower().Contains(strSearchCondition)) ||
                                    x.name.ToLower().Contains(strSearchCondition)).ToList();
                }

                iTotal = lst.Count();

                return(lst.Skip((iPage - 1) * iCount).Take(iCount).ToList());
            }

            return(null);
        }
        public JsonResult GetSubDepartment(string id, string departlist)
        {
            string accessToken = WeChatCommonService.GetWeiXinToken(AppId);
            //修改Department数据源 先根据AppId获取应用信息 allowPartys  Pending

            var config = WeChatCommonService.GetWeChatConfigByID(AppId);

            var app = AppApi.GetAppInfo(accessToken, int.Parse(config.WeixinAppId));
            GetAppInfo_AllowPartys allowPartys = app.allow_partys;

            // TODO: async/await执行较长等待的task
            var subdepartList = MailListApi.GetDepartmentList(accessToken, Int32.Parse(id)).department;//.Where(x => allowPartys.partyid.Contains(x.id)).ToList()

            var listReturn = EasyUITreeData.GetTreeData(subdepartList, "id", "name", "parentid");

            listReturn.ForEach(a =>
            {
                a.state = "closed";
            });

            if (!string.IsNullOrEmpty(departlist))
            {
                var departids = departlist.Split('|');
                EasyUITreeData.SetChecked <string>(departids.ToList(), listReturn);
            }

            return(Json(listReturn, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 13
0
        /// <summary>
        /// 添加标签成员
        /// </summary>
        /// <returns></returns>
        public JsonResult addTagMember(string[] userlist, string tagId)
        {
            string accessToken = GetToken();

            MailListApi.AddTagMember(accessToken, Int32.Parse(tagId), userlist);
            return(Json(doJson(null), JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 14
0
        //[TestMethod]
        public void UpdateMemberTest(string userId)
        {
            var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);

            var memberUpdateRequest = new MemberUpdateRequest()
            {
                userid       = userId,
                english_name = "new english name",
                department   = new long[] { 2 },
                gender       = "1",
                email        = "*****@*****.**"
            };

            var result = MailListApi.UpdateMember(accessToken, memberUpdateRequest);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功);

            //校验更新成功
            var newMemberData = MailListApi.GetMember(accessToken, userId);

            Assert.AreEqual(memberUpdateRequest.english_name, newMemberData.english_name);
            Assert.AreEqual(memberUpdateRequest.email, newMemberData.email);

            Console.WriteLine("new user info:" + newMemberData.ToJson());
        }
Exemplo n.º 15
0
        //[TestMethod]
        public void CreateMemberTest(string userId)
        {
            Extattr extattr = new Extattr()
            {
                attrs = new List <Attr>()
                {
                    new Attr()
                    {
                        name = "员工角色", value = "123"
                    }
                }
            };
            var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);

            var memberCreateRequest = new  MemberCreateRequest()
            {
                userid       = userId,
                name         = string.Format("单元测试生成-{0}", SystemTime.Now.ToString("yyMMdd-HH:mm:ss")),
                english_name = "english name",
                department   = new long[] { 2 },
                gender       = "1",
                email        = "*****@*****.**",
                extattr      = extattr
            };

            var result = MailListApi.CreateMember(accessToken, memberCreateRequest);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功);
        }
Exemplo n.º 16
0
        public override JsonResult Delete(string sIds)
        {
            if (!string.IsNullOrEmpty(sIds))
            {
                try
                {
                    string[] arrID = sIds.Split(',');
                    foreach (string strID in arrID)
                    {
                        if (string.IsNullOrEmpty(strID))
                        {
                            continue;
                        }
                        MailListApi.DeleteDepartment(GetToken(), strID);
                    }
                }
                catch (ErrorJsonResultException ex)
                {
                    WxJsonResult jsResult = ex.JsonResult;
                    string       errorMsg = ((ReturnCode_QY)jsResult.errcode).ToString();
                    return(ErrorNotification(errorMsg));
                }
            }
            else
            {
                //_BaseService.Delete(objModal);
            }

            _cacheManager.Remove("DepartmentList");
            return(Json(doJson(null), JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 17
0
        public JsonResult PostDept(DepartmentList objModal, int?Id)
        {
            //验证错误
            if (!BeforeAddOrUpdate(objModal, Id))
            {
                return(Json(GetErrorJson(), JsonRequestBehavior.AllowGet));
            }

            //objModal.id = int.Parse(Request["deptid"]);
            try
            {
                if (Id.HasValue && Id.Value > 0)
                {
                    MailListApi.UpdateDepartment(GetToken(), objModal);
                }
                else
                {
                    MailListApi.CreateDepartment(GetToken(), objModal);
                }
            }
            catch (ErrorJsonResultException ex)
            {
                WxJsonResult jsResult = ex.JsonResult;
                string       errorMsg = ((ReturnCode_QY)jsResult.errcode).ToString();
                return(ErrorNotification(errorMsg));
            }

            _cacheManager.Remove("DepartmentList");

            return(Json(doJson(null), JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 18
0
        public ActionResult GetSFCode(string lillyID, string openID, string clientID)
        {
            if (!VerifyNewParam("lillyid,openid", clientID, _signCheckService))
            {
                return(ErrMsg());
            }

            var result   = false;
            var strToken = GetToken();
            var userInfo = MailListApi.GetMember(strToken, lillyID);

            System.Random r  = new Random();
            int           rr = r.Next(100000, 999999);

            DateTime dttemp   = DateTime.Now.AddMinutes(-5);
            var      sfSearch = _shunFengInfoService.Repository.Entities.Where(
                t => t.LillyId == lillyID.ToUpper() && t.ValidBefore >= dttemp && t.IsValid == 0).FirstOrDefault();

            //int inttemp = sfSearch.ToList().Count;

            if (sfSearch != null)
            {
                result = true;
            }
            else
            {
                _shunFengInfoService.Repository.Insert(new ShunFengInfo()
                {
                    LillyId       = lillyID.ToUpper(),
                    OpenId        = openID.ToUpper(),
                    Email         = userInfo.email.ToUpper(),
                    Code          = rr.ToString(),
                    ValidBefore   = DateTime.Now,
                    CreatedUserID = "",
                    CreatedDate   = DateTime.Now,
                    UpdatedUserID = "",
                    UpdatedDate   = DateTime.Now,
                    IsDeleted     = false,
                    IsValid       = 0
                });

                if (_shunFengInfoService.Repository.Entities.Where(
                        t => t.LillyId == lillyID.ToUpper() && t.ValidBefore >= dttemp && t.IsValid == 0).FirstOrDefault() != null)
                {
                    result = true;
                }
            }

            if (result)
            {
                var jsonString = CommonService.GetSysConfig("SFEmail", "");
                _objService.SendMail(lillyID.ToUpper(), 0, rr.ToString(), jsonString, "", "", "验证码", true);
            }

            return(Json(new
            {
                result = result,
            }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 19
0
        /// <summary>
        /// 跳转通过oauth获取ticket, 主要逻辑以及跳转在WeChatBaseController中完成
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="uri"></param>
        /// <returns></returns>
        public ActionResult GetTicketExt(int appId, string uri)
        {
            string UserId = ViewBag.WeChatUserID;

            if (string.IsNullOrEmpty(UserId))
            {
                return(Content("用户ID为空,请确定您已经关注企业号并且您的状态是在职!"));
            }

            log.Debug("API GetTicket Start  UserID:{0} Uri:{1} URL:{2}", UserId, uri, Request.Url);

            string enTicket = EncryptionHelper.ConvertBase64(DesHelper.Encrypt(UserId + "|" + DateTime.UtcNow.ToFileTime().ToString(), CommonService.GetSysConfig("EncryptKey", "")));

            string backUrl;//= EncryptionHelper.DecodeFrom64(uri) + enTicket;

            if (uri.IndexOf("_") >= 0)
            {
                var u  = uri.Split('_');
                var u1 = EncryptionHelper.DecodeFrom64(u[0]);

                backUrl = u1;
                // backUrl = (u1.IndexOf("?") >= 0 ? "&" : "?") + EncryptionHelper.DecodeFrom64(u[1]) + enTicket;
            }
            else
            {
                backUrl = EncryptionHelper.DecodeFrom64(uri);
            }

            string strRet = "";

            if (backUrl.IndexOf("ticket=") > 0)
            {
                strRet = backUrl + enTicket;
            }
            else
            {
                strRet = backUrl + (backUrl.IndexOf("?") >= 0 ? "&" : "?") + "ticket=" + enTicket;
            }

            var strToken = GetTokenExt();
            var userInfo = MailListApi.GetMember(strToken, UserId);

            // var userInfo = UserApi.Info(weChatConfig.WeixinAppId, weChatConfig.WeixinCorpSecret, openid);

            strRet = strRet + "&extend1=";

            if (userInfo != null)
            {
                strRet = strRet + userInfo;
            }
            else
            {
                log.Error("用户不存在: userid:{0}", UserId);
            }

            log.Debug("API GetTicket End  backUrl:{0}", strRet);

            return(Redirect(strRet));
        }
Exemplo n.º 20
0
        //[TestMethod]
        public void DeleteTagTest(int tagId)
        {
            var accessToken = AccessTokenContainer.GetToken(_corpId);
            var result      = MailListApi.DeleteTag(accessToken, tagId);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode.请求成功);
        }
Exemplo n.º 21
0
        //[TestMethod]
        public void DelTagMemberTest(int tagId)
        {
            var accessToken = AccessTokenContainer.GetToken(_corpId);
            var result      = MailListApi.DelTagMember(accessToken, tagId, new[] { "TYSZCC" });

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode.请求成功);
        }
Exemplo n.º 22
0
        //[TestMethod]
        public void UpdateMemberTest(int tagId)
        {
            var accessToken = AccessTokenContainer.GetToken(_corpId);
            var result      = MailListApi.UpdateTag(accessToken, tagId, "ceshi2");

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode_QY.请求成功);
        }
Exemplo n.º 23
0
        //[TestMethod]
        public void DeleteDepartmentTest(long id)
        {
            var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);
            var result      = MailListApi.DeleteDepartment(accessToken, id);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功);
        }
        public JsonResult renameTag(string Id, string tagName)
        {
            string accessToken = GetToken();

            MailListApi.UpdateTag(accessToken, Int32.Parse(Id), tagName);
            WeChatCommonService.ClearDepartmentTagMapCache(this.AccountManageID);
            return(Json(doJson(null), JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 25
0
        public static List <TagItem> GetTagListByAccountManageID(int accountManageId)
        {
            var config  = WeChatCommonService.lstSysWeChatConfig.Find(a => a.AccountManageId == accountManageId);
            var token   = AccessTokenContainer.TryGetToken(config.WeixinCorpId, config.WeixinCorpSecret);
            var tagList = MailListApi.GetTagList(token).taglist;

            return(tagList);
        }
        /// <summary>
        /// 添加标签
        /// </summary>
        /// <returns></returns>
        public JsonResult addTag(string tagName)
        {
            string accessToken = GetToken();

            MailListApi.CreateTag(accessToken, tagName);

            return(Json(doJson(null), JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 27
0
        //[TestMethod]
        public void GetTagMemberTest(int tagId)
        {
            var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);
            var result      = MailListApi.GetTagMember(accessToken, tagId);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功);
        }
Exemplo n.º 28
0
        //[TestMethod]
        public void BatchDeleteMemberTest(string[] userIds)
        {
            var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);
            var result      = MailListApi.BatchDeleteMember(accessToken, userIds);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功);
        }
Exemplo n.º 29
0
        //[TestMethod]
        public void UpdateMemberTest(string userId)
        {
            var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);
            var result      = MailListApi.UpdateMember(accessToken, userId, null, null, "new english name", new long[] { 2 }, null, "1", email: "*****@*****.**");

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功);
        }
Exemplo n.º 30
0
        //[TestMethod]
        public void GetDepartmentMemberInfoTest()
        {
            var accessToken = AccessTokenContainer.GetToken(_corpId, base._corpSecret);
            var result      = MailListApi.GetDepartmentMemberInfo(accessToken, 2, 0, 0);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功);
        }