Ejemplo n.º 1
0
        /// <summary>
        /// 腾讯云接口 Get 请求
        /// </summary>
        /// <param name="serviceName">接口服务名称</param>
        /// <param name="hostName">接口请求域名</param>
        /// <param name="queryString">url参数</param>
        /// <param name="api">请求url</param>
        /// <param name="action">接口action</param>
        /// <param name="version">接口version</param>
        /// <param name="requestPayload">请求参数</param>
        /// <typeparam name="T">响应参数</typeparam>
        /// <returns></returns>
        public static async Task <T> TCGetRequst <T>(string serviceName, string hostName,
                                                     string queryString, string api, string action, string version,
                                                     string requestPayload = "")
        {
            //请求公共参数
            var timespan = Time.GetUnixTimestamp();

            //生成签名串
            var authorization = SignV3.CreateAuthorizationSignV3(serviceName, hostName,
                                                                 "GET", queryString, "", timespan);

            //初始化restClient
            var client  = new RestClient(api);
            var request = new RestRequest(method: Method.GET);

            //设置请求头公共参数
            request.AddHeader("Host", hostName);
            request.AddHeader("X-TC-Action", action);
            request.AddHeader("X-TC-RequestClient", "APIExplorer");
            request.AddHeader("X-TC-Timestamp", timespan.ToString());
            request.AddHeader("X-TC-Version", version);
            request.AddHeader("X-TC-Region", BaseTencentConfig.REGION);
            request.AddHeader("X-TC-Language", "zh-CN");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddHeader("Authorization", authorization);
            //发起请求
            var response = await client.ExecuteAsync(request);

            var responseData = JsonConvert.DeserializeObject <T>(response.Content);

            return(responseData);
        }
Ejemplo n.º 2
0
        public static async Task <BaseTencentRespnse> VodPullUploadAsync(VodPullUploadRequest dto)
        {
            var _baseApi = "https://vod.tencentcloudapi.com/";
            var action   = "PullUpload"; //公共参数,本接口取值:PullUpload。
            var version  = "2018-07-17"; //公共参数,本接口取值:2018-07-17。

            //组装url
            var api = new StringBuilder()
                      .Append($"{_baseApi}?")
                      .Append($"MediaUrl={ Format.UrlEncode(dto.MediaUrl)}")
                      .Append($"&MediaName={dto.MediaName}")
                      .Append($"&Procedure={VodConfig.ShortVideoProcedure}")
                      .Append($"&ClassId={VodConfig.ShortVideoClassId}")
                      .ToString();

            //请求公共参数
            var timespan = Time.GetUnixTimestamp();

            //生成签名串
            var authorization = SignV3.CreateAuthorizationSignV3("vod", "vod.tencentcloudapi.com",
                                                                 "GET", api.Split("?")[1], JsonConvert.SerializeObject(dto), timespan);

            //初始化restClient
            var client  = new RestClient(api);
            var request = new RestRequest(method: Method.GET);

            //设置请求头公共参数
            request.AddHeader("Host", "vod.tencentcloudapi.com");
            request.AddHeader("X-TC-Action", action);
            request.AddHeader("X-TC-RequestClient", "APIExplorer");
            request.AddHeader("X-TC-Timestamp", timespan.ToString());
            request.AddHeader("X-TC-Version", version);
            request.AddHeader("X-TC-Region", VodConfig.REGION);
            request.AddHeader("X-TC-Language", "zh-CN");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddHeader("Authorization", authorization);

            //发起请求
            var response = await client.ExecuteAsync(request);

            var responseData = JsonConvert.DeserializeObject <BaseTencentRespnse>(response.Content);

            return(responseData);
        }