/// <summary>
        /// 保存
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <IActionResult> SaveAndUpdate(MpProductTypeDto input)
        {
            MpProductTypeDto result = null;

            if (Request.Form.Files.Count > 0)
            {
                var    profilePictureFile = Request.Form.Files.First();
                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }
                var    fileInfo = new FileInfo(profilePictureFile.FileName);
                var    extra    = fileInfo.Extension.Substring(fileInfo.Extension.IndexOf(".") + 1);
                string fileUrl  = await _fileServer.UploadFile(fileBytes, extra, MpMessageType.mpnews.ToString());

                input.FilePathOrUrl = fileUrl;
                var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
            }

            if (input.Id == 0)
            {
                result = await _mpProductTypeAppService.Create(input);
            }
            else
            {
                result = await _mpProductTypeAppService.Update(input);
            }
            return(Json(result));
        }
Esempio n. 2
0
        /// <summary>
        /// 上传并保存微信图片素材
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <IActionResult> SaveAndUpdate(MpSelfArticleDto input)
        {
            MpSelfArticleDto result = null;

            input.LastModificationTime = DateTime.Now;
            if (Request.Form.Files.Count > 0)
            {
                Logger.Info($"回复图文上传");
                var profilePictureFile = Request.Form.Files.First();

                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }
                var    fileInfo = new FileInfo(profilePictureFile.FileName);
                var    extra    = fileInfo.Extension.Substring(fileInfo.Extension.IndexOf(".") + 1);
                string fileUrl  = await _fileServer.UploadFile(fileBytes, extra, MpMessageType.image.ToString());

                Logger.Info($"回复图文url:{fileUrl}");
                input.FilePathOrUrl = fileUrl;
                var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
            }
            Logger.Info($"回复类:{JsonConvert.SerializeObject(input)}");
            if (input.Id == 0)
            {
                result = await _mpSelfArticleAppService.Create(input);
            }
            else
            {
                result = await _mpSelfArticleAppService.Update(input);
            }
            return(Json(result));
        }
        public async Task <JsonResult> SaveAndUpdate(CustomerMediaImageDto input)
        {
            CustomerMediaImageDto result = null;

            input.LastModificationTime = DateTime.Now;
            if (Request.Form.Files.Count > 0)
            {
                var profilePictureFile = Request.Form.Files.First();
                Logger.Info("开始上传文件");
                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }
                Logger.Info("文件大小:" + fileBytes.Length);
                var    fileInfo = new FileInfo(profilePictureFile.FileName);
                var    extra    = fileInfo.Extension.Substring(fileInfo.Extension.IndexOf(".") + 1);
                string fileUrl  = await _fileServer.UploadFile(fileBytes, extra, MpMessageType.image.ToString());

                input.FilePathOrUrl = fileUrl;
                var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
                input.MediaID = await _wxMediaUpload.UploadAndGetMediaID(input.MpID, fileUrl, MpMessageType.image);
            }

            if (input.Id == 0)
            {
                result = await _CustomerMediaImageAppService.Create(input);
            }
            else
            {
                result = await _CustomerMediaImageAppService.Update(input);
            }
            return(Json(result));
        }
Esempio n. 4
0
        /// <summary>
        /// 上传并保存微信素材
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <IActionResult> SaveAndUpdate(MpMediaVideoDto input)
        {
            MpMediaVideoDto result = null;

            input.LastModificationTime = DateTime.Now;
            if (Request.Form.Files.Count > 0)
            {
                var    profilePictureFile = Request.Form.Files.First();
                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }
                var    fileInfo = new FileInfo(profilePictureFile.FileName);
                var    extra    = fileInfo.Extension.Substring(fileInfo.Extension.IndexOf(".") + 1);
                string fileUrl  = await _fileServer.UploadFile(fileBytes, extra, MpMessageType.video.ToString());

                input.FilePathOrUrl = fileUrl;
                var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);

                input.MediaID = await _wxMediaUpload.UploadVideoAndGetMediaID(input.MpID, fileUrl, MpMessageType.video, input.Title, input.Description);
            }
            if (input.Id == 0)
            {
                result = await _mpMediaVideoAppService.Create(input);
            }
            else
            {
                result = await _mpMediaVideoAppService.Update(input);
            }
            return(Json(result));
        }
