221闪验集成文档-简版
一、创建应用
**提示:一个应用对应一个appid,多个应用(不同bundleID)需在闪验平台创建多个应用以对应多个appid
**
应用的创建流程及APPID/APPKEY的获取,请查看「账号创建」文档
二、集成方式
1.通过CocoaPods自动集成
在工程的Podfile
里面添加以下代码:以下示例pod 版本仅供参考,请按需选择或选择最新版本
pod 'CL_ShanYanSDK', '2.2.0.5'
注意:
在podfile中保存并执行pod install --no-repo-update
,然后用后缀为.xcworkspace
的文件打开工程。
命令行下执行pod search CL_ShanYanSDK
,如显版本不是最新版,或者pod install导入的版本不是最新版,则先执行pod repo update
操作更新本地repo的内容
关于CocoaPods
的更多信息请查看 CocoaPods官方网站。
2. 手动集成
2.1 导入framework
将闪验SDK压缩包中framework文件夹下所有资源添加到工程中(注意勾选Copy items if needed)
2.2 Xcode配置
-
OtherLinkerFlags中 添加-ObjC****:xcode->BuildSetting->Other Linker Flags 添加 -ObjC
image
-
添加libc++.1.tbd: 在xcode->General->Linked Frameworks and Libraries中点击 + ,搜索并选择添加 libc++.1.tbd
image
3. Swift工程额外配置
-
在xcode->BuildSetting->Other Linker Flags 添加-force_load
image
- 在-force_load下方添加CL_ShanYanSDK.framework/CL_ShanYanSDK所在路径,具体操作可以将CL_ShanYanSDK.framework拖入空栏,在尾部拼接静态库名称CL_ShanYanSDK,将前缀绝对地址改成相对地址(SRCROOT)/.../CL_ShanYanSDK.framework/CL_ShanYanSDK"形式
image
三、SDK使用说明
1.初始化
- 导入闪验SDK头文件
#import <CL_ShanYanSDK/CL_ShanYanSDK.h>
- 在AppDelegate中的
didFinishLaunchingWithOptions
方法中添加初始化代码
注意:需要填入闪验控制台上的appid 和 appkey,同时项目工程需要匹配控制台上的bundleId
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 需要填入闪验控制台上的appid 和 appkey
[CLShanYanSDKManager initWithAppId:cl_SDK_APPID AppKey:cl_SDK_APPKEY complete:^(CLCompleteResult * _Nonnull completeResult) {
if (completeResult.error) {
NSLog(@"初始化失败");
} else {
NSLog(@"初始化成功");
}
}];
}
2.预取号
建议进入页面时在viewDidLoad中进行预取号操作
- (void)viewDidLoad {
[super viewDidLoad];
// 预取号
[CLShanYanSDKManager preGetPhonenumber:nil];
}
3.拉起授权页
3.1 授权页UI设置
// 控件元素设置
CLUIConfigure * baseUIConfigure = [[CLUIConfigure alloc] init];
// self 为拉起授权页时的当前页面控制器
baseUIConfigure.viewController = self;
baseUIConfigure.clNavigationBackgroundClear = @(YES);
baseUIConfigure.clNavigationBottomLineHidden = @(YES);
baseUIConfigure.clNavigationBackBtnImage = [UIImage imageNamed:@"close-white"];
baseUIConfigure.clNavigationBarStyle = @(UIBarStyleBlack);
//LOGO
baseUIConfigure.clLogoImage = [UIImage imageNamed:@"logo_shanyan_text"];
baseUIConfigure.clLogoCornerRadius = @(10);
//PhoneNumber
baseUIConfigure.clPhoneNumberColor = UIColor.blackColor;
baseUIConfigure.clPhoneNumberFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:20.0*screenScale];
//LoginBtn
baseUIConfigure.clLoginBtnText = @"本机号一键登录";
baseUIConfigure.clLoginBtnTextFont = [UIFont systemFontOfSize:15*screenScale];
baseUIConfigure.clLoginBtnBgColor = [UIColor colorWithRed:0.2 green:0.8 blue:0.2 alpha:1];
baseUIConfigure.clLoginBtnCornerRadius = @(10*screenScale);
//Privacy
baseUIConfigure.clAppPrivacyFirst = @[@"闪验用户协议",[NSURL URLWithString:@"https://www.baidu.com"]];
baseUIConfigure.clAppPrivacySecond = @[@"隐私政策",[NSURL URLWithString:@"https://www.sina.com"]];
baseUIConfigure.clAppPrivacyColor = @[[UIColor lightGrayColor],[UIColor greenColor]];
baseUIConfigure.clAppPrivacyTextAlignment = @(NSTextAlignmentCenter);
baseUIConfigure.clAppPrivacyTextFont = [UIFont systemFontOfSize:11*screenScale];
//隐私协议页
baseUIConfigure.clAppPrivacyWebBackBtnImage = [UIImage imageNamed:@"title_back"];
NSMutableAttributedString * att0 = [[NSMutableAttributedString alloc]initWithString:@"隐私" attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:17],NSForegroundColorAttributeName:[UIColor blueColor]}];
NSMutableAttributedString * att1 = [[NSMutableAttributedString alloc]initWithString:@"条款" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor orangeColor]}];
[att0 appendAttributedString:att1];
baseUIConfigure.clAppPrivacyWebAttributesTitle = att0;
//CheckBox
baseUIConfigure.clCheckBoxHidden = @(NO);
baseUIConfigure.clCheckBoxValue = @(NO);
baseUIConfigure.clCheckBoxSize = [NSValue valueWithCGSize:CGSizeMake(30*screenScale, 30*screenScale)];
baseUIConfigure.clCheckBoxImageEdgeInsets = [NSValue valueWithUIEdgeInsets:UIEdgeInsetsMake(2*screenScale, 10*screenScale, 13*screenScale, 5*screenScale)];
baseUIConfigure.clCheckBoxVerticalAlignmentToAppPrivacyCenterY = @(YES);
baseUIConfigure.clCheckBoxCheckedImage = [UIImage imageNamed:@"checkBoxSEL"];
baseUIConfigure.clCheckBoxUncheckedImage = [UIImage imageNamed:@"checkBoxNor"];
//Slogan
baseUIConfigure.clSloganTextColor = UIColor.lightGrayColor;
baseUIConfigure.clSloganTextFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:11.0*screenScale];
baseUIConfigure.clSlogaTextAlignment = @(NSTextAlignmentCenter);
// 控件布局设置
CGFloat screenWidth_Portrait;
CGFloat screenHeight_Portrait;
CGFloat screenWidth_Landscape;
CGFloat screenHeight_Landscape;
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
screenWidth_Portrait = UIScreen.mainScreen.bounds.size.width;
screenHeight_Portrait = UIScreen.mainScreen.bounds.size.height;
screenWidth_Landscape = UIScreen.mainScreen.bounds.size.height;
screenHeight_Landscape = UIScreen.mainScreen.bounds.size.width;
}else{
screenWidth_Portrait = UIScreen.mainScreen.bounds.size.height;
screenHeight_Portrait = UIScreen.mainScreen.bounds.size.width;
screenWidth_Landscape = UIScreen.mainScreen.bounds.size.width;
screenHeight_Landscape = UIScreen.mainScreen.bounds.size.height;
}
CGFloat screenScale = [UIScreen mainScreen].bounds.size.width/375.0;
if (screenScale > 1) {
screenScale = 1;
}
//layout 布局
//布局-竖屏
CLOrientationLayOut * clOrientationLayOutPortrait = [CLOrientationLayOut new];
clOrientationLayOutPortrait.clLayoutPhoneCenterY = @(0*screenScale);
clOrientationLayOutPortrait.clLayoutPhoneLeft = @(50*screenScale);
clOrientationLayOutPortrait.clLayoutPhoneRight = @(-50*screenScale);
clOrientationLayOutPortrait.clLayoutPhoneHeight = @(20*screenScale);
clOrientationLayOutPortrait.clLayoutLogoWidth = @(100*screenScale);
clOrientationLayOutPortrait.clLayoutLogoHeight = @(100*screenScale);
clOrientationLayOutPortrait.clLayoutLogoCenterX = @(0);
clOrientationLayOutPortrait.clLayoutLogoCenterY = @(-SCREEN_HEIGHT*0.25);
clOrientationLayOutPortrait.clLayoutLoginBtnCenterY= @(clOrientationLayOutPortrait.clLayoutPhoneCenterY.floatValue + clOrientationLayOutPortrait.clLayoutPhoneHeight.floatValue*0.5*screenScale + 20*screenScale + 15*screenScale);
clOrientationLayOutPortrait.clLayoutLoginBtnHeight = @(30*screenScale);
clOrientationLayOutPortrait.clLayoutLoginBtnLeft = @(70*screenScale);
clOrientationLayOutPortrait.clLayoutLoginBtnRight = @(-70*screenScale);
clOrientationLayOutPortrait.clLayoutAppPrivacyLeft = @(40*screenScale);
clOrientationLayOutPortrait.clLayoutAppPrivacyRight = @(-40*screenScale);
clOrientationLayOutPortrait.clLayoutAppPrivacyBottom = @(0*screenScale);
clOrientationLayOutPortrait.clLayoutAppPrivacyHeight = @(45*screenScale);
clOrientationLayOutPortrait.clLayoutSloganLeft = @(0);
clOrientationLayOutPortrait.clLayoutSloganRight = @(0);
clOrientationLayOutPortrait.clLayoutSloganHeight = @(15*screenScale);
clOrientationLayOutPortrait.clLayoutSloganBottom = @(clOrientationLayOutPortrait.clLayoutAppPrivacyBottom.floatValue - clOrientationLayOutPortrait.clLayoutAppPrivacyHeight.floatValue);
baseUIConfigure.clOrientationLayOutPortrait = clOrientationLayOutPortrait;
// 拉起授权页时将baseUIConfigure参数传入接口中即可
[CLShanYanSDKManager quickAuthLoginWithConfigure:baseUIConfigure openLoginAuthListener:^(CLCompleteResult * _Nonnull completeResult) {
dispatch_async(dispatch_get_main_queue(), ^{
// 隐藏loading操作
...
});
if (completeResult.error) {
NSLog(@"授权页拉起失败");
}else{
NSLog(@"授权页拉起成功");
}
} oneKeyLoginListener:^(CLCompleteResult * _Nonnull completeResult) {
if (completeResult.error) {
NSLog(@"一键登录失败");
}else{
NSLog(@"一键登录成功---进行置换手机号操作");
// 置换手机号操作
...
}
}
];
3.2 自定义控件
__weak typeof(self) weakSelf = self;
baseUIConfigure.customAreaView = ^(UIView * _Nonnull customAreaView) {
__strong typeof(weakSelf) strongSelf = weakSelf;
UIImageView * bg0 = [UIImageView new];
[customAreaView addSubview:bg0];
UIImageView * bg = [[UIImageView alloc]init];
[customAreaView addSubview:bg];
UIButton * weChat = [[UIButton alloc]init];
[weChat setBackgroundImage:[UIImage imageNamed:@"微信"] forState:(UIControlStateNormal)];
[customAreaView addSubview:weChat];
UIButton * qq = [[UIButton alloc]init];
[qq setBackgroundImage:[UIImage imageNamed:@"qq"] forState:(UIControlStateNormal)];
[customAreaView addSubview:qq];
UIButton * weibo = [[UIButton alloc]init];
[weibo setBackgroundImage:[UIImage imageNamed:@"weibo"] forState:(UIControlStateNormal)];
[customAreaView addSubview:weibo];
//布局
[strongSelf setSeylt2Contrains:bg0 bg:bg wx:weChat qq:qq webo:weibo customView:customAreaView];
//屏幕旋转通知
strongSelf-> _notifObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidChangeStatusBarFrameNotification object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note) {
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf setSeylt2Contrains:bg0 bg:bg wx:weChat qq:qq webo:weibo customView:customAreaView];
}];
};
3.3 自定义loading
// 自定义loading
baseUIConfigure.loadingView = ^(UIView * _Nonnull containerView) {
UIImage *image = [YYImage imageNamed:@"KungFuPanda.gif"];
UIImageView *imageBackground = [[YYAnimatedImageView alloc] initWithImage:image];
[containerView addSubview:imageBackground];
imageBackground.layer.cornerRadius = 40;
imageBackground.layer.masksToBounds = YES;
[imageBackground mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(80, 80));
make.center.mas_equalTo(0);
}];
};
4.拉起授权页
// 拉起授权页时将baseUIConfigure参数传入接口中即可
[CLShanYanSDKManager quickAuthLoginWithConfigure:baseUIConfigure openLoginAuthListener:^(CLCompleteResult * _Nonnull completeResult) {
dispatch_async(dispatch_get_main_queue(), ^{
// 隐藏loading操作
...
});
if (completeResult.error) {
NSLog(@"授权页拉起失败");
}else{
NSLog(@"授权页拉起成功");
}
} oneKeyLoginListener:^(CLCompleteResult * _Nonnull completeResult) {
if (completeResult.error) {
NSLog(@"一键登录失败");
}else{
NSLog(@"一键登录成功---进行置换手机号操作");
// 置换手机号操作
...
}
}
];
5.获取置换手机号
[CLShanYanSDKManager quickAuthLoginWithConfigure:baseUIConfigure openLoginAuthListener:^(CLCompleteResult * _Nonnull completeResult) {
...
} oneKeyLoginListener:^(CLCompleteResult * _Nonnull completeResult) {
if (completeResult.error) {
...
}else{
//SDK成功获取到Token
NSString * telecom = [completeResult.data valueForKey:@"telecom"];
//urlStr:用户后台对接闪验后台后配置的API,以下为Demo提供的调试API及调用示例,在调试阶段可暂时调用此API,也可用此API验证后台API是否正确配置
NSString * urlStr = nil;
if ([telecom isEqualToString:@"CMCC"]) {
urlStr = [cl_SDK_URL stringByAppendingString:@"open/flashsdk/mobile-query-m"];
}else if ([telecom isEqualToString:@"CUCC"]) {
urlStr = [cl_SDK_URL stringByAppendingString:@"open/flashsdk/mobile-query-u"];
}else if ([telecom isEqualToString:@"CTCC"]) {
urlStr = [cl_SDK_URL stringByAppendingString:@"open/flashsdk/mobile-query-t"];
}else{
//失败
return;
}
if (urlStr) {
NSLog(@"tokenParamr:%@",completeResult.data);
[NetWorkManager POST_url:urlStr withParameter:completeResult.data complete:^(NSDictionary * _Nonnull responseObject, NSError * _Nonnull error) {
if (error) {
NSLog(@"置换手机号出错:%@",error);
}else{
NSInteger code = [[responseObject valueForKey:@"code"] integerValue];
if (code == 200000) {
NSString * mobileName = responseObject[@"data"][@"mobileName"];
// decryptUseDESKey:解密方法详情见demo
NSString * mobileCode = [mobileName decryptUseDESKey:cl_SDK_APPKEY];
NSLog(@"免密登录成功,手机号:%@",mobileCode);
// 成功拿到手机号后,关闭授权页
[CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:nil];
} else {
NSLog(@"免密登录失败:%@",responseObject);
}
}
}];
}
}
}];
6.关闭授权页
注意:授权页面未拉起的情况调用该方法无效并且无回调
//
[CLShanYanSDKManager finishAuthControllerCompletion:^{
// 关闭授权页后其他操作--该回调已切换为主线程
}];
网友评论