Exemplo n.º 1
0
        /// <summary>
        /// 更新永久图文素材
        /// </summary>
        /// <param name="keyValue"></param>
        public void UpdateForeverNews(string keyValue)
        {
            long   id            = Convert.ToInt64(keyValue);
            string appId         = WxOperatorProvider.Provider.GetCurrent().AppId;
            var    specification = new Specification <WxNews>().FetchStrategy.Include(p => p.WxNewsItems.Select(e => e.Thumb));
            WxNews wxNews        = wxNewsRepository.Get(id, specification);

            NewsModel[] newsModel = new NewsModel[wxNews.WxNewsItems.Count()];
            var         index     = 0;

            foreach (WxNewsItem wxNewsItem in wxNews.WxNewsItems)
            {
                newsModel[index]                       = new NewsModel();
                newsModel[index].title                 = wxNewsItem.Title;
                newsModel[index].author                = wxNewsItem.Author;
                newsModel[index].content               = wxNewsItem.Content;
                newsModel[index].content_source_url    = wxNewsItem.ContentSourceUrl;
                newsModel[index].digest                = wxNewsItem.Digest;
                newsModel[index].need_open_comment     = wxNewsItem.NeedOpenComment;
                newsModel[index].only_fans_can_comment = wxNewsItem.OnlyFansCanComment;
                newsModel[index].show_cover_pic        = wxNewsItem.ShowCoverPic.ToString();
                newsModel[index].thumb_media_id        = wxNewsItem.Thumb.MediaId;
                newsModel[index].thumb_url             = wxNewsItem.Thumb.MediaUrl;
                index++;
            }
            if (!string.IsNullOrEmpty(wxNews.MediaId))
            {
                for (var i = 0; i < newsModel.Length; i++)
                {
                    var wxJsonResult = MediaApi.UpdateForeverNews(appId, wxNews.MediaId, i, newsModel[i], 10000);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 新增永久图文素材
        /// </summary>
        /// <param name="keyValue">NewsId</param>
        public UploadForeverMediaResult UploadForeverNews(string keyValue)
        {
            long   id            = Convert.ToInt64(keyValue);
            string appId         = WxOperatorProvider.Provider.GetCurrent().AppId;
            var    specification = new Specification <WxNews>().FetchStrategy.Include(p => p.WxNewsItems.Select(e => e.Thumb));
            WxNews wxNews        = wxNewsRepository.Get(id, specification);

            NewsModel[] newsModel = new NewsModel[wxNews.WxNewsItems.Count()];
            foreach (WxNewsItem wxNewsItem in wxNews.WxNewsItems)
            {
                int index = wxNews.WxNewsItems.IndexOf(wxNewsItem);
                newsModel[index]                       = new NewsModel();
                newsModel[index].title                 = wxNewsItem.Title;
                newsModel[index].author                = wxNewsItem.Author;
                newsModel[index].content               = wxNewsItem.Content;
                newsModel[index].content_source_url    = wxNewsItem.ContentSourceUrl;
                newsModel[index].digest                = wxNewsItem.Digest;
                newsModel[index].need_open_comment     = wxNewsItem.NeedOpenComment;
                newsModel[index].only_fans_can_comment = wxNewsItem.OnlyFansCanComment;
                newsModel[index].show_cover_pic        = wxNewsItem.ShowCoverPic.ToString();
                newsModel[index].thumb_media_id        = wxNewsItem.Thumb.MediaId;
                newsModel[index].thumb_url             = wxNewsItem.Thumb.MediaUrl;
            }
            var uploadForeverMediaResult = MediaApi.UploadNews(appId, 10000, newsModel);

            if (uploadForeverMediaResult.ErrorCodeValue == 0)
            {
                wxNews.MediaId = uploadForeverMediaResult.media_id;
                wxNewsRepository.Update(wxNews);
            }
            return(uploadForeverMediaResult);
        }
Exemplo n.º 3
0
        public WxNewsOutputDto GetForm(string keyValue)
        {
            var    id = Convert.ToInt64(keyValue);
            var    genericFetchStrategy = new GenericFetchStrategy <WxNews>().Include(p => p.WxNewsItems.Select(e => e.Thumb));
            WxNews wxNews = wxNewsRepository.Get(id, genericFetchStrategy);

            wxNews.WxNewsItems = wxNews.WxNewsItems.OrderBy(u => u.Index).ToList();
            WxNewsOutputDto wxNewsOutputDto = new WxNewsOutputDto();

            AutoMapper.Mapper.Map <WxNews, WxNewsOutputDto>(wxNews, wxNewsOutputDto);
            return(wxNewsOutputDto);
        }
Exemplo n.º 4
0
        public void DeleteForm(string keyValue)
        {
            var    id = Convert.ToInt64(keyValue);
            var    genericFetchStrategy = new GenericFetchStrategy <WxNews>().Include(p => p.WxNewsItems);
            WxNews wxNews = wxNewsRepository.Get(id, genericFetchStrategy);

            if (!string.IsNullOrEmpty(wxNews.MediaId))
            {
                string            appId             = WxOperatorProvider.Provider.GetCurrent().AppId;
                AccessTokenResult accessTokenResult = AccessTokenContainer.GetAccessTokenResult(appId);
                var wxJsonResult = MediaApi.DeleteForeverMedia(accessTokenResult.access_token, wxNews.MediaId, 10000);
                if (wxJsonResult.ErrorCodeValue == 0)
                {
                    wxNews.MediaId      = null;
                    wxNews.DeletedMark  = true;
                    wxNews.DeletionTime = DateTime.Now;
                    foreach (WxNewsItem item in wxNews.WxNewsItems)
                    {
                        item.DeletedMark  = true;
                        item.DeletionTime = DateTime.Now;
                    }
                    wxNewsRepository.Update(wxNews);
                }
            }
            else
            {
                wxNews.MediaId      = null;
                wxNews.DeletedMark  = true;
                wxNews.DeletionTime = DateTime.Now;
                foreach (WxNewsItem item in wxNews.WxNewsItems)
                {
                    item.DeletedMark  = true;
                    item.DeletionTime = DateTime.Now;
                }
                wxNewsRepository.Update(wxNews);
            }
        }
        /// <summary>
        /// 保存微信永久图文消息
        /// </summary>
        /// <param name="lstNewsIds"></param>
        /// <param name="syncRes"></param>
        private async Task SyncWxNews(List <string> lstNewsIds, PubNewsResult syncRes)
        {
            // 保存永久图文消息
            var dtNow    = DateTime.Now;
            var userName = currentUser.UserName;

            foreach (var item in syncRes.item)
            {
                try
                {
                    // 保存图文消息
                    var exist = await repo.FirstOrDefaultAsync <WxNews>(x => x.MediaId == item.media_id);

                    if (exist == null)
                    {
                        exist            = new WxNews();
                        exist.Creater    = userName;
                        exist.CreateTime = dtNow;
                        exist.MediaId    = item.media_id;
                    }

                    var lstDets = item.content.news_item;
                    exist.FirstNewsTitle = lstDets[0].title;
                    exist.IsMultiple     = lstDets.Count > 1 ? 1 : 0;
                    exist.Updater        = userName;
                    exist.UpdateTime     = dtNow;
                    exist.IsDel          = 0;
                    await repo.SaveAsync(exist);

                    lstNewsIds.Add(exist.MediaId);

                    var lstDetIds   = new List <long>();
                    var lstNewsTemp = new List <WxNewsDetail> {
                    };
                    foreach (var det in lstDets)
                    {
                        // 保存图文详情
                        var detTemp = new WxNewsDetail();
                        detTemp.MediaId          = exist.MediaId;
                        detTemp.Title            = det.title;
                        detTemp.ThumbMediaId     = det.thumb_media_id;
                        detTemp.ThumbUrl         = det.thumb_url;
                        detTemp.Author           = det.author;
                        detTemp.Digest           = det.digest;
                        detTemp.ShowCoverPic     = det.show_cover_pic;
                        detTemp.Content          = det.content;
                        detTemp.ContentSourceUrl = det.content_source_url;
                        detTemp.WxUrl            = det.url;
                        detTemp.IsDel            = 0;
                        detTemp.Creater          = userName;
                        detTemp.Updater          = userName;
                        detTemp.CreateTime       = dtNow;
                        detTemp.UpdateTime       = dtNow;
                        //await repo.SaveAsync(detTemp);
                        //lstDetIds.Add(detTemp.Id);
                        lstNewsTemp.Add(detTemp);
                    }

                    await repo.SaveAsync(lstNewsTemp);

                    lstDetIds = lstNewsTemp.Select(x => x.Id).ToList();

                    // 删除以前旧的图文详情信息
                    if (lstDetIds.Count > 0)
                    {
                        var sqlStr = string.Format(" UPDATE WxNewsDetail SET IsDel = 1, Updater = '{0}', UpdateTime = '{1}' WHERE MediaId = {2} AND Id NOT IN ({3}) ",
                                                   userName, dtNow, exist.MediaId, lstDetIds);
                        await repo.ExecuteCommandAsync(sqlStr);
                    }
                }
                catch (Exception ex)
                {
                    logHelper.Error("SyncWxNews:保存永久图文失败:" + ex.Message + "     " + ex.StackTrace);
                }
            }
        }
Exemplo n.º 6
0
        public void SubmitForm(WxNewsInputDto wxNewsInputDto, string keyValue)
        {
            string appId  = WxOperatorProvider.Provider.GetCurrent().AppId;
            WxNews wxNews = new WxNews();

            if (!string.IsNullOrEmpty(keyValue))
            {
                long newsId = Convert.ToInt64(keyValue);
                var  genericFetchStrategy = new GenericFetchStrategy <WxNews>().Include(p => p.WxNewsItems.First().Thumb);
                wxNews = wxNewsRepository.Get(newsId, genericFetchStrategy);
                wxNews.LastModificationTime = DateTime.Now;
                wxNewsRepository.Update(wxNews);
                foreach (WxNewsItemInputDto wxNewsItemInputDto in wxNewsInputDto.WxNewsItems)
                {
                    if (!string.IsNullOrEmpty(wxNewsItemInputDto.Id))
                    {
                        long       newsItemId = Convert.ToInt64(wxNewsItemInputDto.Id);
                        WxNewsItem wxNewsItem = wxNewsItemRepository.Get(newsItemId);
                        wxNewsItem.NewsId           = wxNews.Id;
                        wxNewsItem.Title            = wxNewsItemInputDto.Title;
                        wxNewsItem.Author           = wxNewsItemInputDto.Author;
                        wxNewsItem.Digest           = wxNewsItemInputDto.Digest;
                        wxNewsItem.Content          = wxNewsItemInputDto.Content;
                        wxNewsItem.ContentSourceUrl = wxNewsItemInputDto.ContentSourceUrl;
                        wxNewsItem.ThumbId          = Convert.ToInt64(wxNewsItemInputDto.Thumb.Id);
                        if (!string.IsNullOrEmpty(wxNewsItemInputDto.Thumb.MediaId))
                        {
                            wxNewsItem.ShowCoverPic = 1;
                        }
                        else
                        {
                            wxNewsItem.ShowCoverPic = 0;
                        }
                        wxNewsItem.Index                = wxNewsItemInputDto.Index;
                        wxNewsItem.NeedOpenComment      = wxNewsItemInputDto.NeedOpenComment;
                        wxNewsItem.OnlyFansCanComment   = wxNewsItemInputDto.OnlyFansCanComment;
                        wxNewsItem.LastModificationTime = DateTime.Now;
                        wxNewsItemRepository.Update(wxNewsItem);
                    }
                    else
                    {
                        WxNewsItem wxNewsItem = new WxNewsItem();
                        wxNewsItem.Id               = IdWorkerHelper.GenId64();
                        wxNewsItem.NewsId           = wxNews.Id;
                        wxNewsItem.Title            = wxNewsItemInputDto.Title;
                        wxNewsItem.Author           = wxNewsItemInputDto.Author;
                        wxNewsItem.Digest           = wxNewsItemInputDto.Digest;
                        wxNewsItem.Content          = wxNewsItemInputDto.Content;
                        wxNewsItem.ContentSourceUrl = wxNewsItemInputDto.ContentSourceUrl;
                        wxNewsItem.ThumbId          = Convert.ToInt64(wxNewsItemInputDto.Thumb.Id);
                        if (!string.IsNullOrEmpty(wxNewsItemInputDto.Thumb.Id))
                        {
                            wxNewsItem.ShowCoverPic = 1;
                        }
                        else
                        {
                            wxNewsItem.ShowCoverPic = 0;
                        }
                        wxNewsItem.Index              = wxNewsItemInputDto.Index;
                        wxNewsItem.NeedOpenComment    = wxNewsItemInputDto.NeedOpenComment;
                        wxNewsItem.OnlyFansCanComment = wxNewsItemInputDto.OnlyFansCanComment;
                        wxNewsItem.DeletedMark        = false;
                        wxNewsItem.CreationTime       = DateTime.Now;
                        wxNewsItemRepository.Add(wxNewsItem);
                    }
                }
            }
            else
            {
                wxNews.Id           = IdWorkerHelper.GenId64();
                wxNews.AppId        = appId;
                wxNews.DeletedMark  = false;
                wxNews.CreationTime = DateTime.Now;
                wxNews.WxNewsItems  = new List <WxNewsItem>();
                foreach (WxNewsItemInputDto wxNewsItemInputDto in wxNewsInputDto.WxNewsItems)
                {
                    WxNewsItem wxNewsItem = new WxNewsItem();
                    wxNewsItem.Id               = IdWorkerHelper.GenId64();
                    wxNewsItem.NewsId           = wxNews.Id;
                    wxNewsItem.Title            = wxNewsItemInputDto.Title;
                    wxNewsItem.Author           = wxNewsItemInputDto.Author;
                    wxNewsItem.Digest           = wxNewsItemInputDto.Digest;
                    wxNewsItem.Content          = wxNewsItemInputDto.Content;
                    wxNewsItem.ContentSourceUrl = wxNewsItemInputDto.ContentSourceUrl;
                    wxNewsItem.ThumbId          = Convert.ToInt64(wxNewsItemInputDto.Thumb.Id);
                    if (!string.IsNullOrEmpty(wxNewsItemInputDto.Thumb.Id))
                    {
                        wxNewsItem.ShowCoverPic = 1;
                    }
                    else
                    {
                        wxNewsItem.ShowCoverPic = 0;
                    }
                    wxNewsItem.Index              = wxNewsItemInputDto.Index;
                    wxNewsItem.NeedOpenComment    = wxNewsItemInputDto.NeedOpenComment;
                    wxNewsItem.OnlyFansCanComment = wxNewsItemInputDto.OnlyFansCanComment;
                    wxNewsItem.DeletedMark        = false;
                    wxNewsItem.CreationTime       = DateTime.Now;
                    wxNews.WxNewsItems.Add(wxNewsItem);
                }
                wxNewsRepository.Add(wxNews);
            }
        }