Esempio n. 5
0
        /// <summary>
        /// 上传并保存微信图片素材
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <IActionResult> SaveAndUpdate(MpShoppingMallPicDto input)
        {
            MpShoppingMallPicDto result = null;

            input.LastModificationTime = DateTime.Now;
            if (Request.Form.Files.Count > 0)
            {
                var profilePictureFile = Request.Form.Files.First();

                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }
                var    fileInfo = new FileInfo(profilePictureFile.FileName);
                var    extra    = fileInfo.Extension.Substring(fileInfo.Extension.IndexOf(".") + 1);
                string fileUrl  = await _fileServer.UploadFile(fileBytes, extra, "MpShoppingMallPic");

                input.LocalPicUrl = fileUrl;
                var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
            }
            if (input.Id == 0)
            {
                result = await _MpShoppingMallPicAppService.Create(input);
            }
            else
            {
                result = await _MpShoppingMallPicAppService.Update(input);
            }
            return(Json(result));
        }
Esempio n. 6
0
        public async Task <IActionResult> SaveAndUpdate(CustomerServiceOnlineDto input)
        {
            CustomerServiceOnlineDto result = null;

            input.LastModificationTime = DateTime.Now;
            input.KfAccount            = input.PreKfAccount + "@" + input.PublicNumberAccount;
            string fileUrl = string.Empty;

            if (Request.Form.Files.Count > 0)
            {
                var    profilePictureFile = Request.Form.Files.First();
                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }
                var fileInfo = new FileInfo(profilePictureFile.FileName);
                var extra    = fileInfo.Extension.Substring(fileInfo.Extension.IndexOf(".") + 1);
                fileUrl = await _fileServer.UploadFile(fileBytes, extra, "CustomerServiceOnline");

                input.LocalHeadingUrl = fileUrl;
                input.KfHeadingUrl    = fileUrl;
                var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
            }

            Logger.Info($"客服信息上传开始:客服账号:{input.KfAccount},客服昵称:{input.KfNick},密码:{input.KfPassWord},id={input.Id}");
            if (input.KfType == KFType.WX.ToString())
            {
                //上传客服信息
                if (input.Id == 0)
                {
                    await _wxMediaAppService.AddCustom(input.MpID, input.KfAccount, input.KfNick, input.KfPassWord, input.KfWx);
                }
                else
                {
                    await _wxMediaAppService.UpdateCustom(input.MpID, input.KfAccount, input.KfNick, input.KfPassWord);
                }

                if (Request.Form.Files.Count > 0)
                {
                    Logger.Info($"客服信息上传结束,开始上传客服头像,头像url:{fileUrl}");
                    //上传客服头像
                    await _wxMediaUpload.UploadKfHeading(input.MpID, fileUrl, input.KfAccount);
                }
            }
            else
            {
                input.KfType = KFType.YL.ToString();
            }

            if (input.Id == 0)
            {
                await _CustomerServiceOnlineAppService.Create(input);
            }
            else
            {
                await _CustomerServiceOnlineAppService.Update(input);
            }
            return(Json(""));
        }
        public async Task <IActionResult> SaveAndUpdate(CustomerArticleDto input)
        {
            CustomerArticleDto result = null;

            input.LastModificationTime = DateTime.Now;
            if (Request.Form.Files.Count > 0)
            {
                var profilePictureFile = Request.Form.Files.First();

                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }
                var    fileInfo = new FileInfo(profilePictureFile.FileName);
                var    extra    = fileInfo.Extension.Substring(fileInfo.Extension.IndexOf(".") + 1);
                string fileUrl  = await _fileServer.UploadFile(fileBytes, extra, MpMessageType.image.ToString());

                input.FilePathOrUrl = fileUrl;
                var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
            }
            if (string.IsNullOrWhiteSpace(input.MediaID))
            {
                input.MediaID = Guid.NewGuid().ToString();
            }
            if (input.Id == 0)
            {
                result = await _CustomerArticleAppService.Create(input);
            }
            else
            {
                result = await _CustomerArticleAppService.Update(input);
            }
            return(Json(result));
        }
        /// <summary>
        /// 获取并下载微信临时素材
        /// </summary>
        /// <param name="mpid"></param>
        /// <param name="mediaid"></param>
        /// <returns></returns>
        private async Task <string> GetMedia(int mpid, string mediaid, string msgtype, string format = null)
        {
            var extra = string.Empty;

            if (msgtype == "Image")
            {
                extra = "jpg";
            }
            if (msgtype == "Voice")
            {
                extra = format;
            }
            if (msgtype == "Video")
            {
                extra = "mp4";
            }
            var account = await _mpAccountAppService.GetCache(mpid);

            WebClient client = new WebClient();

            if (account != null)
            {
                try
                {
                    Logger.Error("进入素材下载");
                    Logger.Error($"临时素材发送地址URL:https://api.weixin.qq.com/cgi-bin/media/get?access_token={await _accessTokenContainer.TryGetAccessTokenAsync(account.AppId, account.AppSecret)}&media_id={mediaid}");

                    var mediaData = await client.DownloadDataTaskAsync($"https://api.weixin.qq.com/cgi-bin/media/get?access_token={await _accessTokenContainer.TryGetAccessTokenAsync(account.AppId, account.AppSecret)}&media_id={mediaid}");;
                    return(await _fileServer.UploadFile(mediaData, extra, AppConsts.FileType_WxMedia));

                    //return await _fileServer.Download($"https://api.weixin.qq.com/cgi-bin/media/get?access_token={await _accessTokenContainer.TryGetAccessTokenAsync(account.AppId, account.AppSecret)}&media_id={mediaid}", type: AppConsts.FileType_WxMedia);
                }
                catch (Exception ex)
                {
                    Logger.Error(string.Format("下载MpID为{0},media_id{1}的临时素材报错", mpid, mediaid), ex);
                    var mediaData = await client.DownloadDataTaskAsync($"https://api.weixin.qq.com/cgi-bin/media/get?access_token={await _accessTokenContainer.TryGetAccessTokenAsync(account.AppId, account.AppSecret)}&media_id={mediaid}");;
                    return(await _fileServer.UploadFile(mediaData, extra, AppConsts.FileType_WxMedia));

                    //return await _fileServer.Download($"https://api.weixin.qq.com/cgi-bin/media/get?access_token={await _accessTokenContainer.TryGetAccessTokenAsync(account.AppId, account.AppSecret, true)}&media_id={mediaid}", type: AppConsts.FileType_WxMedia);
                }
            }
            return(string.Empty);
        }
