221閃驗集成文檔-簡版
一亩歹、創(chuàng)建應(yīng)用
**提示:一個應(yīng)用對應(yīng)一個appid,多個應(yīng)用(不同bundleID)需在閃驗平臺創(chuàng)建多個應(yīng)用以對應(yīng)多個appid
**
應(yīng)用的創(chuàng)建流程及APPID/APPKEY的獲取,請查看「賬號創(chuàng)建」文檔
二惊窖、集成方式
1.通過CocoaPods自動集成
在工程的Podfile
里面添加以下代碼:以下示例pod 版本僅供參考,請按需選擇或選擇最新版本
pod 'CL_ShanYanSDK', '2.2.0.5'
注意:
在podfile中保存并執(zhí)行pod install --no-repo-update
,然后用后綴為.xcworkspace
的文件打開工程。
命令行下執(zhí)行pod search CL_ShanYanSDK
,如顯版本不是最新版漫雷,或者pod install導(dǎo)入的版本不是最新版,則先執(zhí)行pod repo update
操作更新本地repo的內(nèi)容
關(guān)于CocoaPods
的更多信息請查看 CocoaPods官方網(wǎng)站鳍咱。
2. 手動集成
2.1 導(dǎo)入framework
將閃驗SDK壓縮包中framework文件夾下所有資源添加到工程中(注意勾選Copy items if needed)
2.2 Xcode配置
-
OtherLinkerFlags中 添加-ObjC****:xcode->BuildSetting->Other Linker Flags 添加 -ObjC
-
添加libc++.1.tbd: 在xcode->General->Linked Frameworks and Libraries中點擊 + 降盹,搜索并選擇添加 libc++.1.tbd
3. Swift工程額外配置
-
在xcode->BuildSetting->Other Linker Flags 添加-force_load
- 在-force_load下方添加CL_ShanYanSDK.framework/CL_ShanYanSDK所在路徑,具體操作可以將CL_ShanYanSDK.framework拖入空欄谤辜,在尾部拼接靜態(tài)庫名稱CL_ShanYanSDK蓄坏,將前綴絕對地址改成相對地址(SRCROOT)/.../CL_ShanYanSDK.framework/CL_ShanYanSDK"形式
三、SDK使用說明
1.初始化
- 導(dǎo)入閃驗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.預(yù)取號
建議進(jìn)入頁面時在viewDidLoad中進(jìn)行預(yù)取號操作
- (void)viewDidLoad {
[super viewDidLoad];
// 預(yù)取號
[CLShanYanSDKManager preGetPhonenumber:nil];
}
3.拉起授權(quán)頁
3.1 授權(quán)頁UI設(shè)置
// 控件元素設(shè)置
CLUIConfigure * baseUIConfigure = [[CLUIConfigure alloc] init];
// self 為拉起授權(quán)頁時的當(dāng)前頁面控制器
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 = @[@"閃驗用戶協(xié)議",[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];
//隱私協(xié)議頁
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);
// 控件布局設(shè)置
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;
// 拉起授權(quán)頁時將baseUIConfigure參數(shù)傳入接口中即可
[CLShanYanSDKManager quickAuthLoginWithConfigure:baseUIConfigure openLoginAuthListener:^(CLCompleteResult * _Nonnull completeResult) {
dispatch_async(dispatch_get_main_queue(), ^{
// 隱藏loading操作
...
});
if (completeResult.error) {
NSLog(@"授權(quán)頁拉起失敗");
}else{
NSLog(@"授權(quán)頁拉起成功");
}
} oneKeyLoginListener:^(CLCompleteResult * _Nonnull completeResult) {
if (completeResult.error) {
NSLog(@"一鍵登錄失敗");
}else{
NSLog(@"一鍵登錄成功---進(jìn)行置換手機號操作");
// 置換手機號操作
...
}
}
];
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];
//屏幕旋轉(zhuǎn)通知
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.拉起授權(quán)頁
// 拉起授權(quán)頁時將baseUIConfigure參數(shù)傳入接口中即可
[CLShanYanSDKManager quickAuthLoginWithConfigure:baseUIConfigure openLoginAuthListener:^(CLCompleteResult * _Nonnull completeResult) {
dispatch_async(dispatch_get_main_queue(), ^{
// 隱藏loading操作
...
});
if (completeResult.error) {
NSLog(@"授權(quán)頁拉起失敗");
}else{
NSLog(@"授權(quán)頁拉起成功");
}
} oneKeyLoginListener:^(CLCompleteResult * _Nonnull completeResult) {
if (completeResult.error) {
NSLog(@"一鍵登錄失敗");
}else{
NSLog(@"一鍵登錄成功---進(jìn)行置換手機號操作");
// 置換手機號操作
...
}
}
];
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提供的調(diào)試API及調(diào)用示例,在調(diào)試階段可暫時調(diào)用此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);
// 成功拿到手機號后嵌屎,關(guān)閉授權(quán)頁
[CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:nil];
} else {
NSLog(@"免密登錄失敗:%@",responseObject);
}
}
}];
}
}
}];
6.關(guān)閉授權(quán)頁
注意:授權(quán)頁面未拉起的情況調(diào)用該方法無效并且無回調(diào)
//
[CLShanYanSDKManager finishAuthControllerCompletion:^{
// 關(guān)閉授權(quán)頁后其他操作--該回調(diào)已切換為主線程
}];