private void GenerateTagInfoDictionary(GetAppInfoResult appInfo) { foreach (var allowTag in appInfo.allow_tags.tagid) { tagMemberdDictionary.Add(allowTag, WeChatCommonService.GetTagMembers(allowTag, int.Parse(appInfo.agentid))); } }
private bool CheckTag(GetAppInfoResult appInfo, int AccountMangageID, IList <int> selectedTagIds, IEnumerable <string> allAssignedUsers, CheckResult checkResult) { if (!selectedTagIds.Any()) { return(true); } var needTags = selectedTagIds.Select(selectedTagId => new TagEntity { TagId = selectedTagId, TagMember = WeChatCommonService.GetTagMembers(selectedTagId, int.Parse(appInfo.agentid)) }).ToList(); //needTags.Select(x => new { TagId = x.Key, TagMember = x.Value }).ToList(); var needUsers = needTags.SelectMany(x => x.TagMember.userlist.Select(y => y.userid)).ToList(); var needParties = WeChatCommonService.GetSubDepartments(needTags.SelectMany(x => x.TagMember.partylist).ToList(), AccountMangageID).ToList(); needUsers.AddRange(WeChatCommonService.lstUser(AccountMangageID).Where(x => needParties.Any(y => x.department.Any(z => z == y.id))).Select(x => x.userid).ToList()); var errorUsers = needUsers.Where(x => allAssignedUsers.Any(y => x == y)).ToList(); var errorTags = needTags.Where(x => errorUsers.Any(y => x.TagMember.userlist.Any(z => z.userid == y))).Select(x => x.TagId).ToList(); if (!errorTags.Any()) { return(true); } checkResult.ErrorTags = GetErrorTags(errorTags, AccountMangageID); return(false); }
public ConfigedInfo(GetAppInfoResult appInfo) { Dictionary = new Dictionary <int, GetTagMemberResult>(); AppInfoResult = appInfo; AssignedDepartmentIds = (appInfo.allow_partys == null || appInfo.allow_partys.partyid == null || !appInfo.allow_partys.partyid.Any()) ? new List <int>() : appInfo.allow_partys.partyid.ToList(); AssignedUserIds = (appInfo.allow_userinfos == null || appInfo.allow_userinfos.user == null || !appInfo.allow_userinfos.user.Any()) ? new List <string>() : appInfo.allow_userinfos.user.Select(x => x.userid).ToList(); //append depart and user of tag var tagIds = (appInfo.allow_tags == null || appInfo.allow_tags.tagid == null || !appInfo.allow_tags.tagid.Any()) ? new List <int>() : appInfo.allow_tags.tagid.ToList(); foreach (var tagId in tagIds) { var memberResult = WeChatCommonService.GetTagMembers(tagId, int.Parse(appInfo.agentid)); AssignedDepartmentIds.AddRange(memberResult.partylist); AssignedUserIds.AddRange(memberResult.userlist.Select(x => x.userid).ToList()); Dictionary.Add(tagId, memberResult); } var subDepartments = WeChatCommonService.GetSubDepartments(AssignedDepartmentIds.Distinct().ToList()).ToList(); AssignedUserIds.AddRange(WeChatCommonService.lstUser.Where(x => x.department.Any(y => subDepartments.Any(d => d.id == y))).Select(x => x.userid).ToList()); AssignedUserIds = AssignedUserIds.Distinct().ToList(); }
private bool CheckDepartment(GetAppInfoResult appInfo, IList <int> selectedDepartmentIds, CheckResult checkResult, int AccountMangageID) { //直接分配给应用 var assignedDepartmentIds = appInfo.allow_partys.partyid.ToList(); var underTagDepartmentIDs = tagMemberdDictionary.Select(x => x.Value).SelectMany(x => x.partylist).ToList(); assignedDepartmentIds.AddRange(underTagDepartmentIDs); //TODO:调整 if (!assignedDepartmentIds.Any()) { if (!selectedDepartmentIds.Any()) { return(true); } checkResult.ErrorDepartments = GetErrorDepartments(selectedDepartmentIds, AccountMangageID); return(false); } var departments = WeChatCommonService.GetSubDepartments(assignedDepartmentIds.Distinct().ToList(), AccountMangageID).ToList(); #region hiddlen //var allowUsers = WeChatCommonService.lstUser.Where(x => x.department.Any(y => departments.Any(z => z.id == y))).ToList(); //var needUsers = WeChatCommonService.lstUser.Where(x => x.department.Any(y => selectedDepartmentIds.Any(s => s == y))).ToList(); //var errorUsers = needUsers.Where(x => allowUsers.All(u => x.userid != u.userid)).ToList(); //if (!errorUsers.Any()) //{ // return true; //} //var errorDepartments = WeChatCommonService.lstDepartment.Where(x => errorUsers.SelectMany(y => y.department).Any(z => z == x.id)).ToList(); //var errorDepartmentIds = selectedDepartmentIds.Where(x => WeChatCommonService.GetSubDepartments(x).Any(y => errorDepartments.Any(z => z.id == y.id))).ToList(); //if (!errorDepartmentIds.Any()) return true; #endregion var errorDepartmentIds = selectedDepartmentIds.Where(x => departments.All(y => x != y.id)).ToList(); if (!errorDepartmentIds.Any()) { return(true); } checkResult.ErrorDepartments = GetErrorDepartments(errorDepartmentIds, AccountMangageID); return(false); }
///// <summary> ///// 获取所有App信息 ///// </summary> ///// <param name="appid"></param> ///// <returns></returns> public List <GetAppInfoResult> GetListInfo(int iPage, int iCount, ref int iTotal) { List <GetAppInfoResult> lst = new List <GetAppInfoResult>(); string aPPList = Request["APPList"]; var strToken = rtntoken(); //获取所有app //var applist = AppApi.GetAppList(strToken); var corpId = CommonService.GetSysConfig("WeixinCorpId", string.Empty); var applist = CommonService.lstSysWeChatConfig.Where(a => a.WeixinCorpId == corpId).ToList(); GetAppInfoResult result = new GetAppInfoResult(); //获取所有app信息 if (string.IsNullOrEmpty(aPPList)) { foreach (var rst in applist) { try { result = AppApi.GetAppInfo(strToken, int.Parse(rst.WeixinAppId)); } catch { continue; } lst.Add(result); } } else { try { result = AppApi.GetAppInfo(strToken, int.Parse(aPPList)); lst.Add(result); } catch { } } if (lst.Count != 0) { iTotal = lst.Count(); return(lst.OrderBy(a => int.Parse(a.agentid)).Skip((iPage - 1) * iCount).Take(iCount).ToList()); } return(null); }
/// <summary> /// 发送微信消息 /// </summary> /// <param name="strMsgType">text,image,news</param> /// <param name="strContent"></param> /// <param name="lstContent"></param> /// <returns></returns> public static MassResult SendMsg(int iAppID, string strMsgType, string strContent, List <ArticleInfoView> lstContent) { //MassResult objResult = null; string strDept = "", strUser = "", strTags = ""; // int IsSec = 0; GetAppInfoResult Ret = GetUserOrDept(iAppID); Ret.allow_userinfos.user.Where(a => a.status == "1").ToList().ForEach(a => { strUser += "|" + a.userid; }); if (strUser.Length > 0) { strUser = strUser.Substring(1); } strDept = string.Join(",", Ret.allow_partys.partyid); strTags = string.Join(",", Ret.allow_tags.tagid); return(SendMsg(iAppID, strMsgType, strUser, strDept, strTags, strContent, lstContent)); }
/// <summary> /// 获取应用详情 /// </summary> /// <param name="QyID">企业ID</param> /// <param name="agentId">企业应用的id,可在应用的设置页面查看</param> /// <returns></returns> public GetAppInfoResult GetAppInfo(string QyID, int agentId) { GetAppInfoResult result = null; try { result = AppApi.GetAppInfo(GetAccessToken(QyID), agentId); } catch (Exception ex) { LogWriter.Error(ex, string.Format("获取QyID为{0}的应用详情失败", QyID)); result = AppApi.GetAppInfo(GetAccessToken(QyID, true), agentId); } if (result.errcode != ReturnCode_QY.请求成功) { LogWriter.Info(string.Format("获取QyID为{0}的应用详情失败,原因:{1}", QyID, result.errmsg)); } return(result); }
private bool CheckVisualRange(int AccountMangageID, GetAppInfoResult appInfo, out IList <string> allAssignedUsers, Action func = null) { allAssignedUsers = null; var isConfig = appInfo.allow_partys.partyid.Any() || appInfo.allow_tags.tagid.Any() || appInfo.allow_userinfos.user.Any(); if (!isConfig) { return(false); } if (func != null) { func(); } //TODO:获取直接配置的用户信息 var assignedUsers = appInfo.allow_userinfos.user.Select(x => x.userid).ToList(); var departments = appInfo.allow_partys.partyid.ToList(); foreach (var tagInfo in tagMemberdDictionary.Values) { //user under tag assignedUsers.AddRange(tagInfo.userlist.Select(x => x.userid).ToList()); departments.AddRange(tagInfo.partylist); } var subDepartments = WeChatCommonService.GetSubDepartments(departments.Distinct().ToList(), AccountMangageID).ToList(); //TODO:获取部门下的人 assignedUsers.AddRange(WeChatCommonService.lstUser(AccountMangageID).Where(x => x.department.Any(y => subDepartments.Any(d => d.id == y))).Select(x => x.userid).ToList()); allAssignedUsers = assignedUsers.Distinct().ToList(); return(true); }
public override ActionResult Edit(string id) { string strToken = rtntoken(int.Parse(id)); GetAppInfoResult result = AppApi.GetAppInfo(strToken, int.Parse(id)); ViewBag.result = result; //部门信息 //List<DepartmentList> subdepartList = MailListApi.GetDepartmentList(GetToken(), 0).department; List <DepartmentList> subdepartList = new List <DepartmentList>(); if (WeChatCommonService.lstDepartment != null) { subdepartList = WeChatCommonService.lstDepartment; } if (result.allow_partys != null) { String allowpart = string.Join(",", result.allow_partys.partyid); List <string> departname = new List <string>(); foreach (var part in allowpart.Split(',')) { foreach (var allow in subdepartList) { if (allow.id.ToString() == part) { departname.Add(allow.name); break; } } } ViewBag.depatlist = departname; } else { ViewBag.depatlist = new List <string>(); } //标签信息 //var tagList = MailListApi.GetTagList(strToken).taglist; //ViewBag.taglist = tagList; List <TagItem> tagList = new List <TagItem>(); if (WeChatCommonService.lstTag != null) { tagList = WeChatCommonService.lstTag; } if (result.allow_tags != null) { String allowtag = string.Join(",", result.allow_tags.tagid); List <string> tagname = new List <string>(); foreach (var tag in allowtag.Split(',')) { foreach (var tag_list in tagList) { if (tag_list.tagid == tag) { tagname.Add(tag_list.tagname); break; } } } ViewBag.tagname = tagname; } else { ViewBag.tagname = new List <string>(); } //用户信息 List <GetMemberResult> user_List = new List <GetMemberResult>(); if (WeChatCommonService.lstUser != null) { user_List = WeChatCommonService.lstUser; } List <GetAppInfo_AllowUserInfos_User> userList = result.allow_userinfos.user; Dictionary <string, string> username = new Dictionary <string, string>(); foreach (var user in userList) { foreach (var user1 in user_List) { if (user1.userid == user.userid) { username.Add(user1.name, user1.avatar); break; } } } ViewBag.userlist = username; //获取corpid与secret var Config = WeChatCommonService.GetWeChatConfig(int.Parse(id)); if (Config != null) { ViewBag.corpid = Config.WeixinCorpId; ViewBag.secret = Config.WeixinCorpSecret; ViewBag.welcomemessage = Config.WelcomeMessage; ViewBag.configid = Config.Id; } return(View("../appmanage/Edit", result)); }
/// <summary> /// 设置企业号应用 /// </summary> /// <param name="data"></param> //[AllowAnonymous] //[HttpPost] public ActionResult SetAppInfo(SetAppPostData data, string Id) { //更新SysWechatConfig数据库 //验证错误 if (!BeforeAddOrUpdate(data, Id) || !ModelState.IsValid) { return(Json(GetErrorJson(), JsonRequestBehavior.AllowGet)); } #region 更新菜单 var loginUser = (SysUser)Session["UserInfo"]; var objModel = sys.Repository.GetByKey(int.Parse(Request["ConfigID"])); var menuModel = _sysMenuService.GetMenusByUserID(loginUser, null).Where(a => a.AppId == int.Parse(Request["ConfigID"]) && a.NavigateUrl.Equals("/")).FirstOrDefault(); if (menuModel != null) { menuModel.MenuName = data.name; menuModel.MenuTitle = data.name; _sysMenuService.Repository.Update(menuModel); } #endregion var Config = WeChatCommonService.GetWeChatConfigByID(int.Parse(Request["ConfigID"])); #region 步到微信 //var strToken = Rtntoken(int.Parse(data.agentid)); var strToken = WeChatCommonService.GetWeiXinToken(Config.Id); if (!string.IsNullOrEmpty(Request["MediaID"])) { data.logo_mediaid = Request["MediaID"]; } if (string.IsNullOrEmpty(data.redirect_domain)) { data.redirect_domain = string.Empty; } AppApi.SetApp(strToken, data); #endregion #region 存DB var objNewModel = new SysWechatConfig(); #region 从微信获取App logo, 存入objNewModel try { GetAppInfoResult result = AppApi.GetAppInfo(strToken, int.Parse(Config.WeixinAppId)); objNewModel.CoverUrl = result.square_logo_url; } catch (Exception ex) { _Logger.Error("an error occurd when get app logo :{0}", ex); } #endregion var lst = new List <string>(); objNewModel.Id = objModel.Id; objNewModel.AppName = data.name; if (Request["CorpID"] != objModel.WeixinCorpId && !string.IsNullOrEmpty(Request["Secret"])) { objNewModel.WeixinCorpId = Request["CorpID"]; } if (Request["Secret"] != objModel.WeixinCorpSecret && Request["Secret"] != "******" && !string.IsNullOrEmpty(Request["Secret"])) { objNewModel.WeixinCorpSecret = Request["Secret"]; } if (Request["Welcome"] != objModel.WelcomeMessage) { objNewModel.WelcomeMessage = Request["Welcome"]; } if (Request["Token"] != objModel.WeixinToken && Request["Token"] != "******" && !string.IsNullOrEmpty(Request["Token"])) { objNewModel.WeixinToken = Request["Token"]; } if (Request["EncodingAESKey"] != objModel.WeixinEncodingAESKey && Request["EncodingAESKey"] != "******" && !string.IsNullOrEmpty(Request["EncodingAESKey"])) { objNewModel.WeixinEncodingAESKey = Request["EncodingAESKey"]; } sys.Repository.Update(objNewModel); #endregion #region 清理缓存 //清理缓存 if (WeChatCommonService.lstDepartment(AccountManageID) != null) { cacheManager.Remove("DepartmentList"); } if (WeChatCommonService.lstTag(AccountManageID) != null) { cacheManager.Remove("TagItem"); } if (WeChatCommonService.lstUser(AccountManageID) != null) { cacheManager.Remove("UserItem" + AccountManageID); } if (WeChatCommonService.lstSysWeChatConfig != null) { cacheManager.Remove("SysWeChatConfig"); } var newMenus = _sysMenuService.GetMenusByUserID(loginUser, null); loginUser.Menus = newMenus; Session["UserInfo"] = loginUser; #endregion return(Json(doJson(null))); }