iOS接入阿里雲一鍵登陸,號碼認證

我接入這個的時候,網上可用代碼找不到,sdk文檔也寫的比較坑,各類錯別字就不說了。json

先說說比較坑的:1.  這個官方sdk帶的demo下載下來是沒法運行的,須要手動替換裏面的sdk包,由於demo裏面的不是release模式。網絡

                        2. 而後換了sdk以後發現ATAuthSDK.bundle和TYRZResource.bundle這兩個文件找不到,須要手動從release文件將他們拖出來放到工程裏面。app

 

到這裏demo能運行了。async

 

好接下來,須要在阿里雲後臺註冊app,填好bundelid就好了。在本身工程裏面也要按照上面的步驟將sdk導入,其餘配置按照接入文檔操做便可。ide

代碼部分:阿里雲

第一步:首次判斷當前設備網絡環境,有沒有運營商網絡 spa

        self.isEnable = [[TXCommonHandler sharedInstance] checkSyncGatewayVerifyEnable:nil];//判斷當前設備是否有移動運營商網絡code

        if (!self.isEnable) {orm

            [self.view hideToastActivity];token

            [KPToast showToastWithMessage:@"設備無移數據網絡 或 獲獲取供應商信息失敗"];

            return;

        }else{

            [self getLoginMobileAndToken];

        }

 

第二部:調用阿里雲sdk

#pragma mark ------ 調用一鍵登陸sdk

- (void)getLoginMobileAndToken{

    

    TXCustomModel *modelNew = [[TXCustomModel alloc] init];

    modelNew.navTitle = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSForegroundColorAttributeName : UIColor.blackColor,NSFontAttributeName : [UIFont systemFontOfSize:24.0]}];

    modelNew.navBackImage = [UIImage imageNamed:@"icon_nav_back_gray"];

    

    //logo

    modelNew.logoImage = [UIImage imageNamed:@"pf_login_icon"];

    modelNew.logoIsHidden = NO;

    modelNew.logoWidth = 200;

    modelNew.logoHeight = 90.0;

    modelNew.logoTopOffetY = self.ratio * 50.0;

    

    //xxxx運營商提供認證服務

    modelNew.sloganIsHidden = NO;

    modelNew.sloganText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@提供號碼認證服務",[TXCommonUtils getCurrentCarrierName]] attributes:@{NSForegroundColorAttributeName : UIColorFromRGB(0x333333),NSFontAttributeName : [UIFont systemFontOfSize:16.0]}];

    modelNew.sloganTopOffetY = self.ratio * 170.0;

    

    //手機號碼

    modelNew.numberColor = UIColorFromRGB(0x333333);

    modelNew.numberFont = [UIFont systemFontOfSize:20.0];

    modelNew.numberTopOffetY = self.ratio * 200.0;

   

    //登陸按鈕

    modelNew.loginBtnText = [[NSAttributedString alloc] initWithString:@"一鍵登陸" attributes:@{NSForegroundColorAttributeName : UIColor.whiteColor,NSFontAttributeName : [UIFont systemFontOfSize:20.0]}];

    modelNew.loginBtnTopOffetY = self.ratio * 270;

    modelNew.loginBtnHeight = 50.0;

    modelNew.loginBtnLRPadding = 18.0;

//    modelNew.loginBtnBgImgs = @[@"pf_loginBtn_bac",@"pf_loginBtn_bac",@"pf_loginBtn_bac"];

    

    //底部協議

    modelNew.privacyColors = @[UIColor.lightGrayColor,UIColorFromRGB(0x3c99fa)];

    modelNew.privacyBottomOffetY = self.ratio * 25.0;

    modelNew.privacyAlignment = NSTextAlignmentCenter;

    modelNew.privacyLRPadding = 8.0;

    modelNew.privacyFont = [UIFont systemFontOfSize:12.0];

    

    modelNew.checkBoxIsHidden = NO;

    modelNew.checkBoxIsChecked = YES;

    modelNew.checkBoxWH = 15.0;

    

    //切換到其餘方式

    modelNew.changeBtnTitle = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSForegroundColorAttributeName : UIColor.orangeColor,NSFontAttributeName : [UIFont systemFontOfSize:18.0]}];

    modelNew.changeBtnIsHidden = YES;//隱藏

    modelNew.changeBtnTopOffetY = self.ratio * 344;

    

    __weak KPLoginNewViewController *weakSelf = self;

    [[TXCommonHandler sharedInstance] getLoginTokenWithController:self model:modelNew timeout:self.time complete:^(NSDictionary * _Nonnull resultDic) {

        [self.view hideToastActivity];

        dispatch_async(dispatch_get_main_queue(), ^{

            NSString *code = [resultDic valueForKey:@"resultCode"];

            if ([code isEqualToString:TX_Auth_Result_Success]) {

                

            }else if ([code isEqualToString:TX_Login_SSO_Action]) {//成功登陸

                [weakSelf dismissViewControllerAnimated:YES completion:nil];

                NSString *token = [resultDic valueForKey:@"token"];

                NSLog(@"運營商token===%@",token);

                // 能夠去請求服務端getMobile接口,用token換取手機號碼啦

                    }else{

                        [weakSelf.view makeToast:@"登陸失敗"];

                    }

                } failure:^(NSString *errorStr, NSString *errorCode) {

                    [weakSelf.view makeToast:@"登陸失敗"];

                }];

                

            }else if ([code isEqualToString:TX_Login_Change_Action]) {//切換到其餘方式

 

            }else if ([code isEqualToString:TX_Login_Return_Action] || [code isEqualToString:TX_Login_AuthPage_Show_Success]) {

                

            }else {

                [weakSelf dismissViewControllerAnimated:YES completion:nil];

                NSLog(@"getLoginTokenWithController fail,resultDic = %@",resultDic);

                [KPToast showToastWithMessage:@"獲取登陸Token失敗"];

            }

#ifdef DEBUG

            NSLog(@"getLoginTokenWithController,resultDic = %@",[self jsonStrFromDic:resultDic]);

#endif

        });

    }];

}

 

代碼就這麼多,阿里雲第三方頁面能夠高度定製,靈活更改,有不懂的聯繫553502397@qq.com

相關文章
相關標籤/搜索