345 lines
18 KiB
C#
345 lines
18 KiB
C#
using System;
|
||
using System.Data;
|
||
using System.Configuration;
|
||
using System.Web;
|
||
using System.Net;
|
||
using System.IO;
|
||
using System.Security.Cryptography;
|
||
using System.Xml;
|
||
using System.Collections.Specialized;
|
||
using System.Text.RegularExpressions;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
using System.Globalization;
|
||
using System.Web.Security;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
using System.Web.UI.WebControls.WebParts;
|
||
using System.Web.UI.HtmlControls;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.Web.Script.Serialization;
|
||
using TencentCloud.Common;
|
||
using TencentCloud.Common.Profile;
|
||
using TencentCloud.Vod.V20180717;
|
||
using TencentCloud.Vod.V20180717.Models;
|
||
namespace Mtxfw.shop
|
||
{
|
||
public partial class livetoken : System.Web.UI.Page
|
||
{
|
||
/// <summary>
|
||
/// 填写你申请的登录资料
|
||
/// </summary>
|
||
|
||
public Mtxfw.Utility.Config config = new Mtxfw.Utility.Config("");
|
||
public Mtxfw.DAL.Article daoArt = new Mtxfw.DAL.Article();
|
||
public Mtxfw.DAL.user_info daoUser = new Mtxfw.DAL.user_info();
|
||
DAL.user_live daolive = new DAL.user_live();
|
||
DAL.user_livefile daofile = new DAL.user_livefile();
|
||
public int gtype = 0;
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
string hostname = Request.Url.Host;
|
||
|
||
if (!IsPostBack)
|
||
{
|
||
Mtxfw.Utility.Common.WriteHtml("/weixin/response.txt", "dddddd");
|
||
if (!String.IsNullOrEmpty(Request.QueryString["action"]))
|
||
{
|
||
Mtxfw.Utility.Common.WriteHtml("/weixin/response1.txt", Request.QueryString["action"].ToString());
|
||
}
|
||
//以下为阿里云直播
|
||
/* if (!String.IsNullOrEmpty(Request.QueryString["action"]) && !String.IsNullOrEmpty(Request.QueryString["id"]))
|
||
{
|
||
string action = Request.QueryString["action"].ToString();
|
||
string usrargs = "";
|
||
if (!String.IsNullOrEmpty(Request.QueryString["usrargs"]))
|
||
{
|
||
usrargs = Request.QueryString["usrargs"].ToString();
|
||
}
|
||
string StreamName = Request.QueryString["id"].ToString();
|
||
int MemberId = Convert.ToInt32(StreamName.Replace("zb", ""));
|
||
Mtxfw.Utility.Common.WriteHtml("/weixin/response0.txt", action);
|
||
if (action == "publish")
|
||
{
|
||
Model.user_live lmodel = daolive.GetModelByMemberId(MemberId, 0);
|
||
if (lmodel != null)
|
||
{
|
||
lmodel.seef = 1;
|
||
daolive.Update(lmodel);
|
||
Response.Write("200");
|
||
}
|
||
}
|
||
else if (action == "publish_done")
|
||
{
|
||
Model.user_live lmodel = daolive.GetModelByMemberId(MemberId, 0);
|
||
if (lmodel != null)
|
||
{
|
||
if (lmodel.seef == 1)
|
||
{
|
||
lmodel.seef = 2;
|
||
daolive.Update(lmodel);
|
||
Response.Write("200");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (Request.GetBufferlessInputStream() != null)
|
||
{
|
||
StreamReader reader = new StreamReader(Request.GetBufferlessInputStream());
|
||
string response = reader.ReadToEnd();
|
||
Mtxfw.Utility.Common.WriteHtml("/weixin/response.txt", response);
|
||
if (response.IndexOf("start_time") != -1)
|
||
{
|
||
alilivefile ftoken = (alilivefile)FromfileJson(response);
|
||
Mtxfw.Model.user_livefile lmodel = new Model.user_livefile();
|
||
lmodel.MemberId = Convert.ToInt32(ftoken.stream.Replace("zb", ""));
|
||
lmodel.stream_id = ftoken.stream;
|
||
lmodel.channel_id = ftoken.app;
|
||
lmodel.file_id = "";
|
||
lmodel.file_format = "";
|
||
lmodel.start_time = ftoken.start_time;
|
||
lmodel.end_time = ftoken.stop_time;
|
||
lmodel.duration = Convert.ToInt64(ftoken.duration.Split('.')[0]);
|
||
lmodel.file_size = 0;
|
||
lmodel.stream_param = "";
|
||
lmodel.video_url = ftoken.uri;
|
||
lmodel.seef = 0;
|
||
lmodel.LinkID = 0;
|
||
lmodel.ttype = 0;
|
||
lmodel.addtime = DateTime.Now;
|
||
daofile.Add(lmodel);
|
||
}
|
||
}*/
|
||
//以下为腾讯云直播
|
||
if (Request.GetBufferlessInputStream() != null)
|
||
{
|
||
StreamReader reader = new StreamReader(Request.GetBufferlessInputStream());
|
||
string response = reader.ReadToEnd();
|
||
Mtxfw.Utility.Common.WriteHtml("/weixin/response.txt", response);
|
||
livetoken_type ltoken = (livetoken_type)FromJson(response);
|
||
string strsign = "";
|
||
MD5 md5 = new MD5CryptoServiceProvider();
|
||
string strkey = "ddd8967bdfb642e37d1da3e05ce9ead5" + ltoken.t;
|
||
StringBuilder sb = new StringBuilder(32);
|
||
byte[] t = md5.ComputeHash(Encoding.GetEncoding("utf-8").GetBytes(strkey));
|
||
for (int i = 0; i < t.Length; i++)
|
||
{
|
||
sb.Append(t[i].ToString("x").PadLeft(2, '0'));
|
||
}
|
||
Mtxfw.Utility.Common.WriteHtml("/weixin/responsesign.txt", sb.ToString() + "|" + ltoken.sign);
|
||
if (sb.ToString() == ltoken.sign)
|
||
{
|
||
if (ltoken.event_type == 1)
|
||
{
|
||
livestream_id ftoken = (livestream_id)FromJson0(response);
|
||
int liveid = Convert.ToInt32(ftoken.stream_id.Replace("zb", ""));
|
||
Model.user_live lmodel = daolive.GetModel(liveid);
|
||
if (lmodel != null)
|
||
{
|
||
|
||
lmodel.seef = 1;
|
||
daolive.Update(lmodel);
|
||
}
|
||
}
|
||
else if (ltoken.event_type == 0)
|
||
{
|
||
livestream_id ftoken = (livestream_id)FromJson0(response);
|
||
int liveid = Convert.ToInt32(ftoken.stream_id.Replace("zb", ""));
|
||
Model.user_live lmodel = daolive.GetModel(liveid);
|
||
if (lmodel != null)
|
||
{
|
||
if (lmodel.seef != 2 && lmodel.seef != 3 && lmodel.seef != 4)
|
||
{
|
||
lmodel.seef = 3;
|
||
lmodel.EndTime = DateTime.Now;
|
||
daolive.Update(lmodel);
|
||
Mtxfw.Model.Article model = new Mtxfw.Model.Article();
|
||
model.senderid = 0;
|
||
model.receiverid = lmodel.MemberId;
|
||
model.Title = "直播信息";
|
||
model.ParentID = 21;
|
||
model.CategoryId = lmodel.Id.ToString();
|
||
model.AddTime = DateTime.Now;
|
||
model.Author = "";
|
||
|
||
model.Content = "直播已结束";
|
||
model.Paths = "";
|
||
model.Content2 = "";
|
||
model.Paths2 = "";
|
||
model.KeyWords = "";
|
||
model.media_id = "";
|
||
model.thumb_media_id = "";
|
||
model.wtype = 0;
|
||
model.wtype2 = 0;
|
||
model.LinkID = 0;
|
||
model.Seef = 0;
|
||
model.gtype = gtype;
|
||
new DAL.Article().Add(model);
|
||
}
|
||
}
|
||
}
|
||
else if (ltoken.event_type == 100)
|
||
{
|
||
|
||
try
|
||
{
|
||
livetoken_file ftoken = (livetoken_file)FromJson1(response);
|
||
int liveid = Convert.ToInt32(ftoken.stream_id.Replace("zb", ""));
|
||
Model.user_live lmodel = daolive.GetModel(liveid);
|
||
if (lmodel != null)
|
||
{
|
||
System.Threading.Thread.Sleep(10);
|
||
|
||
Int64 width = 0, height = 0;
|
||
try
|
||
{
|
||
// 必要步骤:
|
||
// 实例化一个认证对象,入参需要传入腾讯云账户密钥对 SecretId,SecretKey。
|
||
// 本示例采用从环境变量读取的方式,则需要在环境变量中先设置这两个值。
|
||
// 您也可以直接将密钥对写入代码中,但是注意不要复制、上传或分享代码,以免泄露密钥对危及您的财产安全。
|
||
Credential cred = new Credential
|
||
{
|
||
SecretId = config.AccessKeyId,
|
||
SecretKey = config.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);
|
||
DescribeMediaInfosRequest req = new DescribeMediaInfosRequest();
|
||
req.FileIds[0] = ftoken.file_id;
|
||
req.Filters[0] = "metaData";
|
||
DescribeMediaInfosResponse res = client.DescribeMediaInfosSync(req);
|
||
// 输出 JSON 格式的字符串回包
|
||
Mtxfw.Utility.Common.WriteHtml("/weixin/DescribeMediaInfos0.txt", AbstractModel.ToJsonString(res) + "|" + res.RequestId);
|
||
|
||
|
||
|
||
if (res.MediaInfoSet[0].MetaData.Width != null)
|
||
{
|
||
width = Convert.ToInt64(res.MediaInfoSet[0].MetaData.Width);
|
||
}
|
||
if (res.MediaInfoSet[0].MetaData.Height != null)
|
||
{
|
||
height = Convert.ToInt64(res.MediaInfoSet[0].MetaData.Height);
|
||
}
|
||
}
|
||
catch (Exception err0)
|
||
{
|
||
Mtxfw.Utility.Common.WriteHtml("/weixin/responseerr0.txt", err0.ToString());
|
||
}
|
||
Mtxfw.Model.user_livefile fmodel = new Model.user_livefile();
|
||
fmodel.MemberId = lmodel.MemberId;
|
||
fmodel.liveid = lmodel.Id;
|
||
fmodel.stream_id = ftoken.stream_id;
|
||
fmodel.channel_id = ftoken.channel_id;
|
||
fmodel.file_id = ftoken.file_id;
|
||
fmodel.file_format = ftoken.file_format;
|
||
fmodel.start_time = ftoken.start_time;
|
||
fmodel.end_time = ftoken.end_time;
|
||
fmodel.duration = ftoken.duration;
|
||
fmodel.width = width;
|
||
fmodel.height = height;
|
||
fmodel.file_size = ftoken.file_size;
|
||
fmodel.stream_param = ftoken.stream_param;
|
||
fmodel.video_url = ftoken.video_url;
|
||
fmodel.seef = 0;
|
||
fmodel.LinkID = 0;
|
||
fmodel.ttype = 0;
|
||
fmodel.addtime = DateTime.Now;
|
||
fmodel.gtype = lmodel.gtype;
|
||
daofile.Add(fmodel);
|
||
}
|
||
}
|
||
catch (Exception err)
|
||
{
|
||
Mtxfw.Utility.Common.WriteHtml("/weixin/responseerr.txt", err.ToString());
|
||
}
|
||
}
|
||
Response.Write("{\"code\":0}");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
public object FromJson(string json)
|
||
{
|
||
JavaScriptSerializer js = new JavaScriptSerializer();
|
||
return js.Deserialize<livetoken_type>(json);
|
||
}
|
||
public object FromJson0(string json)
|
||
{
|
||
JavaScriptSerializer js = new JavaScriptSerializer();
|
||
return js.Deserialize<livestream_id>(json);
|
||
}
|
||
public object FromJson1(string json)
|
||
{
|
||
JavaScriptSerializer js = new JavaScriptSerializer();
|
||
return js.Deserialize<livetoken_file>(json);
|
||
}
|
||
public object FromfileJson(string json)
|
||
{
|
||
JavaScriptSerializer js = new JavaScriptSerializer();
|
||
return js.Deserialize<alilivefile>(json);
|
||
}
|
||
}
|
||
public class alilivefile
|
||
{
|
||
public String domain { get; set; }
|
||
public String app { get; set; }
|
||
public String stream { get; set; }
|
||
public String uri { get; set; }
|
||
public string duration { get; set; }
|
||
public Int64 start_time { get; set; }
|
||
public Int64 stop_time { get; set; }
|
||
}
|
||
public class livetoken_type
|
||
{
|
||
public int event_type { get; set; }
|
||
public String sign { get; set; }
|
||
public Int64 t { get; set; }
|
||
}
|
||
|
||
public class livestream_id
|
||
{
|
||
public string stream_id { get; set; }
|
||
}
|
||
public class livetoken_file
|
||
{
|
||
public int event_type { get; set; }
|
||
public string stream_id { get; set; }//直播流名称
|
||
public string channel_id { get; set; }//同直播流名称
|
||
public string file_id { get; set; }//点播 file ID,在点播平台可以唯一定位一个点播视频文件
|
||
public string file_format { get; set; }//flv,hls,mp4,aac
|
||
public Int64 start_time { get; set; }//录制文件起始时间戳
|
||
public Int64 end_time { get; set; }//录制文件结束时间戳
|
||
public Int64 duration { get; set; }//录制文件时长,单位秒
|
||
public UInt64 file_size { get; set; }//录制文件大小,单位字节
|
||
public string stream_param { get; set; }//用户推流 URL 所带参数
|
||
public string video_url { get; set; }//录制文件文件下载 URL
|
||
public String sign { get; set; }
|
||
public Int64 t { get; set; }
|
||
}
|
||
|
||
} |