diff --git a/Easydict/Feature/Service/Tencent/TencentService.swift b/Easydict/Feature/Service/Tencent/TencentService.swift index 0694aa0b8..829f9431d 100644 --- a/Easydict/Feature/Service/Tencent/TencentService.swift +++ b/Easydict/Feature/Service/Tencent/TencentService.swift @@ -92,7 +92,12 @@ public final class TencentService: QueryService { ] let endpoint = "https://tmt.tencentcloudapi.com" - let headers = tencentSignHeader(parameters: parameters, secretId: secretId, secretKey: secretKey) + + let service = "tmt" + let action = "TextTranslate" + let version = "2018-03-21" + + let headers = tencentSignHeader(service: service, action: action, version: version, parameters: parameters, secretId: secretId, secretKey: secretKey) let request = AF.request(endpoint, method: .post, diff --git a/Easydict/Feature/Service/Tencent/TencentSigning.swift b/Easydict/Feature/Service/Tencent/TencentSigning.swift index b77cb80df..071b0191f 100644 --- a/Easydict/Feature/Service/Tencent/TencentSigning.swift +++ b/Easydict/Feature/Service/Tencent/TencentSigning.swift @@ -11,12 +11,12 @@ import Alamofire import CryptoKit // Tencent sigh header, Ref: https://github.com/TencentCloud/signature-process-demo/blob/main/signature-v3/swift/signv3.swift -func tencentSignHeader(parameters: [String: Any], secretId: String, secretKey: String) -> HTTPHeaders { - let service = "tmt" - let host = "tmt.tencentcloudapi.com" +func tencentSignHeader(service: String, action: String, version: String, parameters: [String: Any], secretId: String, secretKey: String) -> HTTPHeaders { + let service = service + let host = "\(service).tencentcloudapi.com" let region = "ap-guangzhou" - let action = "TextTranslate" - let version = "2018-03-21" + let action = action + let version = version let algorithm = "TC3-HMAC-SHA256" let timestamp = Int(Date().timeIntervalSince1970) let dateFormatter = DateFormatter()