001 请求接口获取到接入参数 接入 代理 WBFaceVerifyCustomerServiceDelegate
@property (nonatomic, copy) NSString *appid;
@property (nonatomic, copy) NSString *nonce;
@property (nonatomic, copy) NSString *sign;
@property (nonatomic, copy) NSString *orderNO;
@property (nonatomic, copy) NSString *userID;
@property (nonatomic, copy) NSString *licence;
@property (nonatomic, copy) NSString *keyVersion;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *idNo;
@property (nonatomic, copy) NSString *wbfacebaseURLString;
@property (nonatomic, copy) NSString *wbgetFaceIDURLString;
002 发起活体检测
[WBFaceVerifyCustomerService sharedInstance].delegate = self;
WBFaceVerifySDKConfig *config = [self getSDKSettings];
// // 活体检测 + 身份证 + 姓名
NSDictionary *params = @{@"webankAppId":self.appid,
@"orderNo":self.orderNO,
@"name": self.name,
@"idNo": self.idNo,
@"userId":self.userID,
@"nonce":self.nonce,
@"version": @"1.0.0",
@"sign": self.sign,
@"licence":self.licence
};
NSData *bodydata = [NSJSONSerialization dataWithJSONObject:params options:NSJSONReadingMutableLeaves|NSJSONReadingAllowFragments error:nil];
NSURLSession *session = [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.defaultSessionConfiguration];
NSMutableURLRequest *requst = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.wbgetFaceIDURLString]];
[requst setHTTPMethod:@"POST"];
[requst setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
requst.HTTPBody = bodydata;
NSLog(@"request: %@", requst);
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:requst completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
[SVProgressHUD dismiss];
NSString *message = [NSString stringWithFormat:@"%@", error.description];
NSLog(@"error: %@", error);
[SVProgressHUD showErrorWithStatus:message];
return ;
}
NSError * jsonErr = nil;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonErr];
if(jsonErr != nil){
[SVProgressHUD dismiss];
NSString *message = [NSString stringWithFormat:@"%@", jsonErr.description];
NSLog(@"error: %@", error);
[SVProgressHUD showErrorWithStatus:message];
return ;
}
//其他情况, json有数据, json没有faceId
NSLog(@"dict: %@", [dict objectForKey:@"msg"]);
NSString *faceId = [dict valueForKeyPath:@"result.faceId"];
// if (faceId.length <= 0) {
// [SVProgressHUD dismiss];
// [SVProgressHUD showErrorWithStatus:dict.description];
// return ;
// }
dispatch_async(dispatch_get_main_queue(), ^{
// 身份证+姓名接口
[[WBFaceVerifyCustomerService sharedInstance] initSDKWithUserId:self.userID nonce:self.nonce sign:self.sign appid:self.appid orderNo:self.orderNO apiVersion:self.keyVersion licence:self.licence faceId:faceId sdkConfig:config success:^{
[[WBFaceVerifyCustomerService sharedInstance] startWbFaceVeirifySdk];
[SVProgressHUD dismiss];
} failure:^(WBFaceError * _Nonnull error) {
[SVProgressHUD dismiss];
if (iOS8Later) {
NSString *message = [NSString stringWithFormat:@"%@", error.desc];
NSLog(@"error: %@", error);
[SVProgressHUD showErrorWithStatus:message];
//
}
}];
});
}];
[dataTask resume];
return;
}
#pragma mark - WBFaceVerifyCustomerServiceDelegate
-(void)wbSDKServiceDidFinishedNotification:(NSNotification *)noti {
WBFaceVerifyResult *faceVerifyResult = (WBFaceVerifyResult *)[noti.userInfo objectForKey:@"faceVerifyResult"];
if (faceVerifyResult.isSuccess){
NSString *message = [NSString stringWithFormat:@"liveRate: %@, similarity: %@", faceVerifyResult.liveRate, faceVerifyResult.similarity];
[SVProgressHUD showSuccessWithStatus:message];
[self requsetCheckFaceVerify];
}else{
NSString *message = [NSString stringWithFormat:@"%@", faceVerifyResult.error.desc];
[SVProgressHUD showSuccessWithStatus:message];
}
}
- (void)requsetCheckFaceVerify{
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[AutoSwitchFlag shared].openAFNet = YES;
[self routeTargetName:Handle actionName:@"checkAuthCerifyAction:" param:dic];
}
-(WBFaceVerifySDKConfig *)getSDKSettings{
WBFaceVerifySDKConfig *config = [WBFaceVerifySDKConfig sdkConfig];
config.recordVideo = YES;
config.theme = WBFaceVerifyThemeLightness;
config.showSuccessPage = YES;
config.showFailurePage = YES;
config.enableCloseEyes = NO;
return config;
}
- (void)wbfaceVerifyCustomerServiceDidFinishedWithFaceVerifyResult:(nonnull WBFaceVerifyResult *)faceVerifyResult {
if (faceVerifyResult.isSuccess){
NSString *message = [NSString stringWithFormat:@"liveRate: %@, similarity: %@", faceVerifyResult.liveRate, faceVerifyResult.similarity];
[SVProgressHUD showSuccessWithStatus:message];
[self requsetCheckFaceVerify];
}else{
NSString *message = [NSString stringWithFormat:@"%@", faceVerifyResult.error.desc];
[SVProgressHUD showErrorWithStatus:message];
}
}