public JsonResult delTagmember(string userId, string tagId, string mType) { string accessToken = GetToken(); string[] userlist = null; int[] partylist = null; using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = IsolationLevel.RepeatableRead })) { if (mType.Equals("Person", StringComparison.CurrentCultureIgnoreCase)) { userlist = new string[] { userId }; _addressBookService.delMemberTag(userId, Int32.Parse(tagId)); } else { partylist = new int[] { Int32.Parse(userId) }; } var ret = MailListApi.DelTagMember(accessToken, Int32.Parse(tagId), userlist, partylist); if (ret.errcode == Weixin.ReturnCode_QY.请求成功) { transactionScope.Complete(); } } WeChatCommonService.ClearDepartmentTagMapCache(this.AccountManageID); WeChatCommonService.ClearTagCache(int.Parse(tagId)); return(Json(doJson(null), JsonRequestBehavior.AllowGet)); }
//[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.请求成功); }
public JsonResult delTagmember(string userId, string tagId) { string accessToken = GetToken(); List <string> userlist = new List <string>(); userlist.Add(userId); MailListApi.DelTagMember(accessToken, Int32.Parse(tagId), userlist.ToArray()); return(Json(doJson(null), JsonRequestBehavior.AllowGet)); }
public QyJsonResult WX_DelTagMember(int strBQCode, string[] userList) { QyJsonResult Ret = new QyJsonResult(); if (Qyinfo.IsUseWX == "Y") { Ret = MailListApi.DelTagMember(GetToken(), strBQCode, userList); } return(Ret); }
public int UpdateEmployee(LocalSADEntity entity) { var updateEmployee = Repository.Entities.Where(t => t.LilyId.ToUpper() == entity.LillyID.ToUpper()).FirstOrDefault(); if (updateEmployee == null) { return(0); } updateEmployee.EmployeeTime = entity.ACTL_HIRE_DT; updateEmployee.BaseLocation = entity.BS_LCTN_GLBL; updateEmployee.Tag = CommonService.GetSysConfig("TagNameNewEmployee", ""); //过滤条件暂时删除 //if (updateEmployee.EmployeeTime < DateTime.Now.AddMonths(-6).Date) //{ // return 0; //} if (!string.IsNullOrEmpty(updateEmployee.Tag)) { var taglist = WeChatCommonService.lstTag.Where(x => x.tagname == updateEmployee.Tag); int tagid = taglist.FirstOrDefault() != null?Convert.ToInt32(taglist.FirstOrDefault().tagid) : 0; string[] userlist = new string[1]; userlist[0] = entity.LillyID; //不超过6个月时,添加标签 if (tagid != 0 && DateTime.Today <= (updateEmployee.EmployeeTime.AddMonths(6))) { var tagMemberResult = MailListApi.GetTagMember(WeChatCommonService.GetWeiXinToken(0), tagid); var hasTag = tagMemberResult.userlist.Select(a => a.userid.ToUpper() == entity.LillyID.ToUpper()).FirstOrDefault(); if (!hasTag) { MailListApi.AddTagMember(WeChatCommonService.GetWeiXinToken(0), tagid, userlist); } } //超过7个月时,移除标签 if (tagid != 0 && DateTime.Today > (updateEmployee.EmployeeTime.AddMonths(7))) { MailListApi.DelTagMember(WeChatCommonService.GetWeiXinToken(0), tagid, userlist); } } return(Repository.Update(updateEmployee)); }
public JsonResult DelTagDepartment(string tagId, string departmentId) { if (string.IsNullOrEmpty(departmentId)) { return(ErrorNotification("请选择要删除的标签成员!")); } string accessToken = GetToken(); var result = MailListApi.DelTagMember(accessToken, Int32.Parse(tagId), null, new[] { int.Parse(departmentId) }); //if (result.errcode == ReturnCode_QY.请求成功) //{ // WeChatCommonService.lstTag.Clear(); //} return(result.errcode != ReturnCode_QY.请求成功 ? ErrorNotification(result.errmsg) : Json(doJson(null), JsonRequestBehavior.AllowGet)); }
public JsonResult AddDepartmentToTag(IList <int> departments, string tagId) { if (string.IsNullOrEmpty(tagId)) { return(ErrorNotification("数据异常!")); } departments = departments ?? new List <int>(); var accessToken = GetToken(); var partList = MailListApi.GetTagMember(accessToken, int.Parse(tagId)).partylist; var deletedList = partList.Where(x => departments.All(y => y != x)).ToArray(); var addedList = departments.Where(x => !partList.Any(y => y == x)).ToArray(); if (addedList.Any()) { var addResult = MailListApi.AddTagMember(accessToken, Int32.Parse(tagId), null, addedList); if (addResult.errcode != ReturnCode_QY.请求成功) { return(ErrorNotification(addResult.errcode.ToString())); } } if (deletedList.Any()) { var delResult = MailListApi.DelTagMember(accessToken, Int32.Parse(tagId), null, deletedList); if (delResult.errcode != ReturnCode_QY.请求成功) { return(ErrorNotification(delResult.errcode.ToString())); } } //if (addedList.Any() || deletedList.Any()) //{ // WeChatCommonService.lstTag.Clear(); //} return(Json(doJson(null), JsonRequestBehavior.AllowGet)); }
public JsonResult delTag(string Id) { try { string accessToken = GetToken(); var memberResult = MailListApi.GetTagMember(accessToken, Int32.Parse(Id)); string[] userList = null; if (memberResult.userlist != null && memberResult.userlist.Count > 0) { userList = memberResult.userlist.Select(a => a.userid).ToArray(); } if ((userList != null && userList.Count() > 0) || (memberResult.partylist != null && memberResult.partylist.Count() > 0)) { MailListApi.DelTagMember(accessToken, Int32.Parse(Id), userList, memberResult.partylist); foreach (var userId in userList) { _addressBookService.delMemberTag(userId, Int32.Parse(Id)); } } MailListApi.DeleteTag(accessToken, Int32.Parse(Id)); } catch (ErrorJsonResultException ex) { if ((int)ex.JsonResult.errcode == 60018) { var e = new Exception("请在微信企业号管理平台中,取消各应用对此标签的可见范围,再进行删除操作。"); throw e; } } finally { WeChatCommonService.ClearDepartmentTagMapCache(this.AccountManageID); } return(Json(doJson(null), JsonRequestBehavior.AllowGet)); }
private string ImportToTag() { Dictionary <string, Stream> dic = new Dictionary <string, Stream>(); Dictionary <string, TagImport> dics = new Dictionary <string, TagImport>(); //获取accesstoken string accessToken = GetToken(); string invalidList = string.Empty; for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase objFile = Request.Files[i]; var f = new byte[objFile.InputStream.Length]; //将csv文件一次性读出来 objFile.InputStream.Read(f, 0, (int)objFile.InputStream.Length); //定义数据格式UTF-8 string str = System.Text.Encoding.GetEncoding("UTF-8").GetString(f); //获取第一行数据然后取两列数据WeChatUserID,TagID string[] sArray = str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); string[] rowOne = sArray[0].Split(','); int TagidIndex = 0, WeChatUserIDIndex = 0; //循环判断返回数组对应列下标 for (int s = 0; s < rowOne.Length; s++) { if (string.Equals(rowOne[s], "TagID", StringComparison.OrdinalIgnoreCase)) { TagidIndex = s; } else if (string.Equals(rowOne[s], "WeChatUserID", StringComparison.OrdinalIgnoreCase)) { WeChatUserIDIndex = s; } } //循环其他行去把对应下标的数据封装成TagImport对象 for (int x = 1; x < sArray.Length; x++) { string[] rowX = sArray[x].Split(','); string tagid = rowX[TagidIndex]; string WeChatUserID = rowX[WeChatUserIDIndex]; TagImport tagimport = null; //确认dics是否有tagid 有add,没有就新建对象 if (dics.ContainsKey(tagid)) { tagimport = dics[tagid]; tagimport.userlist.Add(WeChatUserID); } else { tagimport = new TagImport(); tagimport.tagid = tagid; tagimport.userlist = new List <string>(); tagimport.userlist.Add(WeChatUserID); tagimport.partylist = new List <int>(); dics.Add(tagid, tagimport); } } //返回invalidlist AddTagMemberResult addResult = new AddTagMemberResult(); //先根据tagid去取当前tagid的userlist再删除掉成员 foreach (var b in dics.Keys) { var lstTagUser = MailListApi.GetTagMember(accessToken, int.Parse(b)).userlist; if (lstTagUser == null || lstTagUser.Count <= 0) { break; } List <string> userList = new List <string>(); lstTagUser.ForEach(a => { userList.Add(a.userid); }); MailListApi.DelTagMember(accessToken, int.Parse(b), userList.ToArray(), null); } //封装完后循环dics,序列化后调用API的接口Post过去 foreach (var a in dics) { var strs = string.Join(",", a.Value.userlist.ToArray()); List <string> lst = new List <string>(); GetStr(strs, lst); foreach (var b in lst) { addResult = MailListApi.AddTagMember( accessToken, int.Parse(a.Key), b.Split(',') ); if (!string.IsNullOrEmpty(addResult.invalidlist)) { invalidList = invalidList + '|' + addResult.invalidlist; } } } dic.Add(objFile.FileName, objFile.InputStream); } return(invalidList); }
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)); }
public JsonResult SendNewEmployee() { var AppId = CommonService.GetSysConfig("NewEmployeeAppId", ""); var articleSettingList = _localSADService.SendArticleToNewEmployee(); try { foreach (var em in articleSettingList) { if (em.employeeLst.Count > 0) { string[] ids = em.ArticleId.Split(','); List <Article> articlelist = new List <Article>(); foreach (var item in ids) { Message message = _messageService.Repository.Entities.Where(a => a.Id.ToString() == item).SingleOrDefault(); if (message != null) { var article = new Article() { Title = message.Title, Description = message.Comment, PicUrl = string.Format("{0}/Common/PushFile?id={1}&FileName={2}", WechatBaseUrl, message.ThumbImageId, message.ThumbImageUrl), Url = string.Format("{0}/News/Message/WxDetailh5/{1}", WechatBaseUrl, item) }; articlelist.Add(article); } } WechatCommon.PublishMessage(int.Parse(AppId), articlelist, em.UserLst, "", ""); BaseService <LogsModel> objServLogs = new BaseService <LogsModel>(); string tmpCategory = em.Month + "&" + em.Days; string tmpCateDis = ""; switch (tmpCategory) { case "&7": tmpCateDis = "7 days"; break; case "&15": tmpCateDis = "15 days"; break; case "5&": tmpCateDis = "5 months"; break; case "6&": tmpCateDis = "6 months"; break; default: break; } string[] arrID = em.UserLst.Split('|'); foreach (string strID in arrID) { if (strID != "") { objServLogs.Repository.Insert(new LogsModel() { LogCate = tmpCateDis, LogContent = "发送成功", CreatedUserID = strID, CreatedUserName = strID }); } } } } var deleteuserList = _localSADService.GetDeleteNewEmployee(); string newname = CommonService.GetSysConfig("TagNameNewEmployee", ""); var Config = WeChatCommonService.GetWeChatConfig(int.Parse(AppId)); var token = AccessTokenContainer.TryGetToken(Config.WeixinCorpId, Config.WeixinCorpSecret); //var taglist = MailListApi.GetTagList(token).taglist.Where(x => x.tagname == tagName); var taglist = WeChatCommonService.lstTag.Where(x => x.tagname == newname); int tagid = taglist.FirstOrDefault() != null?Convert.ToInt32(taglist.FirstOrDefault().tagid) : 0; string[] userLst = deleteuserList.Split('|'); List <string> userlist = new List <string>(); foreach (string user in userLst) { userlist.Add(user); } MailListApi.DelTagMember(token, tagid, userlist.ToArray()); } catch (Exception ex) { _logger.Error("Publish Message Error: {0}", ex.Message.ToString()); return(Json(false, JsonRequestBehavior.AllowGet)); } return(Json(true, JsonRequestBehavior.AllowGet)); }
private string ImportToTag() { var dic = new Dictionary <string, Stream>(); var dics = new Dictionary <string, TagImport>(); //获取accesstoken string accessToken = GetToken(); string invalidList = string.Empty; for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase objFile = Request.Files[i]; if (objFile != null) { var f = new byte[objFile.InputStream.Length]; //将csv文件一次性读出来 objFile.InputStream.Read(f, 0, (int)objFile.InputStream.Length); //定义数据格式UTF-8 string str = System.Text.Encoding.GetEncoding("UTF-8").GetString(f); //获取第一行数据然后取两列数据lillyID,TagID string[] sArray = str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); string[] rowOne = sArray[0].Split(','); int tagidIndex = 0, lillyIdIndex = 0; //循环判断返回数组对应列下标 for (int s = 0; s < rowOne.Length; s++) { if (string.Equals(rowOne[s], "TagID", StringComparison.OrdinalIgnoreCase)) { tagidIndex = s; } else if (string.Equals(rowOne[s], "LillyID", StringComparison.OrdinalIgnoreCase)) { lillyIdIndex = s; } } //循环其他行去把对应下标的数据封装成TagImport对象 for (int x = 1; x < sArray.Length; x++) { string[] rowX = sArray[x].Split(','); string tagid = rowX[tagidIndex]; string lillyid = rowX[lillyIdIndex] == null ? rowX[lillyIdIndex] : rowX[lillyIdIndex].Trim(); TagImport tagimport = null; //确认dics是否有tagid 有add,没有就新建对象 if (dics.ContainsKey(tagid)) { tagimport = dics[tagid]; tagimport.userlist.Add(lillyid); } else { tagimport = new TagImport { tagid = tagid, userlist = new List <string> { lillyid }, partylist = new List <int>() }; dics.Add(tagid, tagimport); } } } //返回invalidlist var addResult = new AddTagMemberResult(); //先根据tagid去取当前tagid的userlist再删除掉成员 foreach (var b in dics.Keys) { var lstTagUser = MailListApi.GetTagMember(accessToken, int.Parse(b)).userlist; if (lstTagUser == null || lstTagUser.Count <= 0) { break; } var userList = new List <string>(); lstTagUser.ForEach(a => userList.Add(a.userid)); MailListApi.DelTagMember(accessToken, int.Parse(b), userList.ToArray()); } //封装完后循环dics,序列化后调用API的接口Post过去 foreach (var a in dics) { var strs = string.Join(",", a.Value.userlist.ToArray()); var lst = new List <string>(); GetStr(strs, lst); foreach (var b in lst) { try { addResult = MailListApi.AddTagMember( accessToken, int.Parse(a.Key), b.Split(',') ); } catch (ErrorJsonResultException e) { //WeChatCommonService.lstUser. var invalidUsers = b.Split(',').Distinct().Where(x => WeChatCommonService.lstUser.All(y => y.userid != x)).ToList(); invalidUsers.Add(invalidList); invalidList = string.Join("|", invalidUsers); } if (!string.IsNullOrEmpty(addResult.invalidlist)) { invalidList = invalidList + '|' + addResult.invalidlist; } } } if (objFile != null) { dic.Add(objFile.FileName, objFile.InputStream); } } if (invalidList.StartsWith("|")) { invalidList.Remove(0, 1); } if (invalidList.EndsWith("|")) { invalidList.Remove(invalidList.Length - 1, 1); } return(invalidList); }