一、准备工作
概述
本文档是身份证二要素SDK_iOS v1.0.0 版本的接入文档,用于指导SDK的使用方法,默认读者熟悉Xcode编译器的使用以及iOS编程语言。
前置条件
- SDK版本:V 1.0
- Xcode版本 : V9.4.1及以上版本,iOS9.0 及以上版本。
创建应用
提示:一个应用对应一个appid,多个应用(不同bundleID)需在闪验平台创建多个应用以对应多个appid
应用的创建流程及APPID/APPKEY的获取,请查看「账号创建」文档
快速体验Demo
- 将获取到appkey 和 appid 填入Demo 中sdk 的初始化方法中
- 将demo的bundleId 改为自己的bundleid
- 编译运行
开发环境搭建
- 将CLAuthSDK.framework导入工程注 注意勾选 Copy Items if need
2.xcode配置
- Xcode->TARGETS->Build Settings->Linking->Other Linker Flags 添加–ObjC
二、SDK调用说明
初始化SDK
方法原型
/// 初始化SDK /// @param appkey 创蓝平台appkey /// @param appid 创蓝平台APPid +(void)initSDKWithAPPkey:(NSString * _Nonnull)appkey appid:(NSString * _Nonnull)appid;
参数描述
参数 | 是否必填 | 类型 | 说明 |
appid | 是 | NSString | 实人认证获取的appid |
appkey | 是 | NSString | 实人认证获取的appkey |
示例代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [AuthSDK initSDKWithAPPkey:@"appkey" appid:@"appid"]; return YES; }
接口作用:初始化SDK,请确保在调用SDK前,调用该接口
添加协议控件(必须)
/// 创建授权控件(允许添加客户授权协议) /// @param contentView 放置授权视图的view;授权视图将和 contentView 一样大小,并且自动 add 到 contentView 上 /// @param agree 是否同意协议 (控制初始状态) /// @param customAuthTitile 用户授权协议 (如:《xxxx授权协议》) /// @param customAuthURL 授权链接 /// @param authType 授权控件展示类型 -(instancetype)initWithAuthUIWithContentView:(UIView *)contentView isAgree:(BOOL)agree customAuthTitile:(NSString *) customAuthTitile authWithURL:(NSString * )customAuthURL authtype:(AuthType )authType NS_DESIGNATED_INITIALIZER;
参数描述
参数 | 是否必填 | 类型 | 说明 |
contentView | 是 | UIView | 授权控件 父视图 (授权控件的 frame = 父视图的bounds) |
agree | 是 | BOOL | 授权控件状态 |
customAuthTitile | 是 | NSString | 客户授权协议名称如《xxx授权协议》 |
customAuthURL | 是 | NSString | 客户授权协议连接如:htto://xxxxxxx |
authType | 是 | 协议显示方式 | 见下面定义 |
authtype 参数说明
参数authtype | 类型 | |
AuthTypeDefault | NSInteger | 只显示默认协议 |
AuthTypeCustom | NSInteger | 只显示客户协议 |
AuthTypeAll | NSInteger | 默认协议和客户协议同时显示 |
调用示例
AuthUI *authUI = [[AuthUI alloc] initWithAuthUIWithContentView:self.userAuthContentView isAgree:YES customAuthTitile:@"《客户条款》" authWithURL:@"http://www.baidu.com" authtype:AuthTypeAll]; self.authUI = authUI;
二要素核验核验及回调结果
方法原型
/// 调用认证 /// @param authUI 授权对象 /// @param vc 当前viewController /// @param userName 用户名 /// @param idCardNumber 身份证号码 /// @param result 认证结果 + (void)authorWithAuthUI:(AuthUI *)authUI authVC:(UIViewController *)vc userName:(NSString *)userName idCardNumber:(NSString *)idCardNumber authResult:(AuthResult )result;
参数描述
参数 | 是否必填 | 类型 | 说明 |
authUI | 是 | AuthUI | 授权控件 |
vc | 是 | UIViewController | 当前视图控制器 |
userName | 是 | NSString | 核验人员姓名 |
idCardNumber | 是 | NSString | 核验人员身份证号码 |
result | 否 | block | 验证结果回调 |
示例代码
[AuthSDK authorWithAuthUI:self.authUI authVC:self userName:@"张三" idCardNumber:@"张三身份证号码" authResult:^(NSDictionary * _Nullable data, NSError * _Nullable error) { //网络错误 if (error) { dispatch_async(dispatch_get_main_queue(), ^{ sender.enabled = YES; [self.loadingView stopAnimating]; UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"网络错误" message:error.userInfo[NSLocalizedDescriptionKey] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alter show]; }); } if (data) { NSData *dt = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:nil]; NSString *jsonString = [[NSString alloc] initWithData:dt encoding:NSUTF8StringEncoding]; dispatch_async(dispatch_get_main_queue(), ^{ sender.enabled = YES; [self.loadingView stopAnimating]; UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"核验结果" message:jsonString delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alter show]; }); } }];
result回调参数描述
参数 | 类型 | 说明 |
error | NSError | 网络错误 |
data | NSDictionary(json) | 业务数据 |
data数据 详细说明
字段名 | 类型 | 说明 |
code | String | 响应code码。200000:成功,其他失败。见附录5.1响应code码 |
message | String | 响应code码解释 |
data | Object |
|
orderNo | String | 业务唯一流水号。例:628291418130630 |
handleTime | String | 查询时间 例:2018-04-09 15:05:01 |
province | String | 省份 |
city | String | 市区 |
country | String | 县区 |
birthday | String | 生日,格式是yyyyMMdd |
age | String | 年龄 |
gender | String | 性别:1:男、2:女 |
remark | String | 备注,例:一致 |
result | String | 返回结果: 01-认证一致(收费) 02-认证不一致(收费) 03-认证不确定(收费) 04-认证失败(不收费) |