156 lines
5.5 KiB
C#
156 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Collections;
|
|
using System.Data;
|
|
using System.Net;
|
|
using System.Net.Mail;
|
|
using System.Configuration;
|
|
using System.Globalization;
|
|
using Wuqi.Webdiyer;
|
|
using System.Web;
|
|
using System.Web.Security;
|
|
using System.Security.Cryptography;
|
|
using Excel = Microsoft.Office.Interop.Excel;
|
|
using System.Security.Cryptography;
|
|
using System.Text.RegularExpressions;
|
|
using System.Management;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.Linq;
|
|
using System.Web.Script.Serialization;
|
|
using System.Threading.Tasks;
|
|
using Shell32;
|
|
namespace Mtxfw.Utility
|
|
{
|
|
public class alilive
|
|
{
|
|
|
|
#region 返回公共请求参数
|
|
public string Version = "2016-11-01";
|
|
public string SignatureMethod = "HMAC-SHA1";
|
|
public string SignatureVersion = "1.0";
|
|
public string ResourceOwnerAccount = "fyd168882017";
|
|
public string Format = "JSON";
|
|
|
|
public string AppName = "agapp";
|
|
/// <summary>
|
|
/// 添加直播拉流配置信息
|
|
/// </summary>
|
|
/// <returns>RequestId</returns>
|
|
public returnRequestId AddLivePullStreamInfoConfig(Config config, DateTime dt, string StreamName)
|
|
{
|
|
SortedDictionary<string, string> dic = new SortedDictionary<string, string>();
|
|
dic.Add("Action", "AddLivePullStreamInfoConfig");
|
|
dic.Add("AppName", AppName);
|
|
dic.Add("DomainName", config.weblivedomain);
|
|
dic.Add("StartTime", dt.ToString("yyyy-MM-ddTHH:mm:ssZ"));
|
|
dic.Add("EndTime", dt.AddDays(1).ToString("yyyy-MM-ddTHH:mm:ssZ"));
|
|
dic.Add("SourceUrl", config.weblivedomain);
|
|
dic.Add("StreamName", StreamName);
|
|
dic.Add("RegionId", "");
|
|
dic.Add("Version", Version);
|
|
dic.Add("AccessKeyId", config.AccessKeyId);
|
|
dic.Add("SignatureMethod", SignatureMethod);
|
|
dic.Add("Timestamp", dt.ToString("yyyy-MM-ddTHH:mm:ssZ"));
|
|
dic.Add("SignatureVersion", SignatureVersion);
|
|
dic.Add("SignatureNonce", new Guid().ToString());
|
|
dic.Add("ResourceOwnerAccount", ResourceOwnerAccount);
|
|
dic.Add("Format", Format);
|
|
string Signature = BuildRequest(dic, config.AccessKeySecret);
|
|
dic.Add("Signature", Signature);
|
|
//获取过滤后的数组
|
|
Dictionary<string, string> dicPara = new Dictionary<string, string>();
|
|
dicPara = FilterPara(dic);
|
|
string LinkString = CreateLinkString(dicPara);
|
|
Mtxfw.Utility.Common.WriteHtml("/weixin/LinkString.txt", LinkString);
|
|
returnRequestId r = new returnRequestId();
|
|
return r;
|
|
}
|
|
|
|
public static string BuildRequest(SortedDictionary<string, string> sParaTemp, string AccessKeySecret)
|
|
{
|
|
//获取过滤后的数组
|
|
Dictionary<string, string> dicPara = new Dictionary<string, string>();
|
|
dicPara = FilterPara(sParaTemp);
|
|
|
|
//组合参数数组
|
|
string prestr = CreateLinkString(dicPara)+ "&key=" + AccessKeySecret;
|
|
|
|
|
|
//获得加密结果
|
|
string myMd5Str = Sha1Sign(prestr, Encoding.UTF8);
|
|
|
|
//返回转换为大写的加密串
|
|
return myMd5Str.ToUpper();
|
|
}
|
|
/// <summary>
|
|
/// 除去数组中的空值和签名参数并以字母a到z的顺序排序
|
|
/// </summary>
|
|
/// <param name="dicArrayPre">过滤前的参数组</param>
|
|
/// <returns>过滤后的参数组</returns>
|
|
public static Dictionary<string, string> FilterPara(SortedDictionary<string, string> dicArrayPre)
|
|
{
|
|
Dictionary<string, string> dicArray = new Dictionary<string, string>();
|
|
foreach (KeyValuePair<string, string> temp in dicArrayPre)
|
|
{
|
|
if (!string.IsNullOrEmpty(temp.Value))
|
|
{
|
|
dicArray.Add(temp.Key, temp.Value);
|
|
}
|
|
}
|
|
|
|
return dicArray;
|
|
}
|
|
//组合参数数组
|
|
public static string CreateLinkString(Dictionary<string, string> dicArray)
|
|
{
|
|
StringBuilder prestr = new StringBuilder();
|
|
foreach (KeyValuePair<string, string> temp in dicArray)
|
|
{
|
|
prestr.Append(temp.Key + "=" + temp.Value + "&");
|
|
}
|
|
|
|
int nLen = prestr.Length;
|
|
prestr.Remove(nLen - 1, 1);
|
|
|
|
return prestr.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// SHA1加密
|
|
/// </summary>
|
|
/// <param name="content">待加密的字符串</param>
|
|
/// <param name="encode">编码方式</param>
|
|
/// <returns></returns>
|
|
public static String Sha1Sign(String content, Encoding encode)
|
|
{
|
|
try
|
|
{
|
|
SHA1 sha1 = new SHA1CryptoServiceProvider();//创建SHA1对象
|
|
byte[] bytes_in = encode.GetBytes(content);//将待加密字符串转为byte类型
|
|
byte[] bytes_out = sha1.ComputeHash(bytes_in);//Hash运算
|
|
sha1.Dispose();//释放当前实例使用的所有资源
|
|
String result = BitConverter.ToString(bytes_out);//将运算结果转为string类型
|
|
result = result.Replace("-", "").ToUpper();
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ex.Message;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
|
|
public class returnRequestId
|
|
{
|
|
public String RequestId { get; set; }
|
|
}
|
|
|
|
}
|