Skip to content

Commit

Permalink
perf: prepares TencentSigning for other services
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry23011 committed Dec 3, 2023
1 parent cde888f commit 9b3fb23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion Easydict/Feature/Service/Tencent/TencentService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions Easydict/Feature/Service/Tencent/TencentSigning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9b3fb23

Please sign in to comment.