Esempio n. 9
0
        /// <summary>
        /// 上传并保存微信素材
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <IActionResult> SaveAndUpdate(MpMediaVoiceDto input)
        {
            MpMediaVoiceDto result = null;

            input.LastModificationTime = DateTime.Now;
            if (Request.Form.Files.Count > 0)
            {
                var    profilePictureFile = Request.Form.Files.First();
                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }
                var    fileInfo = new FileInfo(profilePictureFile.FileName);
                var    extra    = fileInfo.Extension.Substring(fileInfo.Extension.IndexOf(".") + 1);
                string fileUrl  = await _fileServer.UploadFile(fileBytes, extra, MpMessageType.voice.ToString());

                input.FilePathOrUrl = fileUrl;
                var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);

                input.MediaID = await _wxMediaUpload.UploadAndGetMediaID(input.MpID, fileUrl, MpMessageType.voice);

                if (string.IsNullOrWhiteSpace(input.MediaID))
                {
                    throw new UserFriendlyException("对不起,请检查您提交的音频文件的时长。");
                }
            }
            if (input.Id == 0)
            {
                result = await _mpMediaVoiceAppService.Create(input);
            }
            else
            {
                result = await _mpMediaVoiceAppService.Update(input);
            }
            return(Json(result));
        }
        /// <summary>
        /// 上传并保存微信素材
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <IActionResult> SaveAndUpdate(MpMediaArticleDto input)
        {
            MpMediaArticleDto result = null;

            input.LastModificationTime = DateTime.Now;
            if (Request.Form.Files.Count > 0)
            {
                var    profilePictureFile = Request.Form.Files.First();
                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }
                var    fileInfo = new FileInfo(profilePictureFile.FileName);
                var    extra    = fileInfo.Extension.Substring(fileInfo.Extension.IndexOf(".") + 1);
                string fileUrl  = await _fileServer.UploadFile(fileBytes, extra, MpMessageType.mpnews.ToString());

                input.FilePathOrUrl = fileUrl;
                Logger.Info($"封面图片URL:{fileUrl}");
                var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
                input.PicMediaID = await _wxMediaUpload.UploadAndGetMediaID(input.MpID, fileUrl, MpMessageType.image);

                Logger.Info($"封面图片MediaID:{input.PicMediaID}");
                await _mpMediaImageAppService.Create(new MpMediaImageDto
                {
                    FileID               = input.PicFileID,
                    FilePathOrUrl        = input.FilePathOrUrl,
                    MpID                 = input.MpID,
                    Name                 = input.Title + "封面图片",
                    MediaID              = input.PicMediaID,
                    LastModificationTime = DateTime.Now
                });
            }

            //更换微信图文中图片链接

            var domain = _webUrlService.GetServerRootAddress();

            domain          = domain.Substring(0, domain.Length - 1);
            input.WxContent = await _mpMediaArticleAppService.UpdateWxContentString(input.Content, input.ArticleGrid, domain);

            //获取图文mediaID
            if (string.IsNullOrEmpty(input.MediaID))
            {
                input.MediaID = await _wxMediaUpload.UploadArticleAndGetMediaID(input.MpID, new Senparc.Weixin.MP.AdvancedAPIs.GroupMessage.NewsModel
                {
                    author                = input.Author,
                    title                 = input.Title,
                    digest                = input.Description,
                    content               = input.WxContent,
                    content_source_url    = input.AUrl,
                    show_cover_pic        = input.ShowPic,
                    thumb_media_id        = input.PicMediaID,
                    need_open_comment     = input.EnableComment,
                    only_fans_can_comment = input.OnlyFansComment
                });
            }
            else
            {
                input.MediaID = await _wxMediaUpload.UploadArticleAndGetMediaID(input.MpID, new Senparc.Weixin.MP.AdvancedAPIs.GroupMessage.NewsModel
                {
                    author                = input.Author,
                    title                 = input.Title,
                    digest                = input.Description,
                    content               = input.WxContent,
                    content_source_url    = input.AUrl,
                    show_cover_pic        = input.ShowPic,
                    thumb_media_id        = input.PicMediaID,
                    need_open_comment     = input.EnableComment,
                    only_fans_can_comment = input.OnlyFansComment
                }, false, input.MediaID);
            }

            if (input.Id == 0)
            {
                result = await _mpMediaArticleAppService.Create(input);
            }
            else
            {
                result = await _mpMediaArticleAppService.Update(input);
            }
            return(Json(result));
        }
