public WorkJsonResult WX_CreateUser(JH_Auth_User Model) { try { WorkJsonResult Ret = new WorkJsonResult(); if (Qyinfo.IsUseWX == "Y") { long[] Branch = { new JH_Auth_BranchB().GetEntity(d => d.DeptCode == Model.BranchCode).WXBMCode.Value }; MemberCreateRequest User = new MemberCreateRequest(); User.userid = Model.UserName; User.name = Model.UserRealName; User.mobile = Model.mobphone; User.department = Branch; User.gender = Model.Sex == "男" ? "1" : "2"; User.enable = Model.IsUse == "Y" ? 1 : 0; Ret = MailListApi.CreateMember(GetToken(), User); } return(Ret); } catch (Exception ex) { WorkJsonResult Ret = new WorkJsonResult(); new QJY.API.JH_Auth_LogB().Insert(new QJY.Data.JH_Auth_Log() { CRDate = DateTime.Now, LogContent = Model.UserName + "新增错误:" + ex.ToString() }); return(Ret); } }
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")), 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.请求成功); }
/// <summary> /// 添加用户 /// </summary> /// <param name="CreateUserid">操作者ID</param> /// <param name="errMsg">返回错误信息</param> /// <param name="wxDepartmentID"></param> /// <returns></returns> public bool AddMember(string CreateUserid, ref string errMsg, string wxDepartmentID = null) { try { QYConfig.RegistWX(); var accessToken = AccessTokenContainer.GetToken(QYConfig.CorpId); var result = MailListApi.CreateMember(accessToken, UserId, Name, new int[] { int.Parse(wxDepartmentID ?? DepartMent.DepartmentID) }, Position, Mobile, null, Email, Weixinid, 0); if (result.errcode.ToString() == "请求成功") { var gresult = MailListApi.GetMember(accessToken, UserId); Avatar = gresult.avatar; if (MembertDA.AddMember(UserId, Name, Position, Mobile, Email, Weixinid, Avatar, Status, CreateBy, DepartmentPKId.ToString())) { return(true); } else { errMsg = result.errcode + ":" + result.errmsg; return(false); } } else { return(false); } } catch (Exception e) { Logger.Log4Net.Error("add Member error:" + e); errMsg = "操作失敗:" + e.Message; return(false); } }
public QyCallResult CreateMember(string accessToken, Member member) { return (MailListApi.CreateMember(accessToken, member.Userid, member.Name, member.Department.ToArray(), member.Position, member.Mobile, member.Email, member.WeixinId).ToQyCallResult()); }
public WorkJsonResult CreateMember(CreateMemberDto dto) { //dto.AccessToken = GetAccessToken(QyConfig.CorpID, QyConfig.CorpSecret); MemberCreateRequest req = EmitMapperHelper.ObjectMapper <CreateMemberDto, MemberCreateRequest>(dto); var result = MailListApi.CreateMember(dto.AccessToken, req); return(result); }
public static bool AddWxUser(ref string erromsg, string userId, string name, int[] department = null, string position = null, string mobile = null, string email = null, string weixinId = null) { try { var result = MailListApi.CreateMember(GetToken(), userId, name, department, position, mobile, email, weixinId); erromsg = result.errmsg; } catch (ErrorJsonResultException ex) { erromsg = WxReturnCodeMessage.GetReturnMessage((int)ex.JsonResult.errcode); return(false); } return(true); }
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 result = MailListApi.CreateMember(accessToken, userId, string.Format("单元测试生成-{0}", DateTime.Now.ToString("yyMMdd-HH:mm")), "13900000000", "english name", new long[] { 2 }, null, "1", null, null, null, extattr: extattr); Assert.IsNotNull(result); Assert.IsTrue(result.errcode == ReturnCode_Work.请求成功); }
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 result = MailListApi.CreateMember(accessToken, userId, "ceshi", new[] { 2 }, null, "18913536683", null, null, null, extattr); Assert.IsNotNull(result); Assert.IsTrue(result.errcode == ReturnCode_QY.请求成功); }
/// <summary> /// 创建人员 /// </summary> /// <param name="_userId">成员UserID。对应管理端的帐号,企业内必须唯一。长度为1~64个字节</param> /// <param name="_name">成员名称。长度为1~64个字节</param> /// <param name="_departmnet">成员所属部门id列表 [1, 2],</param> /// <param name="_position">职位信息。长度为0~64个字节</param> /// <param name="_mobile">手机号码。企业内必须唯一,mobile/weixinid/email三者不能同时为空</param> /// <param name="_gender">性别。1表示男性,2表示女性</param> /// <param name="_email">邮箱。长度为0~64个字节。企业内必须唯一</param> /// <param name="_weixinid">微信号。企业内必须唯一。(注意:是微信号,不是微信的名字)</param> /// <param name="_avatar_mediaid">成员头像的mediaid,通过多媒体接口上传图片获得的mediaid</param> /// <param name="_extattr">扩展属性。扩展属性需要在WEB管理端创建后才生效,否则忽略未知属性的赋值</param> /// <returns></returns> public static bool CreateMember(string _userId, string _name, int[] _departmnet, string _position, string _mobile, string _gender, string _email, string _weixinid, string _avatar_mediaid, Extattr _extattr) { AccessTokenResult access_token_result = new AccessTokenResult(); QYConfigInfo config = GetQYConfig(); access_token_result = CommonApi.GetToken(config.QYCorpId, config.QYSecret); //调用接口 var result = MailListApi.CreateMember(access_token_result.access_token, _userId, _name, _departmnet, _position, _mobile, _email, _weixinid, _avatar_mediaid, _extattr); if (result.errmsg == "created") { return(true); } else { return(false); } }
public bool AddUser(WorkUser user) { if (env.IsDevelopment()) { return(true); } var entity = new MemberCreateRequest { userid = user.UserID, name = user.Name, mobile = user.Mobile, department = new long[] { Convert.ToInt64(user.DepartmentIds) }, gender = user.Gender.ToString(), enable = 1, }; var reObj = MailListApi.CreateMember(workSetting.Value.ContactsAccessTokenKey, entity); return(reObj.errcode == ReturnCode_Work.请求成功); }
/// <summary> /// 创建成员 /// </summary> /// <param name="QyID">企业ID</param> /// <param name="userId">员工UserID。必须企业内唯一</param> /// <param name="name">成员名称。长度为1~64个字符</param> /// <param name="department">成员所属部门id列表。注意,每个部门的直属员工上限为1000个</param> /// <param name="position">职位信息。长度为0~64个字符</param> /// <param name="mobile">手机号码。必须企业内唯一</param> /// <param name="tel">办公电话。长度为0~64个字符</param> /// <param name="email">邮箱。长度为0~64个字符。必须企业内唯一</param> /// <param name="weixinId">微信号。必须企业内唯一</param> /// <returns></returns> public QyJsonResult CreateUser(string QyID, string userId, string name, int[] department = null, string position = null, string mobile = null, string email = null, string weixinId = null, string tel = null, int gender = 0, string avatarMediaid = null, Extattr extattr = null) { QyJsonResult result = null; try { result = MailListApi.CreateMember(GetAccessToken(QyID), userId, name, department, position, mobile, email, weixinId, tel, gender, avatarMediaid, extattr); } catch (Exception ex) { LogWriter.Error(ex, string.Format("创建QyID为{0}的成员失败", QyID)); result = MailListApi.CreateMember(GetAccessToken(QyID, true), userId, name, department, position, mobile, email, weixinId, tel, gender, avatarMediaid, extattr); } if (result.errcode != ReturnCode_QY.请求成功) { LogWriter.Info(string.Format("创建QyID为{0}的成员失败,原因:{1}", QyID, result.errmsg)); } return(result); }
public QyJsonResult WX_CreateUser(JH_Auth_User Model) { try { QyJsonResult Ret = new QyJsonResult(); if (Qyinfo.IsUseWX == "Y") { int[] Branch = { new JH_Auth_BranchB().GetEntity(d => d.DeptCode == Model.BranchCode).WXBMCode.Value }; Ret = MailListApi.CreateMember(GetToken(), Model.UserName, Model.UserRealName, Branch, Model.zhiwu, Model.mobphone, Model.mailbox, Model.weixinnum); } return(Ret); } catch (Exception ex) { QyJsonResult Ret = new QyJsonResult(); new QJY.API.JH_Auth_LogB().Insert(new QJY.Data.JH_Auth_Log() { CRDate = DateTime.Now, LogContent = Model.UserName + "新增错误:" + ex.ToString() }); return(Ret); } }
public ActionResult UploadUser() { try { //同步部门 GetDepartmentListResult result = MailListApi.GetDepartmentList(WeixinWorkService.GetToken()); var departments = dbContext.SysDepartment.OrderByDescending(c => c.DepartmentName).ToList(); foreach (var item in departments) { if (item.DepartmentId == Guid.Parse("2379788E-45F0-417B-A103-0B6440A9D55D")) { continue; } var parentId = Convert.ToInt64(departments.Where(c => c.DepartmentId == item.ParentId).FirstOrDefault().WeixinWorkId); DepartmentList qyDep = result.department.Where(c => c.id == item.WeixinWorkId).FirstOrDefault(); if (qyDep == null) { var createResult = MailListApi.CreateDepartment(WeixinWorkService.GetToken(), item.DepartmentName, parentId == 0 ? 1 : parentId, 1000 - (item.OrderNo.HasValue ? item.OrderNo.Value : 0)); item.WeixinWorkId = createResult.id; } else { MailListApi.UpdateDepartment(WeixinWorkService.GetToken(), qyDep.id, item.DepartmentName, parentId == 0 ? 1 : parentId, 1000 - (item.OrderNo.HasValue ? item.OrderNo.Value : 0)); } dbContext.SaveChanges(); } //同步用户 var users = dbContext.SysUser.Where(c => c.UserCode != "admin").ToList(); foreach (var userItem in users) { long[] longArr = new long[1]; longArr[0] = Convert.ToInt64(dbContext.SysDepartment.Where(c => c.DepartmentId == userItem.DepartmentId).FirstOrDefault().WeixinWorkId); try { var memberResult = MailListApi.GetMember(WeixinWorkService.GetToken(), userItem.UserCode); if (memberResult.errcode == Senparc.Weixin.ReturnCode_Work.UserID不存在) { MemberCreateRequest request = new MemberCreateRequest(); request.email = userItem.Email; request.department = longArr; request.enable = 1; request.mobile = userItem.Mobile; request.name = userItem.UserName; request.userid = userItem.UserCode; MailListApi.CreateMember(WeixinWorkService.GetToken(), request); } else { MemberUpdateRequest updateRequest = new MemberUpdateRequest(); updateRequest.department = longArr; updateRequest.email = userItem.Email; updateRequest.enable = 1; updateRequest.mobile = userItem.Mobile; updateRequest.name = userItem.UserName; updateRequest.userid = userItem.UserCode; MailListApi.UpdateMember(WeixinWorkService.GetToken(), updateRequest); } } catch { } } return(Json(new { Code = 0, Msg = "同步成功!" })); } catch (Exception ex) { LogHelper.SaveLog(ex); return(Json(new { Code = 1, Msg = "服务器异常,请联系管理员!" })); } }
public JsonResult PostUser(GetMemberResult objModal, string Id) { //验证错误 if (!BeforeAddOrUpdate(objModal, Id) || !ModelState.IsValid) { return(Json(GetErrorJson(), JsonRequestBehavior.AllowGet)); } int[] strs = Request["departmentAll"].Split(',').Select(a => int.Parse(a)).ToArray(); objModal.department = strs; objModal.userid = objModal.userid.Trim(); objModal.name = objModal.name.Trim(); objModal.position = objModal.position != null?objModal.position.Trim() : ""; objModal.weixinid = objModal.weixinid != null?objModal.weixinid.Trim() : ""; objModal.mobile = objModal.mobile != null?objModal.mobile.Trim() : ""; objModal.email = objModal.email.Trim(); objModal.entryDate = objModal.entryDate; LocalSADEntity employee = new LocalSADEntity(); employee.ChineseName = objModal.name; employee.LillyID = objModal.userid; employee.ACTL_HIRE_DT = Convert.ToDateTime(objModal.entryDate); employee.Tag = CommonService.GetSysConfig("TagNameNewEmployee", "[]"); employee.Gender = Convert.ToString(objModal.gender); employee.Email = objModal.email; string[] userList = new string[1]; userList[0] = objModal.userid; //var taglist = MailListApi.GetTagList(GetToken()).taglist.Where(x => x.tagname == employee.Tag); var taglist = WeChatCommonService.lstTag.Where(x => x.tagname == employee.Tag); int tagid = taglist.FirstOrDefault() != null?Convert.ToInt32(taglist.FirstOrDefault().tagid) : 0; try { if (!string.IsNullOrEmpty(Id) && Id != "0") { MailListApi.UpdateMember(GetToken(), objModal); employee.Id = !_localservice.Repository.Entities.Where(a => a.LillyID == objModal.userid).AsNoTracking().IsEmpty() ? _localservice.Repository.Entities.Where(a => a.LillyID == objModal.userid).AsNoTracking().First().Id : 0; if (employee.Id == 0) { _localservice.Repository.Insert(employee); } else { List <string> columns = new List <string>(); columns.Add("ChineseName"); columns.Add("Gender"); columns.Add("Email"); columns.Add("ACTL_HIRE_DT"); _localservice.Repository.Update(employee, columns); } } else { objModal.to_invite = false; MailListApi.CreateMember(GetToken(), objModal); _localservice.Repository.Insert(employee); } } catch (ErrorJsonResultException ex) { if (ex.JsonResult.errcode == (ReturnCode)60102) { return(ErrorNotification(null, "用户已存在")); } } //不超过6个月时,添加标签 if (tagid != 0 && DateTime.Today <= (employee.ACTL_HIRE_DT.AddMonths(6))) { MailListApi.AddTagMember(GetToken(), tagid, userList); } //超过7个月时,移除标签 if (tagid != 0 && DateTime.Today > (employee.ACTL_HIRE_DT.AddMonths(7))) { MailListApi.DelTagMember(GetToken(), tagid, userList); } //添加或更新后会清除掉缓存 if (WeChatCommonService.lstUser != null) { cacheManager.Remove("UserItem"); } return(Json(doJson(null), JsonRequestBehavior.AllowGet)); }