Пример #1
0
        private void Button_Hotlink_Click(object sender, RoutedEventArgs e)
        {
            if (!TryInit())
            {
                return;
            }

            string host   = TextBox_FusionHotlinkHost.Text.Trim();
            string path   = TextBox_FusionHotlinkPath.Text.Trim();
            string file   = TextBox_FusionHotlinkFile.Text.Trim();
            string query  = TextBox_FusionHotlinkQuery.Text.Trim();
            string expire = TextBox_FusionHotlinkExpire.Text.Trim();
            string key    = TextBox_FusionHotlinkQiniuKey.Text.Trim();

            if (string.IsNullOrEmpty(host))
            {
                TextBox_FusionHotLinkText.Text = "请填写host";
                return;
            }

            if (string.IsNullOrEmpty(expire))
            {
                expire = "3600";
                TextBox_FusionHotlinkExpire.Text = expire;
            }

            var request = new TimestampAntiLeechUrlRequest();

            request.Host      = host;
            request.Path      = path;
            request.File      = file;
            request.Query     = query;
            request.Timestamp = UnixTimestamp.GetUnixTimestamp(long.Parse(expire)).ToString();
            request.Key       = key;

            string rawUrl = host + path + file + query;

            if (!UrlHelper.IsValidUrl(rawUrl))
            {
                TextBox_FusionHotLinkText.Text = string.Format("不符合格式的URL: {0}", rawUrl);
                return;
            }

            if (string.IsNullOrEmpty(key))
            {
                TextBox_FusionHotLinkText.Text = string.Format("请填写key");
                return;
            }

            var result = cdnManager.CreateTimestampAntiLeechUrl(request);

            TextBox_FusionHotLinkText.Text = result;
        }
Пример #2
0
        /// <summary>
        /// 时间戳防盗链
        /// </summary>
        /// <param name="host">主机,如http://domain.com</param>
        /// <param name="path">路径,如/dir1/dir2/</param>
        /// <param name="fileName">文件名,如1.jpg</param>
        /// <param name="query">请求参数,如?v=1.1</param>
        /// <param name="encryptKey">后台提供的key</param>
        /// <param name="expireInSeconds">链接有效时长</param>
        /// <returns>时间戳防盗链接</returns>
        public string CreateTimestampAntiLeechUrl(string host, string path, string fileName, string query, string encryptKey, int expireInSeconds)
        {
            TimestampAntiLeechUrlRequest request = new TimestampAntiLeechUrlRequest();

            request.Host  = host;
            request.Path  = path;
            request.File  = fileName;
            request.Query = query;
            request.Key   = encryptKey;
            request.SetLinkExpire(expireInSeconds);

            return(CreateTimestampAntiLeechUrl(request));
        }
Пример #3
0
        public void CreateAnitleechUrlTest()
        {
            Mac        mac    = new Mac(AccessKey, SecretKey);
            CdnManager target = new CdnManager(mac);

            string qiniuKey        = "12345678";
            int    expireInSeconds = 600;

            TimestampAntiLeechUrlRequest req = new TimestampAntiLeechUrlRequest(TestURL2, qiniuKey, expireInSeconds);

            string result = target.CreateTimestampAntiLeechUrl(req);

            Assert.IsNotNull(result);
        }
Пример #4
0
        /// <summary>
        /// 时间戳防盗链
        /// 另请参阅https://support.qiniu.com/question/195128
        /// </summary>
        /// <param name="request">“时间戳防盗链”请求,详情请参阅该类型的说明</param>
        /// <returns>时间戳防盗链接</returns>
        public string CreateTimestampAntiLeechUrl(TimestampAntiLeechUrlRequest request)
        {
            string RAW = request.RawUrl;

            string key   = request.Key;
            string path  = Uri.EscapeUriString(request.Path);
            string file  = request.File;
            string query = request.Query;
            string ts    = (long.Parse(request.Timestamp)).ToString("x");
            string SIGN  = Hashing.CalcMD5X(key + path + file + ts);
            string LEAD  = query + "&";

            if (string.IsNullOrEmpty(query))
            {
                LEAD = "?";
            }

            return(string.Format("{0}{1}sign={2}&t={3}", RAW, LEAD, SIGN, ts));
        }
Пример #5
0
        /// <summary>
        /// 时间戳防盗链
        /// </summary>
        public void hotLink()
        {
            Mac        mac       = new Mac(Settings.AccessKey, Settings.SecretKey);
            CdnManager fusionMgr = new CdnManager(mac);

            TimestampAntiLeechUrlRequest request = new TimestampAntiLeechUrlRequest();

            request.Host  = "http://your-host";
            request.Path  = "/path/";
            request.File  = "file-name";
            request.Query = "?version=1.1";
            request.SetLinkExpire(600);

            //request.RawUrl

            string prefLink = fusionMgr.CreateTimestampAntiLeechUrl(request);

            Console.WriteLine(prefLink);
        }