Esempio n. 11
0
        public async Task <JsonResult> SaveAndUpdate(CustomerServiceResponseTextDto input)
        {
            CustomerServiceResponseTextDto result = null;

            input.LastModificationTime = DateTime.Now;
            if (Request.Form.Files.Count > 0)
            {
                IFormFile profilePictureFile = null;
                string    fileUrl            = null;
                if (input.ReponseContentType == (int)CustomerServiceMsgType.image)
                {
                    profilePictureFile = Request.Form.Files.First(m => m.Name == "UploadPic");
                }
                else if (input.ReponseContentType == (int)CustomerServiceMsgType.video)
                {
                    profilePictureFile = Request.Form.Files.First(m => m.Name == "UploadVideo");
                }
                else if (input.ReponseContentType == (int)CustomerServiceMsgType.voice)
                {
                    profilePictureFile = Request.Form.Files.First(m => m.Name == "UploadVoice");
                }

                if (profilePictureFile != null)
                {
                    Logger.Info("开始上传文件");
                    byte[] fileBytes;
                    using (var stream = profilePictureFile.OpenReadStream())
                    {
                        fileBytes = stream.GetAllBytes();
                    }
                    Logger.Info("文件大小:" + fileBytes.Length);
                    var fileInfo = new FileInfo(profilePictureFile.FileName);
                    var extra    = fileInfo.Extension.Substring(fileInfo.Extension.IndexOf(".") + 1);
                    fileUrl = await _fileServer.UploadFile(fileBytes, extra, "CustomerCommon");

                    input.PreviewImgUrl = fileUrl;
                    var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
                }

                if (!string.IsNullOrWhiteSpace(fileUrl))
                {
                    if (input.ReponseContentType == (int)CustomerServiceMsgType.image)
                    {
                        input.MediaId = await _wxMediaUpload.UploadAndGetMediaID(input.MpID, fileUrl, MpMessageType.image);
                    }
                    else if (input.ReponseContentType == (int)CustomerServiceMsgType.video)
                    {
                        input.MediaId = await _wxMediaUpload.UploadAndGetMediaID(input.MpID, fileUrl, MpMessageType.voice);
                    }
                    else if (input.ReponseContentType == (int)CustomerServiceMsgType.voice)
                    {
                        input.MediaId = await _wxMediaUpload.UploadVideoAndGetMediaID(input.MpID, fileUrl, MpMessageType.video, input.Title, input.Description);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(input.MediaId))
                        {
                            input.MediaId = Guid.NewGuid().ToString();
                        }
                    }
                }
            }

            if (input.Id == 0)
            {
                result = await _CustomerServiceResponseTextAppService.Create(input);
            }
            else
            {
                result = await _CustomerServiceResponseTextAppService.Update(input);
            }
            return(Json(result));
        }