private ReturnValue SendSystemNoticeToPersonals(SystemNotice systemNotice, string personals) { BLLJIMP.BLLUser bllUser = new BLLUser(""); BLLJIMP.BLLWeixin bllWeixin = new BLLWeixin(""); BLLWeixin.TMTaskNotification notificaiton = new BLLWeixin.TMTaskNotification(); notificaiton.Url = string.Format("http://{0}/WuBuHui/MyCenter/SystemMessageBox.aspx", System.Web.HttpContext.Current.Request.Url.Host); var accessToken = bllWeixin.GetAccessToken(); string[] userArray = personals.Split(','); int successCount = 0; foreach (string userId in userArray) { successCount += SendSystemNoticeToUserId(systemNotice, userId) ? 1 : 0; try { notificaiton.First = "您好,您有新系统消息"; notificaiton.Keyword1 = systemNotice.Title; notificaiton.Keyword2 = systemNotice.NoticeTypeString; notificaiton.Remark = "点击查看"; bllWeixin.SendTemplateMessage(accessToken, bllUser.GetUserInfo(userId).WXOpenId, notificaiton); } catch (Exception) { continue; } } return(new ReturnValue { Code = 0, Msg = string.Format("成功将消息发送到{0}个人.", successCount) }); }
private ReturnValue SendSystemNoticeToAll(SystemNotice systemNotice, string websiteOwner) { BLLJIMP.BLLWeixin bllWeixin = new BLLWeixin(""); BLLWeixin.TMTaskNotification notificaiton = new BLLWeixin.TMTaskNotification(); notificaiton.Url = string.Format("http://{0}/WuBuHui/MyCenter/SystemMessageBox.aspx", System.Web.HttpContext.Current.Request.Url.Host); var acctoken = bllWeixin.GetAccessToken(); List <UserInfo> userList = new List <UserInfo>(); if (WebsiteOwner.Equals("wubuhui")) { userList = this.GetList <UserInfo>(string.Format("WebsiteOwner='{0}' and Phone is not null and Phone <>''", websiteOwner)); } else { userList = this.GetList <UserInfo>(string.Format("WebsiteOwner='{0}'", websiteOwner)); } int successCount = 0; foreach (UserInfo uinfo in userList) { successCount += SendSystemNoticeToUserId(systemNotice, uinfo.UserID) ? 1 : 0; try { notificaiton.First = "您好,您有新系统消息"; notificaiton.Keyword1 = systemNotice.Title; notificaiton.Keyword2 = systemNotice.NoticeTypeString; notificaiton.Remark = "点击查看"; bllWeixin.SendTemplateMessage(acctoken, uinfo.WXOpenId, notificaiton); } catch (Exception) { continue; } } return(new ReturnValue { Code = 0, Msg = string.Format("成功将消息发送到{0}个人.", successCount) }); }
private ReturnValue SendSystemNoticeToGroups(SystemNotice systemNotice, string groups, string websiteOwner) { BLLJIMP.BLLWeixin bllWeixin = new BLLWeixin(""); BLLWeixin.TMTaskNotification notificaiton = new BLLWeixin.TMTaskNotification(); notificaiton.Url = string.Format("http://{0}/WuBuHui/MyCenter/SystemMessageBox.aspx", System.Web.HttpContext.Current.Request.Url.Host); var acctoken = bllWeixin.GetAccessToken(); string[] groupArray = groups.Split(','); string strWhere = string.Format("TagName like '%{0}%'", groupArray[0].Trim()); foreach (string group in groupArray) { strWhere += string.Format(" or TagName like '%{0}%'", group); } List <UserInfo> userList = this.GetList <UserInfo>(string.Format("WebsiteOwner='{0}' and ({1})", websiteOwner, strWhere)); int successCount = 0; foreach (UserInfo uinfo in userList) { successCount += SendSystemNoticeToUserId(systemNotice, uinfo.UserID) ? 1 : 0; try { notificaiton.First = "您好,您有新系统消息"; notificaiton.Keyword1 = systemNotice.Title; notificaiton.Keyword2 = systemNotice.NoticeTypeString; notificaiton.Remark = "点击查看"; bllWeixin.SendTemplateMessage(acctoken, uinfo.WXOpenId, notificaiton); } catch (Exception) { continue; } } return(new ReturnValue { Code = 0, Msg = string.Format("成功将消息发送到{0}个人.", successCount) }); }