class TencentCloud::Common::AbstractClient
def build_req_with_v3_signature(action, params, req, options = {})
def build_req_with_v3_signature(action, params, req, options = {}) content_type = req.method == 'GET' ? FORM_URLENCODED_CONTENT : JSON_CONTENT content_type = MULTIPART_CONTENT if options['IsMultipart'] timestamp = Time.now.to_i req.header['Content-Type'] = content_type req.header['Host'] = endpoint req.header['X-TC-Action'] = action req.header['X-TC-Timestamp'] = timestamp req.header['X-TC-Version'] = @api_version req.header['X-TC-Region'] = @region req.header['X-TC-Language'] = @profile.language req.header['X-TC-Token'] = @credential.token if @credential.token req.header['X-TC-Content-SHA256'] = 'UNSIGNED-PAYLOAD' if @profile.unsigned_payload if req.method == 'GET' params = AbstractModel.format_params(nil, params) req.data = URI.encode_www_form(params) canonical_querystring = req.data payload = '' else case content_type when JSON_CONTENT req.data = JSON.generate(params, { 'ascii_only' => true, 'space' => ' ' }) when MULTIPART_CONTENT binparas = options['binparas'] || [] boundary = SecureRandom.hex req.header['Content-Type'] += '; boundary=' + boundary body = '' params.each do |k, v| body += "--#{boundary}\r\n" body += "Content-Disposition: form-data; name=\"#{k}\"" if binparas.include? k body += "; filename=\"File\"\r\n" else body += "\r\n" if v.is_a?(Array) || v.is_a?(Hash) v = JSON.generate(v, { 'ascii_only' => true, 'space' => ' ' }) body += "Content-Type: application/json\r\n" end end body += "\r\n#{v}\r\n" end body += "--#{boundary}--\r\n" unless body.empty? req.data = body # req.is_multipart = options['IsMultipart'] else raise TencentCloudSDKException.new('ContentTypeError', "Unsupported content type: #{content_type}") end payload = req.data canonical_querystring = '' end payload = 'UNSIGNED-PAYLOAD' if @profile.unsigned_payload hashed_payload = Digest::SHA256.hexdigest(payload) authorization = Sign.sign_v3(content_type, endpoint, @profile.http_profile.req_method, req.uri, canonical_querystring, hashed_payload, req.header['X-TC-Timestamp'], @credential.secret_id, @credential.secret_key) req.header['Authorization'] = authorization end