Пример #1
0
        /// <summary>
        /// 添加图文消息
        /// </summary>
        /// <param name="news"></param>
        /// <returns></returns>
        public string AddNews(WX_Media_News news)
        {
            var json = new
            {
                articles = new List <Object>()
                {
                    new
                    {
                        title                 = news.title,
                        thumb_media_id        = news.thumb_media_id,
                        author                = news.author,
                        digest                = news.digest,
                        show_cover_pic        = news.show_cover_pic,
                        content               = news.content,
                        content_source_url    = news.content_source_url,
                        need_open_comment     = news.need_open_comment,
                        only_fans_can_comment = news.only_fans_can_comment,
                    }
                }
            };
            string url      = string.Format(MEDIA_ADD_NEWS, this.Get_Access_Token());
            string respJson = MyHttpUtility.SendPost(url, JsonConvert.SerializeObject(json));

            return(respJson);
        }
Пример #2
0
        public ActionResult Sync()
        {
            var r           = false;
            var json        = JObject.Parse(new MediaService(WXAPP.AppId, WXAPP.AppSecret).Get("news"));
            int total_count = Convert.ToInt32(json["total_count"].ToString());
            int item_count  = Convert.ToInt32(json["total_count"].ToString());

            if (total_count > item_count)    //如果总数大于单次获取的量,那么循环调用
            {
            }
            else
            {
                WX_MediaManager manager = new WX_MediaManager();
                foreach (var i in json["item"].Children())
                {
                    var           jo   = i["content"]["news_item"][0];
                    WX_Media_News news = new WX_Media_News()
                    {
                        title              = jo["title"].ToString(),
                        thumb_media_id     = jo["thumb_media_id"].ToString(),
                        show_cover_pic     = Convert.ToInt32(jo["show_cover_pic"].ToString()),
                        author             = jo["author"].ToString(),
                        digest             = jo["digest"].ToString(),
                        content            = jo["content"].ToString(),
                        content_source_url = jo["content_source_url"].ToString(),
                        url = jo["url"].ToString(),
                    };

                    WX_Media media = new WX_Media()
                    {
                        AppId        = WXAPP.AppId,
                        MediaId      = i["media_id"].ToString(),
                        MediaName    = jo["title"].ToString(),
                        MediaType    = "news",
                        MediaContent = JsonConvert.SerializeObject(news).Replace("\\", "")
                    };
                    var info = manager.Where(m => m.AppId.Equals(media.AppId) && m.MediaId.Equals(media.MediaId)).FirstOrDefault();
                    if (info != null)
                    {
                        media.MyMediaId = info.MyMediaId;
                        r = manager.Update(media);
                    }
                    else
                    {
                        r = manager.Add(media);
                    }
                }
            }
            return(Json(r, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        private static WX_Media_News Trans(string MediaContent)
        {
            var           jo   = JObject.Parse(MediaContent);
            WX_Media_News news = new WX_Media_News()
            {
                author                = jo["author"].ToString(),
                content               = jo["content"].ToString(),
                content_source_url    = jo["content_source_url"].ToString(),
                digest                = jo["digest"].ToString(),
                need_open_comment     = Convert.ToInt32(jo["need_open_comment"]),
                only_fans_can_comment = Convert.ToInt32(jo["only_fans_can_comment"]),
                show_cover_pic        = Convert.ToInt32(jo["show_cover_pic"]),
                thumb_media_id        = jo["thumb_media_id"].ToString(),
                title = jo["title"].ToString(),
                url   = jo["url"].ToString(),
            };

            return(news);
        }
Пример #4
0
        public static string GetMediaId(this WX_Media_News news)
        {
            var content = JsonConvert.SerializeObject(news).Replace("\\", "");

            return(new WXDataEntities().WX_Media.Where(m => m.MediaContent.Equals(content)).FirstOrDefault().MediaId);
        }
Пример #5
0
 public static string GetPicUrl(this WX_Media_News news)
 {
     return(new WXDataEntities().WX_Media.Where(m => m.MediaId.Equals(news.thumb_media_id) && m.MediaType.Equals("image")).FirstOrDefault().MediaContent);
 }
Пример #6
0
        public ActionResult Add(WX_Media_News news)
        {
            var json = new MediaService(WXAPP.AppId, WXAPP.AppSecret).AddNews(news);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }