// GET: WXMedia/News public ActionResult Index(int index = 1, int size = 3) { var list = new WX_MediaManager().Where(m => m.AppId.Equals(WXAPP.AppId) && (m.MediaType.Equals("news"))); ViewBag.PageList = new PageList <WX_Media_News>(list.TransitionToNews(), index, size); return(View()); }
/// <summary> /// 测试用群发消息 /// </summary> /// <param name="text"></param> public void Send() { var news = new WX_MediaManager().Where(m => m.MediaType.Equals("news"))[0]; List <string> openIdList = WXAPP.WX_User.ToList().GetOpenIdList(); string result = new MessageService(WXAPP.AppId, WXAPP.AppSecret).Send(news); WX_CustomMsgManager manager = new WX_CustomMsgManager(); JObject json = JObject.Parse(result); if (json["errcode"].ToString().Equals("0")) { foreach (var i in openIdList) { WX_CustomMsg msg = new WX_CustomMsg() { MsgId = json["msg_id"].ToString(), OpenID = i, AppId = WXAPP.AppId, CreateTime = DateTime.Now, Content = news.MediaContent, MsgSource = "客服", MsgType = "text", }; manager.Add(msg); } } }
/// <summary> /// 图文 /// </summary> /// <returns></returns> public ActionResult Sync(string AppId) { var Ap = new WX_AppManager().GetByPK(AppId); var list = new WX_MediaManager().Where(m => m.AppId.Equals(Ap.AppId) && m.MediaType.Equals("news")).TransitionToNews(); return(Json(list, JsonRequestBehavior.AllowGet)); }
public ActionResult Delete(string mediaid) { WX_MediaManager manager = new WX_MediaManager(); var json = JObject.Parse(new MediaService(WXAPP.AppId, WXAPP.AppSecret).Delete(mediaid)); if (json["errcode"].ToString().Equals("0")) { var info = manager.GetByMediaId(mediaid, WXAPP.AppId); var r = manager.Delete(info.MyMediaId); return(Json(r, JsonRequestBehavior.AllowGet)); } return(Json(false, JsonRequestBehavior.AllowGet)); }
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)); }
public ActionResult GetPublicMedia() { var list = new WX_MediaManager().Where(m => m.AppId == null); var json = list.Select(m => new { m.MyMediaId, m.MediaId, m.MediaName, m.MediaType, m.MediaContent, m.MediaState, m.UploadTime, }); return(Json(list, JsonRequestBehavior.AllowGet)); }
public ActionResult AddMedia(FormCollection form) { if (Request.Files.Count == 0) { //Request.Files.Count 文件数为0上传不成功 return(Json("文件数为0上传不成功", JsonRequestBehavior.AllowGet)); } var file = Request.Files["Media"]; if (file.ContentLength == 0) { //文件大小(以字节为单位)为0时,做一些操作 return(Json("文件大小(以字节为单位)为0", JsonRequestBehavior.AllowGet)); } else { HttpPostedFileBase files = Request.Files[0]; string fileName = (!string.IsNullOrEmpty(form["FileName"])) ? form["FileName"]: files.FileName; string format = files.FileName.Substring(files.FileName.LastIndexOf('.')); if (fileName.IndexOf(format) == -1) { fileName += format; } //文件大小不为0 string url = Server.MapPath("/Upload/") + fileName; files.SaveAs(url); MediaService ser = new MediaService(WXAPP.AppId, WXAPP.AppSecret); JObject jo = ser.PostImage(fileName); //返回一个mediaid和url if (jo != null) //新增成功 { var r = new WX_MediaManager().Add(new WX_Media() { AppId = WXAPP.AppId, MediaId = jo["media_id"].ToString(), MediaName = fileName, MediaType = "image", MediaContent = jo["url"].ToString(), UploadTime = DateTime.Now, }); } } return(Redirect("Index")); }
public ActionResult SyncImage() { string json = new MediaService(WXAPP.AppId, WXAPP.AppSecret).Get("image"); JObject jo = JObject.Parse(json); if (jo["errcode"] != null) { return(Content("<script> alert('错误:" + jo["errmsg"].ToString() + "');</script>")); } int total_count = Convert.ToInt32(jo["total_count"]); // 该类型素材总数 int item_count = Convert.ToInt32(jo["item_count"]); // 本次获取的素材数量 if (total_count > item_count) //如果总数大于单次获取的量,那么循环调用 { } else { WX_MediaManager manager = new WX_MediaManager(); foreach (var i in jo["item"].Children()) { var media = new WX_Media() { AppId = WXAPP.AppId, MediaId = i["media_id"].ToString(), MediaName = i["name"].ToString(), MediaType = "image", MediaContent = i["url"].ToString(), //UploadTime = DateTime_EX.GetDateTime(Convert.ToInt32(i["update_Time"].ToString())) }; var info = manager.GetByMediaId(media.MediaId, media.AppId); if (info != null) { media.MyMediaId = info.MyMediaId; var r = manager.Update(media); } else { var r = manager.Add(media); } } } return(Json(json, JsonRequestBehavior.AllowGet)); }