using System; using System.Collections.Generic; using System.Net; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Data; using System.Text; using System.Text.RegularExpressions; using System.Globalization; using System.Linq; using System.Collections.Specialized; using System.Web.Script.Serialization; namespace Mtxfw.shop._Admin { public partial class admin_weixin_add2 : Mtxfw.Utility.AdminPage { public Mtxfw.DAL.Article daoArt = new Mtxfw.DAL.Article(); public Mtxfw.Utility.Config config = new Mtxfw.Utility.Config(); public String TitName, strwtype = "0", strwtype2 = "0", strtitle, strBody = "", strimg=""; protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!IsPostBack) { wtype.Attributes.Add("onchange", "onwtype()"); wtype2.Attributes.Add("onchange", "onwtype2()"); } Hidd_Url.Value = Request.UrlReferrer.ToString(); if (Request.QueryString["ParentID"] != null && Request.QueryString["CategoryId"] != null) { if (Request.QueryString["action"] == "add") { TitName = "添加"; if (!IsPostBack) { Btn_Update.Visible = false; } } else { TitName = "更新"; if (!IsPostBack) { Btn_Insert.Visible = false; } Mtxfw.Model.Article model = daoArt.GetModel(int.Parse(Request.QueryString["ID"])); if (model != null) { if (!IsPostBack) { Text_Title.Text = model.Title; Text_Paths.Text = model.Paths; Text_addtime.Text = model.AddTime.ToString(); hiddenphoto.Value = model.Author; hiddenphoto2.Value = model.Author; for (int i = 0; i < wtype.Items.Count; i++) { if (wtype.Items[i].Value == model.wtype.ToString()) { wtype.Items[i].Selected = true; } else { wtype.Items[i].Selected = false; } } for (int i = 0; i < wtype2.Items.Count; i++) { if (wtype2.Items[i].Value == model.wtype2.ToString()) { wtype2.Items[i].Selected = true; } else { wtype2.Items[i].Selected = false; } } } strBody = model.Content; if (hiddenphoto.Value != "") { strimg = "
  • 删除
  • "; } } } } Btn_Insert.Click += delegate(object s, EventArgs ex) { Mtxfw.Model.Article model = new Mtxfw.Model.Article(); model.senderid = 0; model.receiverid = 0; model.Title = Text_Title.Text; model.KeyWords = ""; model.ParentID = int.Parse(Request.QueryString["ParentID"].ToString()); model.CategoryId = Request.QueryString["CategoryId"].ToString(); model.AddTime = DateTime.Now; model.Author = hiddenphoto.Value; model.thumb_media_id = ""; string access_token = Mtxfw.Utility.Common.getaccess_token(HttpContext.Current, config.webappKey, config.webappSecret, config); if (hiddenphoto.Value!=""&& hiddenphoto.Value!=hiddenphoto2.Value) { if ((wtype.SelectedItem.Value == "3" && wtype2.SelectedItem.Value == "1") || wtype2.SelectedItem.Value == "2") { List list = new List(); list.Add(new FormItem() { Name = "access_token", ParamType = ParamType.Text, Value = access_token }); list.Add(new FormItem() { Name = "type", Value = "image", ParamType = ParamType.Text });//媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb) list.Add(new FormItem() { Name = "media", Value = config.webUpPath + hiddenphoto.Value, ParamType = ParamType.File }); string response = Funcs.PostFormData(list, "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=" + access_token); string thumb_media_id = ""; if (response.Length > 0) { if (response.IndexOf("media_id") != -1) { thumb_media_id = response.Replace("\"", "").Replace(":", "").Replace("{", "").Replace("}", "").Replace("(", "").Replace("media_id", "").Replace(";", "").Trim(); } } model.thumb_media_id = thumb_media_id; } else { model.thumb_media_id = ""; } } else model.Author = String.Empty; model.media_id = ""; model.Content = Hidd_myEditor.Value; model.Content2 = ""; model.Paths = Text_Paths.Text; model.Paths2 = ""; model.Seef = 1; model.wtype = Convert.ToInt32(wtype.SelectedItem.Value); model.wtype2 = Convert.ToInt32(wtype2.SelectedItem.Value); model.LinkID = 0; daoArt.Add(model); if (Session["UploadFileIng"] != null) { string[] stra = Session["UploadFileIng"].ToString().Split(','); foreach (string str in stra) { if (str.Trim() != "") { if (model.Content.IndexOf(str.Trim()) == -1) { if (System.IO.File.Exists(Server.MapPath(str.Trim()))) { System.IO.File.Delete(Server.MapPath(str.Trim())); } } } } } Session.Remove("UploadFileIng"); System.Collections.IDictionaryEnumerator CacheEnum = Cache.GetEnumerator(); while (CacheEnum.MoveNext()) { Cache.Remove(CacheEnum.Key.ToString()); } Response.Redirect(Hidd_Url.Value); }; Btn_Update.Click += delegate(object s, EventArgs ex) { Int32 ID = int.Parse(Request.QueryString["ID"]); Mtxfw.Model.Article model = daoArt.GetModel(ID); model.senderid = 0; model.receiverid = 0; model.Title = Text_Title.Text; model.ParentID = int.Parse(Request.QueryString["ParentID"].ToString()); model.AddTime = Convert.ToDateTime(Text_addtime.Text); model.Content = Hidd_myEditor.Value; model.Content2 = ""; model.Paths = Text_Paths.Text; model.Author = hiddenphoto.Value; model.LinkID = 0; model.id = ID; string access_token = Mtxfw.Utility.Common.getaccess_token(HttpContext.Current, config.webappKey, config.webappSecret, config); if (hiddenphoto.Value!=""&& hiddenphoto.Value!=hiddenphoto2.Value) { if ((wtype.SelectedItem.Value == "3" && wtype2.SelectedItem.Value == "1") || wtype2.SelectedItem.Value == "2") { List list = new List(); list.Add(new FormItem() { Name = "access_token", ParamType = ParamType.Text, Value = access_token }); list.Add(new FormItem() { Name = "type", Value = "image", ParamType = ParamType.Text });//媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb) list.Add(new FormItem() { Name = "media", Value = config.webUpPath + hiddenphoto.Value, ParamType = ParamType.File }); string response = Funcs.PostFormData(list, "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=" + access_token); Mtxfw.Utility.Common.WriteHtml("/weixin/weixin.txt", response); string thumb_media_id = ""; if (response.Length > 0) { if (response.IndexOf("media_id") != -1) { thumb_media_id = response.Replace("\"", "").Replace(":", "").Replace("{", "").Replace("}", "").Replace("(", "").Replace("media_id", "").Replace(";", "").Trim(); Mtxfw.Utility.Common.WriteHtml("/weixin/weixin.txt", response + "|thumb_media_id=" + thumb_media_id); } } if (thumb_media_id != "") { model.thumb_media_id = thumb_media_id; } } } model.wtype = Convert.ToInt32(wtype.SelectedItem.Value); model.wtype2 = Convert.ToInt32(wtype2.SelectedItem.Value); daoArt.Update(model); if (Session["UploadFileIng"] != null) { string[] stra = Session["UploadFileIng"].ToString().Split(','); foreach (string str in stra) { if (str.Trim() != "") { if (model.Content.IndexOf(str.Trim()) == -1) { if (System.IO.File.Exists(Server.MapPath(str.Trim()))) { System.IO.File.Delete(Server.MapPath(str.Trim())); } } } } } Session.Remove("UploadFileIng"); System.Collections.IDictionaryEnumerator CacheEnum = Cache.GetEnumerator(); while (CacheEnum.MoveNext()) { Cache.Remove(CacheEnum.Key.ToString()); } Response.Redirect(Hidd_Url.Value); }; } public object FromJson(string json) { JavaScriptSerializer js = new JavaScriptSerializer(); return js.Deserialize(json); } } }