/// <summary> /// 获取视频回复 /// </summary> /// <param name="content"></param> /// <returns></returns> public static Video CreateVideoResponseMessage(AutoReplyContentView content, string strCorpID) { if (content.IsNewContent.Value) { var video = JsonConvert.DeserializeObject <List <NewsInfoView> >(content.Content)[0]; return(new Video() { Title = video.NewsTitle, Description = video.NewsComment, MediaId = GetMediaIDByNewsInfo(video, content.Id), }); } else { if (content.FileID != null) { NewsInfoView news; Innocellence.WeChatMain.Common.WechatCommon.GetMediaIDByFileID(content.FileID, _attachmentsItemService, strCorpID, out news); return(new Video() { Title = news.NewsTitle, Description = news.NewsComment, MediaId = news.MediaId, }); } else { throw new Exception("do not found file id."); } } return(null); }
///// <summary> ///// 取得口令回复一览 ///// </summary> ///// <param name="autoReplyView"></param> ///// <returns></returns> //private List<AutoReplyContentView> GetAutoReplyList(AutoReplyView autoReplyView) //{ // // THIS IS NOT A GOOD WAY, SHOULD TRANSFER TO JSON OBJECT IN FRONT END // var list = new List<AutoReplyContentView>(); // var replyTypes = Request.Form.GetValues("replyType"); // var textReply = Request.Form.Get("saytext"); // var newsTitle = Request.Form.Get("msgPictitle"); // var newsComment = Request.Form.Get("msgtips"); // var newsBody = Request.Form.Get("msgbody"); // //var isTextEncrypts = Request.Form.GetValues("isTextEncryptReplace"); // var replyNewsTypes = Request.Form.GetValues("replyNewsType"); // var replyNewsLatestCounts = Request.Form.GetValues("replyNewsLatestCount"); // var replyNewsLists = Request.Form.GetValues("replyNewsList"); // var textReplyFiles = Request.Form.GetValues("textReplyFiles"); // //if (replyTypes != null) // //{ // // var count = replyTypes.Length; // // for (int i = 0; i < count; i++) // // { // var content = new AutoReplyContentView(); // content.AutoReplyId = autoReplyView.Id; // content.PrimaryType = 2;//int.Parse(replyTypes[i]); // NewsInfoView view = new NewsInfoView(); // switch (content.PrimaryType) // { // #region text // case (int)AutoReplyContentEnum.TEXT: // case (int)AutoReplyContentEnum.LINK: // { // content.Content = textReply; // //if (isTextEncrypts != null) // //{ // // content.IsEncrypt = isTextEncrypts[i] == "1"; // //} // break; // } // #endregion // #region news // case (int)AutoReplyContentEnum.PHOTO_TEXT: // { // view.NewsTitle = newsTitle; // view.NewsComment = newsComment; // view.NewsContent = newsBody; // // //ImageContent = news // content.NewsID = Guid.NewGuid().ToString(); // var configs = Infrastructure.Web.Domain.Service.CommonService.lstSysConfig; // var config = configs.Where(a => a.ConfigName.Equals("Content Server", StringComparison.CurrentCultureIgnoreCase)).First(); // string host = config.ConfigValue; // if (host.EndsWith("/")) // { // host = host.Substring(0, host.Length - 1); // } // //var picUrl = host + item.ImageContent; // var url = host + "WechatMain/AutoReply/GetNews?id=" + content.NewsID; // content.Content = JsonConvert.SerializeObject(view); // //if (replyNewsTypes != null) // //{ // // content.SecondaryType = int.Parse(replyNewsTypes[i]); // // if (content.SecondaryType == (int)AutoReplyNewsEnum.LATEST) // // { // // if (replyNewsLatestCounts != null) content.Content = replyNewsLatestCounts[i]; // // } // // else if (content.SecondaryType == (int)AutoReplyNewsEnum.MANUAL) // // { // // if (replyNewsLists != null) content.NewsID = replyNewsLists[i]; // // } // //} // break; // } // #endregion // case (int)AutoReplyContentEnum.VIDEO: // view.NewsTitle = newsTitle; // break; // case (int)AutoReplyContentEnum.FILE: // view.NewsTitle = newsTitle; // break; // case (int)AutoReplyContentEnum.IMAGE: // view.NewsTitle = newsTitle; // break; // case (int)AutoReplyContentEnum.AUDIO: // view.NewsTitle = newsTitle; // break; // default: // { // //if (textReplyFiles != null) content.FileID = int.Parse(textReplyFiles[i]); // break; // } // } // list.Add(content); // // } // //} // return list; //} #endregion private List <AutoReplyContentView> GetAutoReplyList(AutoReplyNewView model) { var list = new List <AutoReplyContentView>(); var content = new AutoReplyContentView(); content.AutoReplyId = model.Main.Id; var news = model.Send[0]; //保存多条内容。只有新闻存在多条情况 content.IsEncrypt = news.isSecurityPost; var cate = (AutoReplyContentEnum)Enum.Parse(typeof(AutoReplyContentEnum), news.NewsCate, true); //选择资源文件 if (news.materialId.HasValue && news.materialId.Value > 0) { var config = WeChatCommonService.GetWeChatConfigByID(model.Main.AppId); content.FileID = news.materialId; content.IsNewContent = false; //更新MediaID //out 之后news.isSecurityPost 被清空 Innocellence.WeChatMain.Common.WechatCommon.GetMediaIDByFileID(news.materialId, _attachmentsItemService, config.WeixinCorpId, out news); content.Content = JsonConvert.SerializeObject(new List <NewsInfoView> { news }); } else if (cate == AutoReplyContentEnum.NEWS) { //图文消息特殊处理 if (string.IsNullOrEmpty(news.NewsID)) //如果不是选择的素材 { var listArticle = GetArticleList(model.Send); content.NewsID = string.Join(",", listArticle.Select(a => a.Id).ToArray()); } else { content.NewsID = news.NewsID; } content.IsNewContent = false; //content.SecondaryType = model.Main.Contents[0].SecondaryType; content.SecondaryType = (int)AutoReplyNewsEnum.MANUAL; //此处缺少功能,临时写死。画面应该增加返回最近的几条新闻 } else { if (cate != AutoReplyContentEnum.TEXT && cate != AutoReplyContentEnum.LINK) //上传文件处理 { var mediaId = WechatCommon.GetMediaInfo(cate, news, model.Main.AppId); content.MediaId = mediaId; } content.IsNewContent = true; //content.Content = JsonConvert.SerializeObject(model.Send); //这个地方不应该存数组,todo content.Content = JsonConvert.SerializeObject(new List <NewsInfoView> { news }); } content.PrimaryType = (int)cate; list.Add(content); return(list); }
private IResponseMessageBase CreateLinkeResponseMessage(AutoReplyContentView content) { var testMsg = this.CreateResponseMessage <ResponseMessageText>(); testMsg.Content = CustomMessageCommon.CreateLinkResponseMessage(content); log.Debug("Create link response :{0}", content); return(testMsg); }
private IResponseMessageBase CreateImageResponseMessage(AutoReplyContentView content) { var imageMsg = this.CreateResponseMessage <ResponseMessageImage>(); //var image = JsonConvert.DeserializeObject<List<NewsInfoView>>(content.Content)[0]; //imageMsg.Image = new Image() { MediaId = image.MediaId }; imageMsg.Image = CustomMessageCommon.CreateImageResponseMessage(content, _postModel.CorpId); return(imageMsg); }
private IResponseMessageBase CreateTextResponseMessage(AutoReplyContentView content) { var testMsg = this.CreateResponseMessage <ResponseMessageText>(); //var info = JsonConvert.DeserializeObject<List<NewsInfoView>>(content.Content); //testMsg.Content = info[0].NewsContent; testMsg.Content = CustomMessageCommon.CreateTextResponseMessage(content); log.Debug("Create text response :{0}", content); return(testMsg); }
private void OtherOperationImpl(AutoReplyContentView content) { var chat = GetWechatConfig(); if (content.UserGroups != null && content.UserGroups.Count > 0) { var user = wechatMPUserService.GetUserByOpenId(WeixinOpenId); if (!string.IsNullOrEmpty(user.TagIdList)) { var untagResult = Innocellence.Weixin.MP.AdvancedAPIs.UserTagApi.BatchUntagging(chat.WeixinAppId, chat.WeixinCorpSecret, int.Parse(user.TagIdList), new List <string> { WeixinOpenId }); if (untagResult.errcode != ReturnCode.请求成功) { throw new Exception(untagResult.errmsg); } } var tagResult = Innocellence.Weixin.MP.AdvancedAPIs.UserTagApi.BatchTagging(chat.WeixinAppId, chat.WeixinCorpSecret, content.UserGroups[0], new List <string> { WeixinOpenId }); if (tagResult != null && tagResult.errcode == ReturnCode.请求成功) { bool result = wechatMPUserService.ChangeGroup(content.UserGroups[0], WeixinOpenId); } } if (content.UserTags != null && content.UserTags.Count > 0) { //systemUserTagMappingService.DeleteByOpenId(WeixinOpenId); var oldTags = systemUserTagMappingService.GetUserTagByOpenId(WeixinOpenId); var userTagMappings = content.UserTags.Select(a => new SystemUserTagMapping() { TagId = a, UserOpenid = WeixinOpenId }).ToList(); var newIds = userTagMappings.Select(a => a.TagId).ToList(); foreach (var old in oldTags) { if (newIds.Contains <int>(old.TagId)) { var item = userTagMappings.Where(a => a.TagId == old.TagId).First(); userTagMappings.Remove(item); } } systemUserTagMappingService.Create(userTagMappings); } //if (content.MessageTags != null && content.MessageTags.Count > 0) //{ //} if (string.IsNullOrEmpty(content.InterfaceLink)) { //to do } }
public static string CreateLinkResponseMessage(AutoReplyContentView content) { if (content.IsNewContent.Value) { var info = JsonConvert.DeserializeObject <List <NewsInfoView> >(content.Content); var url = info[0].NewsContent; var title = info[0].NewsTitle; return(string.Format("<a href=\"{0}\">{1}</a>", url, title)); } else { return(content.Content); } }
public static string CreateTextResponseMessage(AutoReplyContentView content) { // var testMsg = this.CreateResponseMessage<ResponseMessageText>(); if (content.IsNewContent.Value) { var info = JsonConvert.DeserializeObject <List <NewsInfoView> >(content.Content); return(info[0].NewsContent); } else { return(content.Content); } // LogManager.GetLogger(this.GetType()).Debug("Create text response :{0}", content); // return testMsg; }
private IResponseMessageBase CreateVideoResponseMessage(AutoReplyContentView content) { var videoMsg = this.CreateResponseMessage <ResponseMessageVideo>(); //var video = JsonConvert.DeserializeObject<List<NewsInfoView>>(content.Content)[0]; //videoMsg.Video = new Video() //{ // Title = video.NewsTitle, // Description = video.NewsComment, // MediaId = video.MediaId, //}; videoMsg.Video = CustomMessageCommon.CreateVideoResponseMessage(content, _postModel.CorpId); log.Debug("ResponseMessageVideo Type:{0}", videoMsg.MsgType.ToString()); return(videoMsg); }
/// <summary> /// 获取语音回复 /// </summary> /// <param name="content"></param> /// <returns></returns> public static Voice CreateVoiceResponseMessage(AutoReplyContentView content, string strCorpID) { // var voiceMsg = this.CreateResponseMessage<ResponseMessageVoice>(); if (content.IsNewContent.Value) { var voice = JsonConvert.DeserializeObject <List <NewsInfoView> >(content.Content)[0]; return(new Voice() { MediaId = GetMediaIDByNewsInfo(voice, content.Id) }); } else { NewsInfoView news; return(new Voice() { MediaId = Innocellence.WeChatMain.Common.WechatCommon.GetMediaIDByFileID(content.FileID, _attachmentsItemService, strCorpID, out news) }); } return(null); }
private IResponseMessageBase CreateNewsResponseMessage(AutoReplyContentView content, int appId) { var photoTextMsg = this.CreateResponseMessage <ResponseMessageNews>(); var list = CustomMessageCommon.CreateNewsResponseMessage(content, appId, false, false, true); photoTextMsg.Articles = list.Select(a => (Article)a).ToList(); //photoTextMsg.Articles = new List<Article>(); //var info = JsonConvert.DeserializeObject<List<NewsInfoView>>(content.Content)[0]; //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 = config.ConfigValue; //if (host.EndsWith("/")) //{ // host = host.Substring(0, host.Length - 1); //} //string contentHost = contentConfig.ConfigValue; //if (contentHost.EndsWith("/")) //{ // contentHost = contentHost.Substring(0, contentHost.Length - 1); //} //var picUrl = contentHost + info.ImageSrc; //var url = host + "/MPNews/ArticleInfo/GetNews?id=" + content.AutoReplyId +"&type="+(int)NewsTypeEnum.AutoReply + "&wechatid=" + appId;// "&subId=" + item.Id; //var newArticle = new Article() //{ // Title = info.NewsTitle, // Url = url, // PicUrl = picUrl, // Description = info.NewsComment //}; //photoTextMsg.Articles.Add(newArticle); return(photoTextMsg); }
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); }