using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Text.RegularExpressions; using System.Globalization; using System.Data; using System.Text; using System.Security.Cryptography; namespace Mtxfw.VipSite { public partial class Admin_Member_gong_add : Mtxfw.Utility.MemberBase { public Mtxfw.Utility.Config config = new Mtxfw.Utility.Config(""); public Mtxfw.DAL.Article daoArt = new Mtxfw.DAL.Article(); public String strTitle = "", strBody="", Signature = ""; protected override void OnLoad(EventArgs e) { base.OnLoad(e); string hostname = Request.Url.Host; /*string secretId = config.AccessKeyId; long currentTimeStamp = Mtxfw.Utility.Common.CreatenTimestamp(DateTime.Now); long expireTime = Mtxfw.Utility.Common.CreatenTimestamp(DateTime.Now.AddHours(24)); string random = Mtxfw.Utility.Common.RandNum(6); long classId = 659337; string strkey = "secretId=" + secretId + "¤tTimeStamp=" + currentTimeStamp + "&expireTime=" + expireTime + "&random=" + random + "&classId=" + classId + "&storageRegion=ap-beijing"; byte[] bytesSign = hash_hmac_byte(strkey, config.AccessKeySecret); byte[] byteContent = System.Text.Encoding.Default.GetBytes(strkey); byte[] nCon = new byte[bytesSign.Length + byteContent.Length]; bytesSign.CopyTo(nCon, 0); byteContent.CopyTo(nCon, bytesSign.Length); Signature = Convert.ToBase64String(nCon);*/ if (!IsPostBack) { if (Session["IFPassword"] == null) { Response.Redirect("/Member_IFPassword.aspx?Url=/Admin_Member_gong.aspx"); } if (IFStores != 1) { Mtxfw.Utility.Tools.Message("您没有权限!", "/gl.aspx"); } if (MemberJS.IndexOf("视频管理") == -1) { Mtxfw.Utility.Tools.Message("您没有权限!", "/gl.aspx"); } Data_Bind(); } Btn_Insert.Click += delegate(object s, EventArgs ex) { bool b = true; /*if (b) { if (!System.Text.RegularExpressions.Regex.IsMatch(Text_Minute.Text, @"^-?\d+$")) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } }*/ string strUpPath = ""; if (b) { Mtxfw.Utility.UploadFile upload = new Utility.UploadFile(File_AdsImg.PostedFile, config.webUpPath, config.webUpType, int.Parse(config.webUpSize)); if (File_AdsImg.FileName.Length > 0) { upload.StatrUpFile(); if (!String.IsNullOrEmpty(upload.UploadPath)) { strUpPath = upload.UploadPath; } else { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } } if (b) { try { Mtxfw.Model.Article model = new Mtxfw.Model.Article(); model.senderid = 0; model.receiverid = 0; model.Title = Text_Title.Text; model.ParentID = 18; model.CategoryId = "0";//DropType.SelectedItem.Value model.AddTime = DateTime.Now; model.Author = strUpPath; model.Content = Hidd_myEditor.Value; model.Paths = hiddenvideo.Value; model.Content2 = ""; model.Paths2 = ""; model.media_id = (Text_Minute.Text != "" ? Text_Minute.Text : "0"); model.thumb_media_id = ""; model.wtype = (Text_Num.Text != "" ? Convert.ToInt32(Text_Num.Text) : 0); model.wtype2 = 0; string strzd = daoArt.Getzd("max(LinkID)", "ParentID=" + model.ParentID).ToString(); if (strzd != "") { model.LinkID = (Convert.ToInt32(strzd) + 1); } else { model.LinkID = 0; } model.Seef = 1; model.KeyWords = ""; model.gtype = 0; model.id = daoArt.Add(model); model = daoArt.GetModel(model.id); Decimal latitude = 0; Decimal longitude = 0; model.jlsecond = (Text_Minute.Text != "" ? Convert.ToInt32(Text_Minute.Text) : 0); model.xfjmoney = 0; model.tfllmoney = 0; model.zscs = 0; model.gxzmoney = 0; model.ltype = 0; model.csday = (Text_Num.Text != "" ? Convert.ToInt32(Text_Num.Text) : 0); model.latitude = latitude; model.longitude = longitude; if (model.Paths != "") { if (model.Paths.IndexOf("https://fv.pmhapp.cn/mdavideo/") != -1) { Qiniu.Util.Mac mac = new Qiniu.Util.Mac(config.qiniuAccessKey, config.qiniuSecretKey); //Qiniu.Storage.PutPolicy putPolicy = new Qiniu.Storage.PutPolicy(); //putPolicy.Scope = config.qiniuScope; //string upToken = Qiniu.Util.Auth.CreateUploadToken(mac, putPolicy.ToJsonString()); Qiniu.Storage.Config qnconfig = new Qiniu.Storage.Config(); // 设置上传区域 qnconfig.Zone = Qiniu.Storage.Zone.ZONE_CN_South; // 设置 http 或者 https 上传 qnconfig.UseHttps = true; qnconfig.UseCdnDomains = true; string Bucket = config.qiniuScope; // 文件名 string Key = model.Paths.Replace("https://fv.pmhapp.cn/", ""); bool force = false; // 队列名称,如果没有,请设置为null // 另请参阅https://qiniu.kf5.com/hc/kb/article/112978/ string pipeline = "default.sys"; // 接收处理结果通知的URL,另请参阅 string notifyUrl = config.webUrl + "/pay/qiniunotifyUrl.aspx"; // 要保存的目标空间 string dstBucket = config.qiniuScope; string dstKey = Key.Replace("mdavideo/", "mdadvideo/"); string saveAsUri = Qiniu.Util.Base64.UrlSafeBase64Encode(dstBucket + ":" + dstKey); // 需要执行的数据处理,例如视频转码 string fopM = "avthumb/mp4"; //示例: "avthumb/mp4"; // 使用管道'|'命令,将处理结果saveas另存 string fops = fopM + "|saveas/" + saveAsUri; // 这个示例单独使用了一个Settings类,其中包含AccessKey和SecretKey // 实际应用中,请自行设置您的AccessKey和SecretKey Qiniu.Storage.OperationManager ox = new Qiniu.Storage.OperationManager(mac, qnconfig); Qiniu.Storage.PfopResult result = ox.Pfop(Bucket, Key, fops, pipeline, notifyUrl, force); if (result.Code == 200) { model.thumb_media_id = result.PersistentId; } } } daoArt.Update(model); Model.User_CZ_log logmodel = new Model.User_CZ_log(); logmodel.MemberId = Card; logmodel.AddTime = DateTime.Now; logmodel.IP = Mtxfw.Utility.Common.GetIP; logmodel.Body = "添加视频,标题:" + model.Title + ""; logmodel.UType = 0; logmodel.gtype = 1; new DAL.User_CZ_log().Add(logmodel); 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"); } if (Session["UploadFileIng0"] != null) { string[] stra = Session["UploadFileIng0"].ToString().Split(','); foreach (string str in stra) { if (str.Trim() != "") { if (model.Author != str.Trim()) { if (System.IO.File.Exists(Server.MapPath(str.Trim()))) { System.IO.File.Delete(Server.MapPath(str.Trim())); } } } } Session.Remove("UploadFileIng0"); } System.Collections.IDictionaryEnumerator CacheEnum = Cache.GetEnumerator(); while (CacheEnum.MoveNext()) { Cache.Remove(CacheEnum.Key.ToString()); } ClientScript.RegisterStartupScript(this.GetType(), "", ""); } catch (Exception err) { Mtxfw.Utility.Common.WriteHtml("/weixin/gong_add_err.txt", err.ToString()); } } }; Btn_Update.Click += delegate(object s, EventArgs ex) { bool b = true; /*if (b) { if (!System.Text.RegularExpressions.Regex.IsMatch(Text_Minute.Text, @"^-?\d+$")) { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } }*/ string strUpPath = ""; if (b) { Mtxfw.Utility.UploadFile upload = new Utility.UploadFile(File_AdsImg.PostedFile, config.webUpPath, config.webUpType, int.Parse(config.webUpSize)); if (File_AdsImg.FileName.Length > 0) { upload.StatrUpFile(); if (!String.IsNullOrEmpty(upload.UploadPath)) { strUpPath = upload.UploadPath; } else { b = false; ClientScript.RegisterStartupScript(this.GetType(), "", ""); } } else { strUpPath = Hidd_Img.Value; } } if(b) { Int32 ID = int.Parse(Request.QueryString["ID"]); Mtxfw.Model.Article model = daoArt.GetModel(ID); model.Title = Text_Title.Text; model.Author = strUpPath; model.Paths = hiddenvideo.Value; model.Content = Hidd_myEditor.Value; model.jlsecond = (Text_Minute.Text != "" ? Convert.ToInt32(Text_Minute.Text) : 0); model.csday = (Text_Num.Text != "" ? Convert.ToInt32(Text_Num.Text) : 0); if (model.Paths != "") { if (model.Paths.IndexOf("https://fv.pmhapp.cn/mdavideo/") != -1) { Qiniu.Util.Mac mac = new Qiniu.Util.Mac(config.qiniuAccessKey, config.qiniuSecretKey); //Qiniu.Storage.PutPolicy putPolicy = new Qiniu.Storage.PutPolicy(); //putPolicy.Scope = config.qiniuScope; //string upToken = Qiniu.Util.Auth.CreateUploadToken(mac, putPolicy.ToJsonString()); Qiniu.Storage.Config qnconfig = new Qiniu.Storage.Config(); // 设置上传区域 qnconfig.Zone = Qiniu.Storage.Zone.ZONE_CN_South; // 设置 http 或者 https 上传 qnconfig.UseHttps = true; qnconfig.UseCdnDomains = true; string Bucket = config.qiniuScope; // 文件名 string Key = model.Paths.Replace("https://fv.pmhapp.cn/", ""); bool force = false; // 队列名称,如果没有,请设置为null // 另请参阅https://qiniu.kf5.com/hc/kb/article/112978/ string pipeline = "default.sys"; // 接收处理结果通知的URL,另请参阅 string notifyUrl = config.webUrl + "/pay/qiniunotifyUrl.aspx"; // 要保存的目标空间 string dstBucket = config.qiniuScope; string dstKey = Key.Replace("mdavideo/", "mdadvideo/"); string saveAsUri = Qiniu.Util.Base64.UrlSafeBase64Encode(dstBucket + ":" + dstKey); // 需要执行的数据处理,例如视频转码 string fopM = "avthumb/mp4"; //示例: "avthumb/mp4"; // 使用管道'|'命令,将处理结果saveas另存 string fops = fopM + "|saveas/" + saveAsUri; // 这个示例单独使用了一个Settings类,其中包含AccessKey和SecretKey // 实际应用中,请自行设置您的AccessKey和SecretKey Qiniu.Storage.OperationManager ox = new Qiniu.Storage.OperationManager(mac, qnconfig); Qiniu.Storage.PfopResult result = ox.Pfop(Bucket, Key, fops, pipeline, notifyUrl, force); if (result.Code == 200) { model.thumb_media_id = result.PersistentId; } } } daoArt.Update(model); Model.User_CZ_log logmodel = new Model.User_CZ_log(); logmodel.MemberId = Card; logmodel.AddTime = DateTime.Now; logmodel.IP = Mtxfw.Utility.Common.GetIP; logmodel.Body = "修改视频,标题:" + model.Title + ""; logmodel.UType = 0; logmodel.gtype = 0; new DAL.User_CZ_log().Add(logmodel); 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"); } if (Session["UploadFileIng0"] != null) { string[] stra = Session["UploadFileIng0"].ToString().Split(','); foreach (string str in stra) { if (str.Trim() != "") { if (model.Author != str.Trim()) { if (System.IO.File.Exists(Server.MapPath(str.Trim()))) { System.IO.File.Delete(Server.MapPath(str.Trim())); } } } } Session.Remove("UploadFileIng0"); } System.Collections.IDictionaryEnumerator CacheEnum = Cache.GetEnumerator(); while (CacheEnum.MoveNext()) { Cache.Remove(CacheEnum.Key.ToString()); } ClientScript.RegisterStartupScript(this.GetType(), "", ""); } }; } protected void Data_Bind() { if (Request.UrlReferrer != null) { Hidd_Url.Value = Request.UrlReferrer.ToString(); } else { Hidd_Url.Value = "Admin_Member_gong.aspx"; } if (Request.QueryString["ID"] == null) { strTitle = "添加视频"; Page.Title = strTitle + " - " + GetWebName; Btn_Update.Visible = false; } else { strTitle = "更新视频"; Page.Title = strTitle + " - " + GetWebName; Btn_Insert.Visible = false; Mtxfw.Model.Article model = daoArt.GetModel(int.Parse(Request.QueryString["ID"])); if (model != null) { Text_Title.Text = model.Title; Text_Minute.Text = model.jlsecond.ToString(); Text_Num.Text = model.csday.ToString(); strBody = model.Content; hiddenvideo.Value = model.Paths; if (!String.IsNullOrEmpty(model.Author)) { Img_Img.Visible = true; Img_Img.Src = Mtxfw.Utility.Common.GetCoverPic(model.Author, "40x40", config.webImgMode); Hidd_Img.Value = model.Author; } else { Img_Img.Visible = false; Hidd_Img.Value = String.Empty; } } } } private byte[] hash_hmac_byte(string signatureString, string secretKey) { var enc = Encoding.UTF8; HMACSHA1 hmac = new HMACSHA1(enc.GetBytes(secretKey)); hmac.Initialize(); byte[] buffer = enc.GetBytes(signatureString); return hmac.ComputeHash(buffer); } } }