Files
g.hnyhua.cn/Mtxfw.VipSite/Admin_Member_video_add.aspx.cs

302 lines
16 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;
/*using TencentCloud.Common;
using TencentCloud.Common.Profile;
using TencentCloud.Vod.V20180717;
using TencentCloud.Vod.V20180717.Models;
using COSXML;
using COSXML.Auth;
using COSXML.Model.Object;*/
namespace Mtxfw.VipSite
{
public partial class Admin_Member_video_add : Mtxfw.Utility.MemberBase
{
public Mtxfw.Utility.Config cconfig = new Mtxfw.Utility.Config("");
public Mtxfw.DAL.Article daoArt = new Mtxfw.DAL.Article();
public String strTitle = "",strBody = "", VodSessionKey="", Signature = "";
public int gtype = 0;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
string hostname = Request.Url.Host;
string secretId = cconfig.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 + "&currentTimeStamp=" + currentTimeStamp + "&expireTime=" + expireTime + "&random=" + random + "&classId=" + classId + "&storageRegion=ap-beijing";
byte[] bytesSign = hash_hmac_byte(strkey, cconfig.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_video.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)
{
Mtxfw.Model.Article model = new Mtxfw.Model.Article();
model.senderid = 0;
model.receiverid = 0;
model.Title = Text_Title.Text;
model.ParentID = 29;
model.CategoryId = "0";//DropType.SelectedItem.Value
model.AddTime = DateTime.Now;
Mtxfw.Utility.UploadFile upload = new Utility.UploadFile(File_AdsImg.PostedFile, cconfig.webUpPath, cconfig.webUpType, int.Parse(cconfig.webUpSize));
if (File_AdsImg.FileName.Length > 0)
{
upload.StatrUpFile();
model.Author = upload.UploadPath;
}
else model.Author = Hidd_Img.Value;
model.Content = "";
model.Paths = hidden_video.Value;
model.Content2 = "";
model.Paths2 = file_id.Value;
model.KeyWords = "";
model.media_id = "";
model.thumb_media_id = "";
model.wtype = 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 = 0;
model.gtype = gtype;
model.id = daoArt.Add(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 = gtype;
new DAL.User_CZ_log().Add(logmodel);
/*try
{
//初始化 CosXmlConfig
string appid = "1301659355";//设置腾讯云账户的账户标识 APPID
string region = "upload-1301659355"; //设置一个默认的存储桶地域
CosXmlConfig config = new CosXmlConfig.Builder()
.SetConnectionTimeoutMs(60000) //设置连接超时时间单位毫秒默认45000ms
.SetReadWriteTimeoutMs(40000) //设置读写超时时间单位毫秒默认45000ms
.IsHttps(true) //设置默认 HTTPS 请求
.SetAppid(appid) //设置腾讯云账户的账户标识 APPID
.SetRegion(region) //设置一个默认的存储桶地域
.SetDebugLog(true) //显示日志
.Build(); //创建 CosXmlConfig 对象
//初始化 QCloudCredentialProviderCOS SDK 中提供了3种方式永久密钥、临时密钥、自定义
QCloudCredentialProvider cosCredentialProvider = null;
//方式1 永久密钥
string secretId = cconfig.AccessKeyId; //"云 API 密钥 SecretId";
string secretKey = cconfig.AccessKeySecret; //"云 API 密钥 SecretKey";
long durationSecond = 600; //每次请求签名有效时长,单位为秒
cosCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond);
CosXml cosXml = new CosXmlServer(config, cosCredentialProvider);
int ift = 0;
try
{
string bucket = "upload-1301659355"; //存储桶格式BucketName-APPID
string key = "exampleobject"; //对象在存储桶中的位置,即称对象键
string srcPath = Server.MapPath(model.Paths);//本地文件绝对路径
PutObjectRequest request = new PutObjectRequest(bucket, key, srcPath);
//设置签名有效时长
request.SetSign(COSXML.Utils.TimeUtils.GetCurrentTime(COSXML.Utils.TimeUnit.SECONDS), 600);
//设置进度回调
request.SetCosProgressCallback(delegate (long completed, long total)
{
cconfig.webMoney57 = (completed * 100.0 / total).ToString();
//context.Response.Write(String.Format("progress={0:##.##}%", completed * 100.0 / total));
if (completed >= total && ift == 0)
{
ift = 1;
// 必要步骤:
// 实例化一个认证对象,入参需要传入腾讯云账户密钥对 SecretIdSecretKey。
// 本示例采用从环境变量读取的方式,则需要在环境变量中先设置这两个值。
// 您也可以直接将密钥对写入代码中,但是注意不要复制、上传或分享代码,以免泄露密钥对危及您的财产安全。
Credential cred = new Credential
{
SecretId = cconfig.AccessKeyId,
SecretKey = cconfig.AccessKeySecret
};
// 实例化一个 client 选项,可选的,没有特殊需求可以跳过
ClientProfile clientProfile = new ClientProfile();
// 指定签名算法(默认为 HmacSHA256
clientProfile.SignMethod = ClientProfile.SIGN_SHA1;
// 非必要步骤
// 实例化一个客户端配置对象,可以指定超时时间等配置
HttpProfile httpProfile = new HttpProfile();
// SDK 默认使用 POST 方法。
// 如果您一定要使用 GET 方法可以在这里设置。GET 方法无法处理一些较大的请求。
httpProfile.ReqMethod = "POST";
// SDK 有默认的超时时间,非必要请不要进行调整。
// 如有需要请在代码中查阅以获取最新的默认值。
httpProfile.Timeout = 30; // 请求连接超时时间单位为秒默认值为60
// SDK 会自动指定域名。通常无需指定域名,但如果您访问的是金融区的服务,则必须手动指定域名。
// 例如云服务器的上海金融区域名cvm.ap-shanghai-fsi.tencentcloudapi.com
// 代理服务器,当您的环境下有代理服务器时设定
httpProfile.WebProxy = Environment.GetEnvironmentVariable("HTTPS_PROXY");
clientProfile.HttpProfile = httpProfile;
// 实例化要请求产品(以 CVM 为例)的 client 对象
// 第二个参数是地域信息,可以直接填写字符串 ap-guangzhou或者引用预设的常量clientProfile 是可选的
VodClient client = new VodClient(cred, "ap-beijing", clientProfile);
ApplyUploadRequest req = new ApplyUploadRequest();
req.MediaType = "MP4";
req.ClassId = 659337;
ApplyUploadResponse res = client.ApplyUploadSync(req);
// 输出 JSON 格式的字符串回包
Mtxfw.Utility.Common.WriteHtml("/weixin/TencentCloud.txt", AbstractModel.ToJsonString(res) + "|" + res.VodSessionKey);
CommitUploadRequest req0 = new CommitUploadRequest();
req0.VodSessionKey = res.VodSessionKey;
CommitUploadResponse res0 = client.CommitUploadSync(req0);
model.Paths = res0.MediaUrl;
daoArt.Update(model);
// 输出 JSON 格式的字符串回包
Mtxfw.Utility.Common.WriteHtml("/weixin/TencentCloud0.txt", AbstractModel.ToJsonString(res0) + "|" + res0.MediaUrl);
}
});
//执行请求
PutObjectResult result = cosXml.PutObject(request);
//对象的 eTag
string eTag = result.eTag;
}
catch (COSXML.CosException.CosClientException clientEx)
{
//请求失败
Mtxfw.Utility.Common.WriteHtml("/weixin/TencentClouderr2.txt", clientEx.Message);
//context.Response.Write("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
//请求失败
Mtxfw.Utility.Common.WriteHtml("/weixin/TencentClouderr1.txt", serverEx.GetInfo());
//context.Response.Write("CosServerException: " + serverEx.GetInfo());
}
}
catch (Exception err)
{
Mtxfw.Utility.Common.WriteHtml("/weixin/TencentClouderr0.txt", err.ToString());
Response.Write(err.Message);
}*/
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('添加视频成功!');location.replace('" + Hidd_Url.Value + "')</script>");
};
Btn_Update.Click += delegate(object s, EventArgs ex)
{
Int32 ID = int.Parse(Request.QueryString["ID"]);
Mtxfw.Model.Article model = daoArt.GetModel(ID);
model.Title = Text_Title.Text;
Mtxfw.Utility.UploadFile upload = new Utility.UploadFile(File_AdsImg.PostedFile, cconfig.webUpPath, cconfig.webUpType, int.Parse(cconfig.webUpSize));
if (File_AdsImg.FileName.Length > 0)
{
upload.StatrUpFile();
model.Author = upload.UploadPath;
}
else model.Author = Hidd_Img.Value;
model.Paths = hidden_video.Value;
model.Paths2 = file_id.Value;
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 = gtype;
new DAL.User_CZ_log().Add(logmodel);
ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('更新推荐视频成功!');location.replace('" + Hidd_Url.Value + "')</script>");
};
}
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);
}
protected void Data_Bind()
{
if (Request.UrlReferrer != null)
{
Hidd_Url.Value = Request.UrlReferrer.ToString();
}
else
{
Hidd_Url.Value = "Admin_Member_video.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;
hidden_video.Value = model.Paths;
file_id.Value = model.Paths2;
if (!String.IsNullOrEmpty(model.Author))
{
Img_Img.Visible = true;
Img_Img.Src = Mtxfw.Utility.Common.GetCoverPic(model.Author, "40x40", cconfig.webImgMode);
Hidd_Img.Value = model.Author;
}
else
{
Img_Img.Visible = false;
Hidd_Img.Value = String.Empty;
}
}
}
}
}
}