web端利用騰訊雲點播接口上傳視頻

騰訊雲web上傳文件文檔

https://cloud.tencent.com/document/product/266/9239#.E5.B8.B8.E8.A7.81.E9.97.AE.E9.A2.98

sdk:https://github.com/tencentyun/vod-js-sdk-v6

根據文檔下載sdk或參考sdk即可

前端源代碼地址 https://github.com/tencentyun/vod-js-sdk-v6/blob/master/docs/index.html

注意,前端獲取簽名的地址要改成自己後臺的簽名生成地址

在視頻上傳成功裏面加入自己的邏輯

 

 

c# 簽名代碼 

簽名規範及參數文檔 https://cloud.tencent.com/document/product/266/9221 

 /// <summary>
    /// 獲取web端上傳視頻簽名   https://cloud.tencent.com/document/product/266/9219
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private string TencentGetUploadSign(HttpContext context)
    {
        try
        {
            //調用方法
            Signature sign = new Signature();
            sign.m_strSecId = "AKIDkOODn9PJ2b2LWUQDxRl25xfVEk25qfLN";
            sign.m_strSecKey = "QSI5erqb7QUOK5KrEQ62lKfXGXayAC0b";
            sign.m_qwNowTime = Signature.GetIntTimeStamp();
            sign.m_iRandom = new Random().Next(0, 1000000);
            sign.m_iSignValidDuration = 3600 * 24 * 2;
            string signStr = sign.GetUploadSignature();
            //根據自己系統的規範返回
            return ReturnJson.AjaxJsonByDt(true, "", signStr);
        }
        catch (Exception ex)
        {
            LogHelper.WriteErrorLog(ex.ToString(), "APIError", "Live");
            return ReturnJson.AjaxJsonByDt(false, ex.Message, "");
        }
    }  





public class Signature
    {
        public string m_strSecId;
        public string m_strSecKey;
        public int m_iRandom;
        public long m_qwNowTime;
        public int m_iSignValidDuration;
        public static long GetIntTimeStamp()
        {
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1);
            return Convert.ToInt64(ts.TotalSeconds);
        }
        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);
        }
        public string GetUploadSignature()
        {
            string strContent = "";
            strContent += ("secretId=" + Uri.EscapeDataString((m_strSecId)));
            strContent += ("&currentTimeStamp=" + m_qwNowTime);
            strContent += ("&expireTime=" + (m_qwNowTime + m_iSignValidDuration));
            strContent += ("&random=" + m_iRandom);
            byte[] bytesSign = hash_hmac_byte(strContent, m_strSecKey);
            byte[] byteContent = System.Text.Encoding.Default.GetBytes(strContent);
            byte[] nCon = new byte[bytesSign.Length + byteContent.Length];
            bytesSign.CopyTo(nCon, 0);
            byteContent.CopyTo(nCon, bytesSign.Length);
            return Convert.ToBase64String(nCon);
        }
    }

注意 :

添加簽名其他參數時,其他參數要UrlEncode,  比如加轉碼時

procedure= HttpUtility.UrlEncode("轉碼任務流");

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章