public MessageController( IArticleInfoService objServiceArticle, IAttachmentsItemService attachmentsItemService, ISysWechatConfigService SysWechatConfigService, IWechatMPUserService WechatMPUserService, IMessageLogService messageLogService, IAddressBookService addressBookService, IWeChatUserRequestMessageLogHandler WeChatUserRequestMessageLogHandler) : base(objServiceArticle) { // _objService = objService; //_messageService = objService; _objServiceArticle = objServiceArticle; _attachmentsItemService = attachmentsItemService; _WechatMPUserService = WechatMPUserService; _SysWechatConfigService = SysWechatConfigService; _WeChatUserRequestMessageLogHandler = WeChatUserRequestMessageLogHandler; _MessageLogService = messageLogService; _addressBookService = addressBookService; // _previewMessageLogService = previewMessageLogService; // AppId = (int)CategoryType.Undefined; ViewBag.AppId = AppId; ViewBag.KeywordTypes = new Dictionary <string, string>() { { WechatMessageLogType.file.ToString(), "文件" }, { WechatMessageLogType.image.ToString(), "图片" }, { WechatMessageLogType.news.ToString(), "图文" }, { WechatMessageLogType.text.ToString(), "文本" }, { WechatMessageLogType.video.ToString(), "视频" }, { WechatMessageLogType.voice.ToString(), "语音" } }; }
public AutoReplyController(IAutoReplyService objService, IArticleInfoService articleInfoService, IAttachmentsItemService fileManageService, IAttachmentsItemService attachmentsItemService, IWechatUserRequestMessageTagService messageTagService, ISystemUserTagService systemUserTagService) : base(objService) { _autoReplyService = objService; _articleInfoService = articleInfoService; _fileManageService = fileManageService; _attachmentsItemService = attachmentsItemService; _messageTagService = messageTagService; _systemUserTagService = systemUserTagService; AppId = (int)CategoryType.Undefined; ViewBag.AppId = AppId; }
public static string DoNewsInfo(NewsInfoView news, SysWechatConfig config, AutoReplyContentEnum type, string strFileName) { string mediaId = null; if (news.materialId.HasValue && news.materialId.Value > 0) //有素材 { IAttachmentsItemService _attachmentsItemService = EngineContext.Current.Resolve <IAttachmentsItemService>(); NewsInfoView news1; mediaId = WechatCommon.GetMediaIDByFileID(news.materialId, _attachmentsItemService, config.WeixinCorpId, out news1); } else { mediaId = WechatCommon.GetMediaInfo(type, news, news.AppId); NewsToAttachments(news, type.ToString().ToLower(), strFileName); } return(mediaId); }
/// <summary> /// 消息内容存储到素材表 /// </summary> /// <param name="news"></param> /// <param name="uploadFileType"></param> /// <param name="strFileName"></param> private static void NewsToAttachments(NewsInfoView news, string uploadFileType, string strFileName) { IAttachmentsItemService _attachmentsItemService = EngineContext.Current.Resolve <IAttachmentsItemService>(); string strFullName = (HttpContext.Current == null ? HttpRuntime.AppDomainAppPath : HttpContext.Current.Request.PhysicalApplicationPath) + strFileName; AttachmentsItemPostProperty p = new AttachmentsItemPostProperty() { SaveFullName = Path.GetFileName(strFullName), ServerPath = HttpRuntime.AppDomainAppPath, FileName = news.NewsTitle, TargetFilePath = strFileName.Replace(Path.GetFileName(strFullName), "").Replace("//", "/").Trim('/'), UploadFileType = uploadFileType, AppId = news.AppId, Description = news.NewsComment, VideoCoverSrc = string.IsNullOrEmpty(news.ImageSrc) ? news.ImageContent : news.ImageSrc, UserName = _attachmentsItemService.Repository.LoginUserName,// User.Identity.Name, MediaId = news.MediaId, // MediaExpireTime= //ViewId = pid, }; SysAttachmentsItem itemView = _attachmentsItemService.ThumbImageAndInsertIntoDB(p); }
public FileManageController(IAttachmentsItemService attachmentsItemService) : base(attachmentsItemService) { _attachmentsItemService = attachmentsItemService; }
/// <summary> /// 根据资源ID获取回复信息,如果过期重新上传 /// </summary> /// <param name="fileID"></param> /// <param name="news"></param> /// <returns></returns> public static string GetMediaIDByFileID(int?fileID, IAttachmentsItemService _attachmentsItemService, string CorpId, out NewsInfoView news) { if (fileID == null) { throw new Exception("do not found file id."); } else { log.Debug("GetMediaIDByFileID start: fileID:{0}", fileID); // var fileInfo = _attachmentsItemService.GetById <AttachmentsItemView>((int)fileID); if (fileInfo != null) { news = new NewsInfoView() { NewsContent = "", NewsTitle = fileInfo.AttachmentTitle, ImageContent = fileInfo.AttachmentUrl, VideoContent = fileInfo.AttachmentUrl, FileSrc = fileInfo.AttachmentUrl, SoundSrc = fileInfo.AttachmentUrl, MediaId = fileInfo.MediaId, NewsComment = fileInfo.Description }; } else { news = new NewsInfoView(); } if (fileInfo != null && (string.IsNullOrEmpty(fileInfo.MediaId) || !fileInfo.MediaExpireTime.HasValue || fileInfo.MediaExpireTime.Value < DateTime.Now)) { var config = WeChatCommonService.lstSysWeChatConfig.Find(a => a.WeixinCorpId == CorpId); AutoReplyContentEnum cate = AutoReplyContentEnum.FILE; if (fileInfo.Type == (int)AttachmentsType.IMAGE) { cate = AutoReplyContentEnum.IMAGE; if (fileInfo.FileSize > 2 * 1024 * 1024) { throw new Exception("图片文件不能大于2M!"); } } else if (fileInfo.Type == (int)AttachmentsType.VIDEO) { cate = AutoReplyContentEnum.VIDEO; if (fileInfo.FileSize > 10 * 1024 * 1024) { throw new Exception("视频文件不能大于10M!"); } } else if (fileInfo.Type == (int)AttachmentsType.AUDIO) { cate = AutoReplyContentEnum.VOICE; if (fileInfo.FileSize > 2 * 1024 * 1024) { throw new Exception("声音文件不能大于210M!"); } } else if (fileInfo.Type == (int)AttachmentsType.FILE) { cate = AutoReplyContentEnum.FILE; if (fileInfo.FileSize > 20 * 1024 * 1024) { throw new Exception("普通文件不能大于20M!"); } } news.NewsCate = cate.ToString().ToLower(); news.AppId = config.Id; Innocellence.WeChatMain.Common.WechatCommon.GetMediaInfo(cate, news, config.Id); _attachmentsItemService.UpdateMediaId(fileInfo.Id, news.MediaId, DateTimeHelper.GetDateTimeFromXml(news.MediaCreateTime)); log.Debug("GetMediaIDByFileID end GetNewMediaId: fileID:{0} MediaId:{1}", fileID, news.MediaId); return(news.MediaId); } else { log.Debug("GetMediaIDByFileID end Use Old MediaId: fileID:{0} MediaId:{1}", fileID, news.MediaId); return(fileInfo == null ? string.Empty : fileInfo.MediaId); } } }