diff --git a/Easydict/Feature/Service/Model/EZConstKey.h b/Easydict/Feature/Service/Model/EZConstKey.h index 0f041f01a..c5fe96a54 100644 --- a/Easydict/Feature/Service/Model/EZConstKey.h +++ b/Easydict/Feature/Service/Model/EZConstKey.h @@ -32,8 +32,8 @@ static NSString *const EZDeepLAuthKey = @"EZDeepLAuthKey"; static NSString *const EZBingCookieKey = @"EZBingCookieKey"; static NSString *const EZNiuTransAPIKey = @"EZNiuTransAPIKey"; static NSString *const EZCaiyunToken = @"EZCaiyunToken"; -//static NSString *const EZTencentSecretId = @"EZTencentSecretId"; -//static NSString *const EZTencentSecretKey = @"EZTencentSecretKey"; +static NSString *const EZTencentSecretId = @"EZTencentSecretId"; +static NSString *const EZTencentSecretKey = @"EZTencentSecretKey"; @interface EZConstKey : NSObject diff --git a/Easydict/Feature/Service/Tencent/TencentService.swift b/Easydict/Feature/Service/Tencent/TencentService.swift index 08a78511d..37b394685 100644 --- a/Easydict/Feature/Service/Tencent/TencentService.swift +++ b/Easydict/Feature/Service/Tencent/TencentService.swift @@ -40,27 +40,28 @@ public final class TencentService: QueryService { //MARK: API Request -//TODO: Implement user SecretId/SecretKey -// private static let defaultSecretId = "" -// private static let defaultSecretKey = "" -// -// private var secretId: String { -// let secretId = UserDefaults.standard.string(forKey: EZTencentSecretId) -// if let secretId, !secretId.isEmpty { -// return secretId -// } else { -// return TencentService.defaultSecretId -// } -// } -// -// private var secretKey: String { -// let secretKey = UserDefaults.standard.string(forKey: EZTencentSecretKey) -// if let secretKey, !secretKey.isEmpty { -// return secretKey -// } else { -// return TencentService.defaultSecretKey -// } -// } + private static let defaultSecretId = "" + private static let defaultSecretKey = "" + + // easydict://writeKeyValue?EZTencentSecretId=xxx + private var secretId: String { + let secretId = UserDefaults.standard.string(forKey: EZTencentSecretId) + if let secretId, !secretId.isEmpty { + return secretId + } else { + return TencentService.defaultSecretId + } + } + + // easydict://writeKeyValue?EZTencentSecretKey=xxx + private var secretKey: String { + let secretKey = UserDefaults.standard.string(forKey: EZTencentSecretKey) + if let secretKey, !secretKey.isEmpty { + return secretKey + } else { + return TencentService.defaultSecretKey + } + } public override func translate(_ text: String, from: Language, to: Language, completion: @escaping (EZQueryResult, Error?) -> Void) { if prehandleQueryTextLanguage(text, autoConvertChineseText: false, from: from, to: to, completion: completion) { @@ -90,14 +91,6 @@ public final class TencentService: QueryService { return digest.compactMap{String(format: "%02x", $0)}.joined() } - // 密钥参数 - // 需要设置环境变量 TENCENTCLOUD_SECRET_ID,值为示例的 AKIDz8krbsJ5yKBZQpn74WFkmLPx3******* - //let secretId = ProcessInfo.processInfo.environment["TENCENTCLOUD_SECRET_ID"] - let secretId = "" - // 需要设置环境变量 TENCENTCLOUD_SECRET_KEY,值为示例的 Gu5t9xGARNpq86cd98joQYCN3******* - //let secretKey = ProcessInfo.processInfo.environment["TENCENTCLOUD_SECRET_KEY"] - let secretKey = "" - let service = "tmt" let host = "tmt.tencentcloudapi.com" let endpoint = "https://\(host)" diff --git a/Easydict/Feature/Utility/EZLinkParser/EZSchemeParser.m b/Easydict/Feature/Utility/EZLinkParser/EZSchemeParser.m index 0c8d8b86f..cfcd9f8fc 100644 --- a/Easydict/Feature/Utility/EZLinkParser/EZSchemeParser.m +++ b/Easydict/Feature/Utility/EZLinkParser/EZSchemeParser.m @@ -205,6 +205,8 @@ - (NSArray *)allowedReadWriteKeys { EZDeepLTranslationAPIKey, EZNiuTransAPIKey, EZCaiyunToken, + EZTencentSecretId, + EZTencentSecretKey, EZBingCookieKey, EZIntelligentQueryModeKey,