iOS SDK API
GTCaptcha4SessionTaskDelegate
驗證會話任務代理協議
gtCaptchaSession:didReceive:result:
回調驗證會話的結果參數。
Declaration
- (void)gtCaptchaSession:(GTCaptcha4Session *)captchaSession
didReceive:(NSString *)status
result:(nullable NSDictionary *)result;
Parameters
| Param | Description |
|---|---|
| captchaSession | 驗證會話 |
| status | 狀態碼。@"0"/@"1": 未完成/完成。 當 status 為 @"1" 時,則為成功,需要對結果進行二次校驗。 |
| result | 結果校驗參數。 |
Discussion
拿到驗證結果的參數後,需要提交到業務服務端,完成參數的校驗。result 示例:
{
pass_token = "eb6d2e064524ae96ddc99a0e6e15f95dbb234008d108f0db269f27d426bcf3c6";
gen_time = "1660894030";
captcha_output = "fI9I34MDjVi10gJO_EqXwNpN8hK0rYLEPVWSDE4W6kc1umDoTHIlD_t6YQNNpPG2tJlKR8he6WFWkkllU8goGeNVNOzhqmAm256BpK8qAEHNrOjHzkNagfIcx_A21ssPrG6YlnnHFx3PfBnbrn5fb2aKDIi0I5xmCUjxq0dsFuANLIQVtllMjkJ7-1l_j-Wz";
captcha_id = "647f5ed2ed8acb4be36784e01556bb71";
lot_number = "0861c607d519469b9117d0c6dd551fe3";
}
gtCaptchaSession:didReceiveError:
回調驗證會話中發生的錯誤。
Declaration
- (void)gtCaptchaSession:(GTCaptcha4Session *)captchaSession
didReceiveError:(GTC4Error *)error;
Parameters
| Param | Description |
|---|---|
| captchaSession | 驗證會話 |
| error | 錯誤描述對象 |
Seealso
GTCaptcha4Session
驗證會話
delegate
驗證會話任務代理。
Declaration
@property (nonatomic, weak) id<GTCaptcha4SessionTaskDelegate> delegate;
captchaID
當前驗證會話的驗證 ID。
Declaration
@property (nonnull, readonly, nonatomic, strong) NSString *captchaID;
challenge
當前驗證會話的流水號。
Declaration
@property (nullable, readonly, nonatomic, strong) NSString *challenge;
configuration
當前驗證會話的配置。
Declaration
@property (nonnull, readonly, nonatomic, strong) GTCaptcha4SessionConfiguration *configuration;
sessionWithCaptchaID:
創建一個新的驗證會話實例。
Declaration
+ (instancetype)sessionWithCaptchaID:(NSString *)captchaID;
Parameters
| Param | Description |
|---|---|
| captchaID | 驗證ID |
Return Value
一個新的 GTCaptcha4Session 實例
sessionWithCaptchaID:configuration:
創建一個新的驗證會話實例。
Declaration
+ (instancetype)sessionWithCaptchaID:(NSString *)captchaID
configuration:(nullable GTCaptcha4SessionConfiguration *)configuration;
| Param | Description |
|---|---|
| captchaID | 驗證ID |
| configuration | 會話配置 |
Return Value
一個新的 GTCaptcha4Session 實例
initWithCaptchaID:
創建一個新的驗證會話實例。
Declaration
- (instancetype)initWithCaptchaID:(NSString *)captchaID;
Parameters
| Param | Description |
|---|---|
| captchaID | 驗證ID |
Return Value
一個新的 GTCaptcha4Session 實例
initWithCaptchaID:configuration:
創建一個新的驗證會話實例。
Declaration
- (instancetype)initWithCaptchaID:(NSString *)captchaID
configuration:(nullable GTCaptcha4SessionConfiguration *)configuration;
| Param | Description |
|---|---|
| captchaID | 驗證ID |
| configuration | 會話配置 |
Return Value
一個新的 GTCaptcha4Session 實例
verify
開始驗證。
Declaration
- (void)verify;
cancel
取消驗證。
Declaration
- (void)cancel;
sdkVersion
獲取 SDK 版本號。
Declaration
+ (NSString *)sdkVersion;
GTCaptcha4SessionConfiguration
驗證會話配置
GTC4UserInterfaceStyle
驗證介面樣式。
Declaration
typedef NS_ENUM(NSInteger, GTC4UserInterfaceStyle) {
/** 跟隨系統樣式 */
GTC4UserInterfaceStyleSystem = 0,
/** 普通樣式 */
GTC4UserInterfaceStyleLight,
/** 暗黑樣式 */
GTC4UserInterfaceStyleDark,
/** 默認樣式 */
GTC4UserInterfaceStyleDefault = GTC4UserInterfaceStyleLight
};
resourcePath
遠程訪問靜態資源的完整路徑, 默認為空。
Declaration
@property (nullable, nonatomic, strong) NSString *resourcePath;
protocol
遠程訪問靜態資源時的協議,默認 @“https”。
Declaration
@property (nonatomic, strong) NSString *protocol;
userInterfaceStyle
界面和狀態欄樣式,默認普通白色。
Declaration
@property (nonatomic, assign) GTC4UserInterfaceStyle userInterfaceStyle;
backgroundColor
背景顏色,默認透明。
Declaration
@property (nonatomic, strong) UIColor *backgroundColor;
debugEnable
調試模式開關,默認關閉。
Declaration
@property (nonatomic, assign) BOOL debugEnable;
backgroundUserInteractionEnable
點擊背景的交互,默認開啟。
Declaration
@property (nonatomic, assign) BOOL backgroundUserInteractionEnable;
timeout
請求超時時長,默認 8 秒。
Declaration
@property (nonatomic, assign) NSTimeInterval timeout;
language
語言,默認跟隨系統。指定語言請參考語言短碼。
Declaration
@property (nonatomic, strong) NSString *language;
supportedInterfaceOrientations
支持的橫豎屏方向。
Declaration
@property (assign, nonatomic) UIInterfaceOrientationMask supportedInterfaceOrientations;
additionalParameter
額外的參數, 默認為空。參數將被組裝後提交到engagelab。
Declaration
@property (nullable, nonatomic, strong) NSDictionary *additionalParameter;
Discussion
支持的鍵值列表如下:
|Key |Type |Description|Default Value|
|---- |---- |---------- | ----------- |
| @"loading" | NSString | 自定義加載中的狀態指示器,WebView 加載 html 的 loading 資源相對路徑。設置空字符串表示取消 loading。 | @"./gt4-loading.gif" |
| @"rem" | NSNumber | 設置驗證碼整體的縮放比例 | @(1) |
| @"hideBar" | NSArray<NSString *> * | 隱藏後續驗證界面的關閉按鈕、刷新按鈕。設置 @[@"close", @"refresh"] 則為隱藏關閉和刷新按鈕。 | @[] |
| @"nextWidth" | NSString | 驗證碼彈窗的寬度,需要攜帶單位,如 @"300px" | nil |
| @"riskType" | NSString | 結合風控融合,指定驗證形式 | nil |
| @"hideSuccess" | NSNumber | 隱藏驗證成功彈窗,@(0)/@(1) 為不隱藏或隱藏 | @(0) |
Sample Code
#define captchaID @"1234567890abcdef"
GTCaptcha4SessionConfiguration *config = [GTCaptcha4SessionConfiguration defaultConfiguration];
NSMutableDictionary *params = [@{} mutableCopy];
[params setValue:@(1.25) forKey:@"rem"]; // 放大 1.25 倍
[params setValue:@[@"close", @"refresh"] forKey:@"hideBar"]; // 隱藏關閉按鈕及刷新按鈕
[params setValue:@"300px" forKey:@"nextWidth"];
[params setValue:@"click" forKey:@"riskType"]; // 指定智能點擊形式驗證,需與後端配置一致
[params setValue:@(1) forKey:@"hideSuccess"]; // 使用 NSNumber 表示布爾值
[params setValue:@"./gt4-loading.gif" forKey:@"loading"];
config.additionalParameter = params;
GTCaptcha4Session *captchaSession = [GTCaptcha4Session sessionWithCaptchaID:captchaID configuration:config];
...
defaultConfiguration
獲得一個默認配置。
Declaration
+ (GTCaptcha4SessionConfiguration *)defaultConfiguration;
Return Value
+ (GTCaptcha4SessionConfiguration *)defaultConfiguration {
GTCaptcha4SessionConfiguration *config = [[GTCaptcha4SessionConfiguration alloc] init];
config.debugEnable = NO;
config.timeout = 8.0;
config.language = [GTC4Utils systemLanguage];
config.protocol = @"https";
config.userInterfaceStyle = GTC4UserInterfaceStyleDefault;
config.backgroundColor = [UIColor clearColor];
config.backgroundUserInteractionEnable = YES;
return config;
}
Error
錯誤描述對象
/// 不合法的參數。請檢查輸入的參數。
FOUNDATION_EXPORT NSString * const GTC4ErrorCodeInvalidParameter;
/// 操作失敗。詳細查看描述。
FOUNDATION_EXPORT NSString * const GTC4ErrorCodeOperationFail;
/// 資源缺失。請檢查 GTCaptcha4.bundle 文件是否完整。
FOUNDATION_EXPORT NSString * const GTC4ErrorCodeMissedResource;
/// 用戶取消了驗證。
FOUNDATION_EXPORT NSString * const GTC4ErrorCodeUserDidCancel;
/// 加載文件失敗。請檢查是否導入了完整的 GTCaptcha4.bundle 文件或者配置的遠程靜態資源是否可訪問。
FOUNDATION_EXPORT NSString * const GTC4ErrorCodeLoadFileFailure;
/// 加載超時。
FOUNDATION_EXPORT NSString * const GTC4ErrorCodeTimeout;
/// 執行 Javascript 腳本失敗。
FOUNDATION_EXPORT NSString * const GTC4ErrorCodeEvaluatingJavascriptFail;
/// Javascript 返回錯誤。
FOUNDATION_EXPORT NSString * const GTC4ErrorCodeJavascriptError;
/// WebView 記憶體警告。
FOUNDATION_EXPORT NSString * const GTC4ErrorCodeWebViewMemoryWarning;
/// 未知錯誤。
FOUNDATION_EXPORT NSString * const GTC4ErrorCodeUnknown;
code
錯誤碼。可用於匹配處理。
Declaration
@property (readonly, nonatomic, strong) NSString *code;
Seealso
見上方錯誤碼清單
msg
錯誤信息。可用於用戶界面展示。
Declaration
@property (readonly, nonatomic, strong) NSString *msg;
desc
錯誤詳細描述。用於詳細排查問題。
Declaration
@property (readonly, nonatomic, strong) NSDictionary *desc;
Discussion
可用於支撐用戶使用驗證的運營問題。










