private void SendWeChatMessage(int id, string type) { string reply = string.Empty; string msg = string.Empty; var BaseUrl = CommonService.GetSysConfig("WeChatUrl", ""); var appId = CommonService.GetSysConfig(HseAppIdKey, ""); var managerLillyId = CommonService.GetSysConfig("HSELillyID", ""); if (type == "SafetyTrouble") { msg = "您好,微信中有员工已提交安全隐患事件,请尽快查看。谢谢!点击"; reply = string.Format(msg + "<a href=\"{0}/HSE/HseAccident/SafetyTroubleDetail?appid={1}&id={2}\">这里</a>打开报告", BaseUrl, appId, id); } else { msg = "您好,微信中有员工已提交安全汇报事件,请尽快查看。谢谢!点击"; reply = string.Format(msg + "<a href=\"{0}/HSE/HseAccident/SafetyIncidentDetail?appid={1}&id={2}\">这里</a>打开报告", BaseUrl, appId, id); } WechatCommon.SendMsg(int.Parse(appId), "text", managerLillyId, "", "", reply, null); _Logger.Error <string>(string.Format("SendWeChatMessage_safetyReport:{0}", reply)); }
public static List <object> CreateNewsResponseMessage(AutoReplyContentView content, int appId, bool isCorp, bool isSafe, bool isAutoReply = false) { // var photoTextMsg = this.CreateResponseMessage<ResponseMessageNews>(); var Articles = new List <object>(); if (content.IsNewContent.Value) { var info = JsonConvert.DeserializeObject <List <NewsInfoView> >(content.Content); var configs = Infrastructure.Web.Domain.Service.CommonService.lstSysConfig; // var config = configs.Where(a => a.ConfigName.Equals("Content Server", StringComparison.CurrentCultureIgnoreCase)).First(); //var contentConfig = configs.Where(a => a.ConfigName.Equals("Content Server", StringComparison.CurrentCultureIgnoreCase)).First(); string host = Infrastructure.Web.Domain.Service.CommonService.GetSysConfig("Content Server", "").TrimEnd('/');// config.ConfigValue; //if (host.EndsWith("/")) //{ // host = host.Substring(0, host.Length - 1); //} int ii = 0; foreach (var entity in info) { if (ii == 0) //位置不同,缩略图的比例不一样 { entity.ImageSrc = WechatCommon.doGetFileCover(entity.ImageSrc, "_B"); } else { entity.ImageSrc = WechatCommon.doGetFileCover(entity.ImageSrc, "_T"); } ii++; var picUrl = host + entity.ImageSrc; //var url = host + "/News/ArticleInfo/wxdetail/" + content.AutoReplyId + "?wechatid=" + appId;// "&subId=" + item.Id; var url = string.Format("{0}/{1}/Message/GetNews?id={2}&wechatid={2}&type={3}&subId={4}", host, isCorp ? "news" : "mpnews", content.AutoReplyId, appId, (int)NewsTypeEnum.AutoReply, entity.Id); //host + "/News/Message/GetNews?id=" + content.AutoReplyId + "&wechatid=" + appId + "&type=" + (int)NewsTypeEnum.AutoReply; var newArticle = new Article() { Title = entity.NewsTitle, Url = url, PicUrl = picUrl, Description = entity.NewsComment }; Articles.Add(newArticle); } } else { List <ArticleInfoView> articleList = new List <ArticleInfoView>(); if (content.SecondaryType == (int)AutoReplyNewsEnum.MANUAL) { List <int> articleIds = content.NewsID.Trim(',').Split(',').ToList().Select(n => int.Parse(n)).ToList(); if (articleIds.Count > 0) { log.Debug("article count :{0}.", articleIds.Count); var lst = ((DbSet <ArticleInfo>)_articleInfoService.Repository.Entities).AsNoTracking() .Where(t => t.AppId == appId && articleIds.Contains(t.Id) && t.IsDeleted == false).ToList() .Select(a => (ArticleInfoView) new ArticleInfoView().ConvertAPIModelListWithContent(a)).ToList(); //解决顺序问题 foreach (var aID in articleIds) { var al = lst.Find(a => a.Id == aID); if (al != null) { articleList.Add(al); } } } } else if (content.SecondaryType == (int)AutoReplyNewsEnum.LATEST) { articleList.AddRange(((DbSet <ArticleInfo>)_articleInfoService.Repository.Entities).AsNoTracking() .Where(t => t.AppId == appId && t.IsDeleted == false) .OrderBy("Id", System.ComponentModel.ListSortDirection.Descending) .Take(int.Parse(content.Content)).ToList() .Select(a => (ArticleInfoView) new ArticleInfoView().ConvertAPIModelListWithContent(a)).ToList()); } ; // articleList = articleList.Distinct().OrderByDescending(t => t.PublishDate).ToList(); var token = WeChatCommonService.GetWeiXinToken(appId); int ii = 0; foreach (var a in articleList) { log.Debug("Start ID:{0} ImageCoverUrl:{1} ", a.Id, a.ImageCoverUrl); if (ii == 0) //位置不同,缩略图的比例不一样 { a.ImageCoverUrl = WechatCommon.doGetFileCover(a.ImageCoverUrl, "_B"); } else { a.ImageCoverUrl = WechatCommon.doGetFileCover(a.ImageCoverUrl, "_T"); } ii++; if (isSafe) { var newArticle = new MpNewsArticle() { title = a.ArticleTitle, content_source_url = string.Format("{0}/{3}/ArticleInfo/wxdetail/{1}?wechatid={2}&isAutoReply={4}", _newsHost, a.Id, appId, isCorp ? "news" : "mpnews", isAutoReply ? 1 : 0),// _newsHost + "/News/ArticleInfo/wxdetail/" + a.Id + "?wechatid=" + appId, //content = _newsHost + a.ImageCoverUrl, digest = a.ArticleComment, content = a.ArticleContent,// WechatCommonMP.ImageConvert(a.ArticleContent, appId), author = a.CreatedUserID, show_cover_pic = "0", thumb_media_id = WechatCommon.GetMediaId(a.ImageCoverUrl, token) }; log.Debug("Creating MPNews - \r\n\tTitle: " + newArticle.title + "\r\n\tUrl: " + newArticle.content_source_url + "\r\n\tPush Image: " + newArticle.thumb_media_id); Articles.Add(newArticle); } else { var newArticle = new Article() { Title = a.ArticleTitle, Url = string.Format("{0}/{3}/ArticleInfo/wxdetail/{1}?wechatid={2}&isAutoReply={4}", _newsHost, a.Id, appId, isCorp ? "news" : "mpnews", isAutoReply ? 1 : 0),// _newsHost + "/News/ArticleInfo/wxdetail/" + a.Id + "?wechatid=" + appId, PicUrl = _newsHost + a.ImageCoverUrl.Replace("\\", "/").TrimStart('/'), Description = a.ArticleComment }; log.Debug("Creating News - \r\n\tTitle: " + newArticle.Title + "\r\n\tUrl: " + newArticle.Url + "\r\n\tPush Image: " + newArticle.PicUrl); Articles.Add(newArticle); } } } return(Articles); }
public void ProcessRequest(HttpContext context) { //获取access_token string access_Token = WechatCommon.IsExistAccess_Token(); if (!string.IsNullOrEmpty(access_Token) && access_Token != "error") { #region 除原菜单 string url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token={0}", access_Token); //HTTP get 请求 WebRequestPostOrGet(url, ""); #endregion #region 创建菜单 url = string.Format("https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}", access_Token); List <Menu> menus = new List <Menu>(); List <WechatMenuInfo> topMenuList = WechatMenuBLL.ReadRootList(); //subbuttons.Clear(); foreach (var topmenu in topMenuList) { List <SubButton> subbuttons = new List <SubButton>(); foreach (var submenu in WechatMenuBLL.ReadChildList(topmenu.Id)) { //if (submenu.Type == "click") //{ // subbuttons.Add(new SubButton { name = submenu.Name, type = submenu.Type, key = submenu.Key }); //} //else //{ subbuttons.Add(new SubButton { name = submenu.Name, type = submenu.Type, url = submenu.Url, key = submenu.Key }); //} } //if (subbuttons.Count > 0) //{//如果有二级菜单 // menus.Add(new Menu { name = topmenu.Name, sub_button = subbuttons.ToArray<Button>() }); //} //else //{ menus.Add(new Menu { name = topmenu.Name, type = topmenu.Type, key = topmenu.Key, url = topmenu.Url, sub_button = subbuttons.ToArray <Button>() }); //} } #region // menus.Add( // new Menu() // { // name = "微商城", // sub_button = new SubButton[] // { // new SubButton() // { // name = "首页", // url = "http://dzwz18.ncms5.hnjing.net/mobile", // type = "view" // }, // new SubButton() // { // name = "分类", // url = "http://dzwz18.ncms5.hnjing.net/Mobile/ProductClass.html", // type = "view" // } // } // }); // menus.Add( // new Menu() // { // name = "个人中心", // sub_button = new SubButton[] // { // new SubButton() // { // name = "登录", // url = "http://dzwz18.ncms5.hnjing.net/Mobile/User/login.html", // type = "view" // }, // new SubButton() // { // name = "注册", // url = "http://dzwz18.ncms5.hnjing.net/Mobile/User/Register.html", // type = "view" // }, // new SubButton() // { // name = "我的竞网", // url = "http://dzwz18.ncms5.hnjing.net/Mobile/User/index.html", // type = "view" // } // } // }); // menus.Add( //new Menu() //{ // name = "用户服务", // sub_button = new SubButton[] // { // new SubButton() // { // name = "购物车", // url = "http://dzwz18.ncms5.hnjing.net/Mobile/cart.html", // type = "view" // }, // new SubButton() // { // name = "找回密码", // url = "http://dzwz18.ncms5.hnjing.net/Mobile/User/FindPasswordInit.html", // type = "view" // }, // new SubButton() // { // name = "男装搜索", // key="男装", // type = "click" // } // } //}); #endregion WeixinMenu weixinMenu = new WeixinMenu() { button = menus }; //参数 string param = JsonConvert.SerializeObject(weixinMenu); byte[] bs = Encoding.UTF8.GetBytes(param); //参数转化为ascii码 HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); //创建request req.Method = "POST"; //确定传值的方式,此处为post方式传值 req.ContentType = "application/x-www-form-urlencoded;charset=utf-8"; req.ContentLength = bs.Length; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(bs, 0, bs.Length); } string responseString = string.Empty; using (HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse()) { StreamReader sr = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); responseString = sr.ReadToEnd(); } ReturnMsg msg = JsonConvert.DeserializeObject <ReturnMsg>(responseString); if (msg.errcode != "0") { //context.Response.Write("系统忙,请稍后重试"); context.Response.Write("error|" + msg.errcode + ":" + msg.errmsg); context.Response.End(); } else { context.Response.Write("ok|自定义菜单成功"); context.Response.End(); } #endregion } }
/// <summary> /// 页面加载 /// </summary> protected override void PageLoad() { base.PageLoad(); int articleID = RequestHelper.GetQueryString <int>("ID"); article = ArticleBLL.Read(articleID); ArticleInfo tmp = article; tmp.ViewCount = tmp.ViewCount + 1; ArticleBLL.Update(tmp); #region 微信分享 Hashtable ht = new Hashtable(); WechatCommon wxs = new WechatCommon(); ht = wxs.getSignPackage(); timestamp = ht["timestamp"].ToString(); nonce = ht["nonceStr"].ToString(); signature = ht["signature"].ToString(); url = ht["url"].ToString(); WeChatImg = "http://" + HttpContext.Current.Request.Url.Host + article.Photo; title = article.Title; desc = (article.Summary == string.Empty) ? StringHelper.Substring(StringHelper.KillHTML(article.Content), 200) : article.Summary; #endregion thisClass = ArticleClassBLL.Read(ArticleClassBLL.GetLastClassID(article.ClassId)); int topClassID = ArticleClassBLL.GetTopClassID(article.ClassId); topNav = topClassID; topClass = ArticleClassBLL.Read(topClassID); string theArticleClassID = article.ClassId; int lastClassID = int.MinValue; if (theArticleClassID != string.Empty) { theArticleClassID = theArticleClassID.Substring(1); lastClassID = Convert.ToInt32(theArticleClassID.Substring(0, theArticleClassID.IndexOf('|'))); } navList = ArticleClassBLL.ReadArticleClassFullFatherID(ArticleClassBLL.GetLastClassID(article.ClassId)); ArticleSearchInfo articleSearch = new ArticleSearchInfo(); List <ArticleInfo> nextPreList = new List <ArticleInfo>(); if (ArticleBLL.SearchListRowNumber(" ID =" + article.Id + "").Count > 0) { ArticleInfo thisArtInfo = ArticleBLL.SearchListRowNumber(" ID =" + article.Id + "")[0]; nextPreList = ArticleBLL.SearchListRowNumber(" [ClassID] Like'%" + article.ClassId + "%' and [RowNumber]>" + thisArtInfo.RowNumber + " Order by RowNumber asc"); if (nextPreList.Count > 0) { NextNewsM = "<a href=\"/mobile/Newsdetail.html?id=" + nextPreList[0].Id + "\" title=\"" + nextPreList[0].Title + "\" class=\"nextLink\">" + "下一篇:" + StringHelper.Substring(nextPreList[0].Title, 13) + "</a>"; } nextPreList = ArticleBLL.SearchListRowNumber(" ClassID Like'%" + article.ClassId + "%' and RowNumber<" + thisArtInfo.RowNumber + " Order by RowNumber desc"); if (nextPreList.Count > 0) { PreNewsM = "<a href=\"/mobile/Newsdetail.html?id=" + nextPreList[0].Id + "\" title=\"" + nextPreList[0].Title + "\" class=\"prevLink\">" + "上一篇:" + StringHelper.Substring(nextPreList[0].Title, 13) + "</a>"; } } //SEO Title = article.Title; Keywords = (article.Keywords == string.Empty) ? article.Title : article.Keywords; Description = (article.Summary == string.Empty) ? StringHelper.Substring(StringHelper.KillHTML(article.Content), 200) : article.Summary; }
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)); }