Captcha v4
API 参考

iOS

iOS SDK 接口参数与配置说明。

GeeLabCaptchaSessionTaskDelegate

验证会话任务代理协议

geelabCaptchaSession:didReceive:result:

回调验证会话的结果参数。

Declaration

- (void)geelabCaptchaSession:(GeeLabCaptchaSession *)captchaSession
              didReceive:(NSString *)status
                  result:(nullable NSDictionary *)result;

Parameters

ParamDescription
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";
}

geelabCaptchaSession:didReceiveError:

回调验证会话中发生的错误。

Declaration

- (void)geelabCaptchaSession:(GeeLabCaptchaSession *)captchaSession
         didReceiveError:(GeeLabCaptchaError *)error;

Parameters

ParamDescription
captchaSession验证会话
error错误描述对象

Seealso

GeeLabCaptchaError

GeeLabCaptchaSession

验证会话

delegate

验证会话任务代理。

Declaration

@property (nonatomic, weak) id<GeeLabCaptchaSessionTaskDelegate> 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) GeeLabCaptchaSessionConfiguration *configuration;

sessionWithCaptchaID:

创建一个新的验证会话实例。

Declaration

+ (instancetype)sessionWithCaptchaID:(NSString *)captchaID;

Parameters

ParamDescription
captchaID验证ID

Return Value

一个新的 GeeLabCaptchaSession 实例

sessionWithCaptchaID:configuration:

创建一个新的验证会话实例。

Declaration

+ (instancetype)sessionWithCaptchaID:(NSString *)captchaID
                       configuration:(nullable GeeLabCaptchaSessionConfiguration *)configuration;
ParamDescription
captchaID验证ID
configuration会话配置

Return Value

一个新的 GeeLabCaptchaSession 实例

initWithCaptchaID:

创建一个新的验证会话实例。

Declaration

- (instancetype)initWithCaptchaID:(NSString *)captchaID;

Parameters

ParamDescription
captchaID验证ID

Return Value

一个新的 GeeLabCaptchaSession 实例

initWithCaptchaID:configuration:

创建一个新的验证会话实例。

Declaration

- (instancetype)initWithCaptchaID:(NSString *)captchaID
                    configuration:(nullable GeeLabCaptchaSessionConfiguration *)configuration;
ParamDescription
captchaID验证ID
configuration会话配置

Return Value

一个新的 GeeLabCaptchaSession 实例

verify

开始验证。

Declaration

- (void)verify;

cancel

取消验证。

Declaration

- (void)cancel;

sdkVersion

获取 SDK 版本号。

Declaration

+ (NSString *)sdkVersion;

GeeLabCaptchaSessionConfiguration

验证会话配置

GeeLabCaptchaUserInterfaceStyle

验证界面样式。

Declaration

typedef NS_ENUM(NSInteger, GeeLabCaptchaUserInterfaceStyle) {
    /** 跟随系统样式 */
    GeeLabCaptchaUserInterfaceStyleSystem = 0,
    /** 普通样式 */
    GeeLabCaptchaUserInterfaceStyleLight,
    /** 暗黑样式 */
    GeeLabCaptchaUserInterfaceStyleDark,
    /** 默认样式 */
    GeeLabCaptchaUserInterfaceStyleDefault = GeeLabCaptchaUserInterfaceStyleLight
};

resourcePath

远程访问静态资源的完整路径, 默认为空。

Declaration

@property (nullable, nonatomic, strong) NSString *resourcePath;

protocol

远程访问静态资源时的协议,默认 @“https”。

Declaration

@property (nonatomic, strong) NSString *protocol;

userInterfaceStyle

界面和状态栏样式,默认普通白色。

Declaration

@property (nonatomic, assign) GeeLabCaptchaUserInterfaceStyle 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

额外的参数, 默认为空。参数将被组装后提交到验证码服务。

Declaration

@property (nullable, nonatomic, strong) NSDictionary *additionalParameter;

Discussion

支持的键值列表如下:

KeyTypeDescriptionDefault 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"

GeeLabCaptchaSessionConfiguration *config = [GeeLabCaptchaSessionConfiguration 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;

GeeLabCaptchaSession *captchaSession = [GeeLabCaptchaSession sessionWithCaptchaID:captchaID configuration:config];
...

defaultConfiguration

获得一个默认配置。

Declaration

+ (GeeLabCaptchaSessionConfiguration *)defaultConfiguration;

Return Value

+ (GeeLabCaptchaSessionConfiguration *)defaultConfiguration {
    GeeLabCaptchaSessionConfiguration *config = [[GeeLabCaptchaSessionConfiguration alloc] init];
    config.debugEnable  = NO;
    config.timeout      = 8.0;
    config.language     = [GeeLabCaptchaUtils systemLanguage];
    config.protocol     = @"https";
    config.userInterfaceStyle = GeeLabCaptchaUserInterfaceStyleDefault;
    config.backgroundColor = [UIColor clearColor];
    config.backgroundUserInteractionEnable = YES;

    return config;
}

GeeLabCaptchaError

错误描述对象

/// 不合法的参数。请检查输入的参数。
FOUNDATION_EXPORT NSString * const GeeLabCaptchaErrorCodeInvalidParameter;
/// 操作失败。详细查看描述。
FOUNDATION_EXPORT NSString * const GeeLabCaptchaErrorCodeOperationFail;
/// 资源缺失。请检查 GeeLabCaptcha.bundle 文件是否完整。
FOUNDATION_EXPORT NSString * const GeeLabCaptchaErrorCodeMissedResource;

/// 用户取消了验证。
FOUNDATION_EXPORT NSString * const GeeLabCaptchaErrorCodeUserDidCancel;

/// 加载文件失败。请检查是否导入了完整的 GeeLabCaptcha.bundle 文件或者配置的远程静态资源是否可访问。
FOUNDATION_EXPORT NSString * const GeeLabCaptchaErrorCodeLoadFileFailure;
/// 加载超时。
FOUNDATION_EXPORT NSString * const GeeLabCaptchaErrorCodeTimeout;
/// 执行 Javascript 脚本失败。
FOUNDATION_EXPORT NSString * const GeeLabCaptchaErrorCodeEvaluatingJavascriptFail;
/// Javascript 返回错误。
FOUNDATION_EXPORT NSString * const GeeLabCaptchaErrorCodeJavascriptError;
/// WebView 内存警告。
FOUNDATION_EXPORT NSString * const GeeLabCaptchaErrorCodeWebViewMemoryWarning;

/// 未知错误。
FOUNDATION_EXPORT NSString * const GeeLabCaptchaErrorCodeUnknown;

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

可用于支撑用户使用验证的运营问题。