iOS开发之笔记摘录

极限验证---iOS

2019-03-14  本文已影响0人  平安喜乐698
目录

极限验证官网

Podfile中+

pod 'GT3Captcha'
  1. 示例
#import <GT3Captcha/GT3Captcha.h>
<GT3CaptchaManagerDelegate>
/**
 极限验证
 */
@property (nonatomic, strong) GT3CaptchaManager *captchaManager;


    // 开始验证
    [self.captchaManager startGTCaptchaWithAnimated:YES];



#pragma MARK - GT3CaptchaManagerDelegate
/**
 调用startGTCaptchaWithAnimated后(开始验证)会调用
 
 @param manager GT3CaptchaManager
 @param originalRequest API1 originalRequest
 @param replacedHandler 返回修改后的Request
 */
- (void)gtCaptcha:(GT3CaptchaManager *)manager willSendRequestAPI1:(NSURLRequest *)originalRequest withReplacedHandler:(void (^)(NSURLRequest * request))replacedHandler{
    
    NSMutableURLRequest *mRequest = [originalRequest mutableCopy];
    mRequest.URL = originalRequest.URL;
    [mRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];//这个很关键,一
    [mRequest setHTTPMethod:@"POST"];
    mRequest.HTTPBody = [@"参数" dataUsingEncoding:NSUTF8StringEncoding];
    replacedHandler(mRequest);
}


/**
 极限验证通过时调用

 @param manager GT3CaptchaManager
 @param code code
 @param result result
 @param message message
 */
- (void)gtCaptcha:(GT3CaptchaManager *)manager didReceiveCaptchaCode:(NSString *)code result:(NSDictionary *)result message:(NSString *)message{
    
    //
}

/**
 验证过程出现错误时调用

 @param manager GT3CaptchaManager
 @param error 错误
 */
- (void)gtCaptcha:(GT3CaptchaManager *)manager errorHandler:(GT3Error *)error {
    // 处理验证中返回的错误
    if (error.code == -999) {       // 请求被意外中断, 一般由用户进行取消操作导致, 可忽略错误
        return;
    }else if (error.code == -10) {  // 预判断时被封禁, 不会再进行图形验证
    }else if (error.code == -20) {  // 尝试过多
    }else {                         // 网络问题或解析失败, 更多错误码参考开发文档
    }
}


/**
 用户主动关闭验证后调用

 @param manager GT3CaptchaManager
 */
- (void)gtCaptchaUserDidCloseGTView:(GT3CaptchaManager *)manager {
    NSLog(@"User Did Close GTView.");
}


/**
 ReceiveDataFromAPI1

 @param manager GT3CaptchaManager
 @param dictionary dictionary
 @param error error
 @return ReceiveDataFromAPI1
 */
- (NSDictionary *)gtCaptcha:(GT3CaptchaManager *)manager didReceiveDataFromAPI1:(NSDictionary *)dictionary withError:(GT3Error *)error{
    
    if ([[dictionary objectForKey:@"code"] integerValue]== 0) {
        
    }
    return dictionary;
}

/**
 是否禁用API2请求
 
 @param manager GT3CaptchaManager
 @return 是否禁用API2请求
 */
- (BOOL)shouldUseDefaultSecondaryValidate:(GT3CaptchaManager *)manager{
    
    return NO;
}





#pragma mark 懒加载
/**
 极限验证
 
 @return GT3CaptchaManager
 */
- (GT3CaptchaManager *)captchaManager {
    if (!_captchaManager) {
        /**
         创建 极限验证管理器实例
         
         api_1,api_2,超时时间
         */
        _captchaManager = [[GT3CaptchaManager alloc] initWithAPI1:@"api_1" API2:@"api_2" timeout:10.0];
        // dele
        _captchaManager.delegate = self;
        // 底部背景色
        _captchaManager.maskColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.6];
    }
    return _captchaManager;
}
  1. 待续
上一篇下一篇

猜你喜欢

热点阅读