| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759 |
- //
- // YOUPAIZYFirstVC.m
- // VQU
- //
- // Created by Elaine on 2020/6/9.
- // Copyright © 2020 leo. All rights reserved.
- //
- #import "YOUPAIZYFirstVC.h"
- #import "YOUPAILCFinishMsgVC.h"
- #import <UMShare/UMShare.h>
- #import "YOUPAILCBindPhoneAccountVC.h"
- #import "YOUPAILCLoginVC.h"
- #import "YOUPAILCGiftModel.h"
- #import "YOUPAILCSelectSexVC.h"
- #import <AuthenticationServices/AuthenticationServices.h>
- @interface YOUPAIZYFirstVC ()<UITextViewDelegate,ASAuthorizationControllerDelegate,ASAuthorizationControllerPresentationContextProviding>
- @property(nonatomic,strong)UIButton* youpaiploginBtn;
- @property(nonatomic,strong)UIView* youpaipthirdView;
- @property(nonatomic,strong)NSString* youpaippasteString;
- /* 是否同意协议 */
- @property (assign, nonatomic) BOOL youpaipisAgree;
- @end
- @implementation YOUPAIZYFirstVC
- - (UIStatusBarStyle)preferredStatusBarStyle{
- return UIStatusBarStyleLightContent;
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self.navigationController.navigationBar setHidden:YES];
- // [self youpaiftestALiLogin];
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self.navigationController.navigationBar setHidden:NO];
- }
- - (void)viewDidLoad {
-
-
-
- [super viewDidLoad];
- self.view.backgroundColor = LCBkgColor;
- self.youpaipisAgree = NO;
- [self youpaifsetupView];
- // [self youpaiftestALiLogin];
- [YOUPAILZChatRoomManager clear];
- }
- - (void)youpaifsetupView{
-
- //蒙版图片
- UIImageView*bgImageView = [[UIImageView alloc]init];
- [self.view addSubview:bgImageView];
- [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
- bgImageView.image = [UIImage imageNamed:@"vqu_images_ic_login_bg"];
- bgImageView.contentMode = UIViewContentModeScaleAspectFill;
- NSMutableAttributedString * str = [[NSMutableAttributedString alloc]initWithString:@"登录即同意《花蝶用户协议》和《隐私保护》"];
- [str addAttribute:NSLinkAttributeName value:@"protocol://" range:NSMakeRange(5,8)];
- [str addAttribute:NSLinkAttributeName value:@"privacy://" range:NSMakeRange(14,6)];
- UITextView * textview = [[UITextView alloc]init];
- textview.editable = NO;
- textview.scrollEnabled = NO;
- textview.delegate = self;
- textview.backgroundColor = [UIColor clearColor];
- textview.font = LCFont12;
- textview.attributedText = str;
- textview.textColor = LZA3AABEColor;
- textview.textAlignment = NSTextAlignmentCenter;
- textview.linkTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],
- NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleNone]
- };
-
-
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:LCFont(10.0f) forKey:NSFontAttributeName];
- CGSize size = [textview.text boundingRectWithSize:CGSizeMake(MAXFLOAT, 10.0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
- UIView *xiyiBgView = [UIView new];
- [self.view addSubview:xiyiBgView];
- [xiyiBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(size.width+45);
- make.centerX.mas_equalTo(0);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-40);
- make.height.mas_equalTo(@30);
- }];
- [xiyiBgView addSubview:textview];
- //是否同意按钮
- UIButton *xiyiBtn = [UIButton new];
- [xiyiBgView addSubview:xiyiBtn];
- [xiyiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.centerY.mas_equalTo(0);
- make.size.mas_equalTo(CGSizeMake(40, 30));
- }];
- [xiyiBtn setImage:[UIImage imageNamed:@"vqu_images_first_xiyi_n"] forState:UIControlStateNormal];
- [xiyiBtn setImage:[UIImage imageNamed:@"vqu_images_first_xiyi_s"] forState:UIControlStateSelected];
- [xiyiBtn addTarget:self action:@selector(youpaifxiyiBtnClick:) forControlEvents:UIControlEventTouchUpInside];
-
- [textview makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(0);
- make.height.mas_equalTo(@30);
- make.left.mas_equalTo(xiyiBtn.mas_right).offset(-15);
- }];
-
-
-
- UIView* thirdView = [[UIView alloc]init];
- // thirdView.backgroundColor = [UIColor redColor];
- [self.view addSubview:thirdView];
- self.youpaipthirdView = thirdView;
- [thirdView makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(0);
- make.width.equalTo(216.0f);
- make.bottom.equalTo(textview.mas_top).offset(-10);
- make.height.equalTo(@40);
- }];
-
- [self youpaifsetupThirdView];
- //其他label
- UILabel *otherLabel = [UILabel new];
- [self.view addSubview:otherLabel];
- [otherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(0);
- make.bottom.equalTo(thirdView.mas_top).offset(-22);
-
- }];
- otherLabel.text = @"其他登录方式";
- otherLabel.font = [UIFont systemFontOfSize:12];
- otherLabel.textColor = LZA3AABEColor;
- otherLabel.userInteractionEnabled = YES;
- // UITapGestureRecognizer *otherLabelTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifotherLabelPush)];
- // [otherLabel addGestureRecognizer:otherLabelTap];
-
- // otherLabel.hidden = YES;
- UIImageView*avatar = [[UIImageView alloc]init];
- [self.view addSubview:avatar];
- [avatar mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(ScaleHeight(99)+StatusBarHeight);
- make.size.mas_equalTo(CGSizeMake(133, 152));
- make.centerX.mas_equalTo(0);
- }];
- avatar.image = [UIImage imageNamed:@"vqu_images_appBg"];
- avatar.contentMode = UIViewContentModeScaleAspectFit;
-
-
- UIButton* loginBtn = [[UIButton alloc]init];
- self.youpaiploginBtn = loginBtn;
- loginBtn.uxy_acceptEventInterval = 3.0;
- loginBtn.layer.cornerRadius = 28.0f;
- loginBtn.layer.masksToBounds = YES;
- loginBtn.titleLabel.font = LCFont17;
- [loginBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
- [loginBtn setTitle:@"本机一键登录" forState:(UIControlStateNormal)];
- [loginBtn addTarget:self action:@selector(youpaifloginBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
- [self.view addSubview:loginBtn];
- [loginBtn makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(otherLabel.mas_top).offset(-108);
- make.centerX.equalTo(0);
- make.size.mas_equalTo(CGSizeMake(KScreenWidth-54, 56));
- }];
-
- [self.youpaiploginBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth-54, 56) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:1] forState:UIControlStateNormal];
-
-
-
-
-
-
- }
- // 其他登录
- -(void)youpaifotherLabelPush{
- if (self.youpaipisAgree == NO) {
- [ZCHUDHelper showTitle:@"请先同意协议"];
- return;
- }
- YOUPAILCLoginVC *vc = [YOUPAILCLoginVC new];
- [self.navigationController pushViewController:vc animated:YES];
- }
- -(void)youpaifxiyiBtnClick:(UIButton*)sender{
- sender.selected = !sender.selected;
- if (sender.selected) {
-
-
- self.youpaipisAgree = YES;
- }else{
-
-
- self.youpaipisAgree = NO;
- }
-
- }
- - (void)youpaifsetupThirdView{
- NSMutableArray *items = [NSMutableArray array];
- if (@available(iOS 13.0, *)) {
- [items addObject:@{
- @"image":@"vqu_images_sign_appleid",
- @"index":@(1)
- }];
- }
- [items addObject:@{
- @"image":@"vqu_images_sign_weixin",
- @"index":@(2)
- }];
- [items addObject:@{
- @"image":@"vqu_images_sign_qq",
- @"index":@(3)
- }];
- CGFloat width = 40 * items.count + 48 * (items.count - 1);
- CGFloat startX = (216.0f - width) / 2.0f;
- for (int i = 0; i < items.count; i++) {
- CGFloat x = startX + (40+48)*i;
- UIButton* button = [[UIButton alloc]initWithFrame:CGRectMake(x,0, 40, 40)];
-
- [button setImage:[UIImage imageNamed:items[i][@"image"]] forState:(UIControlStateNormal)];
- // weChatBtn.btnString = images[i];
- button.tag = [items[i][@"index"] integerValue];
- [button addTarget:self action:@selector(youpaifthirdClick:) forControlEvents:(UIControlEventTouchUpInside)];
- [self.youpaipthirdView addSubview:button];
- }
-
-
- // NSInteger count = images.count;
- // if (count==1){
- // TLSThirdLoginBtn* weChatBtn = [[TLSThirdLoginBtn alloc]initWithFrame:CGRectMake(KScreenWidth/2-30-20, 20, 40, 40)];
- // [weChatBtn setImage:[UIImage imageNamed:images[0]] forState:(UIControlStateNormal)];
- // weChatBtn.btnString = images[0];
- // [weChatBtn addTarget:self action:@selector(youpaifthirdClick:) forControlEvents:(UIControlEventTouchUpInside)];
- // [self.thirdView addSubview:weChatBtn];
- // }else if (count ==2){
- // for (int i =0; i<count; i++) {
- // TLSThirdLoginBtn* weChatBtn = [[TLSThirdLoginBtn alloc]initWithFrame:CGRectMake(KScreenWidth/2-30-30-40+100*i, 25, 40, 40)];
- // [weChatBtn setImage:[UIImage imageNamed:images[i]] forState:(UIControlStateNormal)];
- // weChatBtn.btnString = images[i];
- // [weChatBtn addTarget:self action:@selector(youpaifthirdClick:) forControlEvents:(UIControlEventTouchUpInside)];
- // [self.thirdView addSubview:weChatBtn];
- // }
- // }else if (count ==3){
- // for (int i =0; i<count; i++) {
- // TLSThirdLoginBtn* weChatBtn = [[TLSThirdLoginBtn alloc]initWithFrame:CGRectMake(KScreenWidth/2-30-20-100+100*i, 25, 40, 40)];
- // [weChatBtn setImage:[UIImage imageNamed:images[i]] forState:(UIControlStateNormal)];
- // weChatBtn.btnString = images[i];
- // [weChatBtn addTarget:self action:@selector(youpaifthirdClick:) forControlEvents:(UIControlEventTouchUpInside)];
- // [self.thirdView addSubview:weChatBtn];
- // }
- // }
- }
- #pragma mark - 手机号码登录
- -(void)youpaiftestALiLogin{
-
-
- // [[TXCommonHandler sharedInstance]checkEnvAvailableWithAuthType:PNSAuthTypeLoginToken complete:^(NSDictionary * _Nullable resultDic) {//检测是否支持一键登录
- // NSLog(@"%@",resultDic);
- // NSString *code = resultDic[@"resultCode"];
- //
- // if (![code isEqualToString:@"600000"]) {
- // YOUPAILCLoginVC *vc = [YOUPAILCLoginVC new];
- //
- // [self.navigationController pushViewController:vc animated:YES];
- // return;
- // }
- //
- // }];
- //
-
- TXCustomModel *model = [PNSBuildModelUtils buildModelWithStyle:PNSBuildModelStyleAutorotate
- button1Title:@""
- target1:nil
- selector1:nil
- button2Title:@""
- target2:nil
- selector2:nil];
-
-
-
- model.navColor = [UIColor clearColor];
-
- // model.alertContentViewColor = LCBkgColor;
- // model.alertTitleBarColor = LCBkgColor;
- // model.alertCloseItemIsHidden = YES;
- // model.alertTitle = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSForegroundColorAttributeName:HexColorFromRGB(0xffffff),NSFontAttributeName:[UIFont systemFontOfSize:15]}];
- // model.alertCornerRadiusArray = @[@0,@0,@0,@0];
- // model.contentViewFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- // frame.size.width = KScreenWidth;
- // frame.size.height = KScreenHeight;
- // frame.origin.y = 0;
- // frame.origin.x = 0;
- // return frame;
- // };
-
- model.presentDirection = PNSPresentationDirectionRight;
- model.preferredStatusBarStyle = UIStatusBarStyleLightContent;
- model.navTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:@{NSForegroundColorAttributeName:HexColorFromRGB(0xffffff),NSFontAttributeName:[UIFont systemFontOfSize:15]}];
- model.navBackImage = [UIImage imageNamed:@"vqu_images_navigation_back_white"];
- model.navTitle = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSForegroundColorAttributeName:HexColorFromRGB(0x333333),NSFontAttributeName:[UIFont systemFontOfSize:15]}];
- model.logoImage = [UIImage imageNamed:@"vqu_images_ali_appBg"];
- model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.size.width = 133;
- frame.size.height = 133;
- frame.origin.y =ScaleHeight(56);
- frame.origin.x = (superViewSize.width - 133) * 0.5;
- return frame;
- };
-
-
-
- // vqu_images_ali_LoginBtn
-
- model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
-
- frame.origin.y = ScaleHeight(284)-StatusBarHeight;
- return frame;
- };
-
- model.sloganText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@提供认证服务",[TXCommonUtils getCurrentCarrierName]] attributes:@{NSForegroundColorAttributeName:HexColorFromRGB(0xA3AABE),NSFontAttributeName:[UIFont systemFontOfSize:11]}];
- CGFloat otherHight = 0;
- if ([[UIScreen mainScreen]bounds].size.height>667) {
- otherHight = 60;
- }else{
- otherHight = 20;
- }
-
- model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.origin.y = ScaleHeight(100 + 124 + otherHight)-StatusBarHeight;
- return frame;
- };
- model.numberColor = [UIColor whiteColor];
- model.numberFont = [UIFont systemFontOfSize:25];
- UIImage *im = [UIImage imageNamed:@"vqu_images_ali_LoginBtn"];
- UIImage *im4 = [UIImage imageNamed:@"vqu_images_ali_loginNor"];
-
-
- model.loginBtnBgImgs = @[im,im4,im];
- model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
-
- frame.size.width = 321;
- frame.size.height = 56;
- frame.origin.x = (superViewSize.width - 321) * 0.5;
- frame.origin.y = ScaleHeight(319 + 20 + 30)-StatusBarHeight;
- return frame;
- };
-
- model.changeBtnTitle = [LCTools setRichTextWithTitle:@"其他手机号登录 " subTitle:@">" titleColor:[UIColor whiteColor] subTitleColor:HexColorFromRGB(0x9F9DA5) titleFontSize:12 subTitleFontSize:12];
- [model setChangeBtnFrameBlock:^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.size.width = 150;
- frame.size.height = 25;
- frame.origin.y = ScaleHeight(369+20+48)-StatusBarHeight;
- frame.origin.x = (superViewSize.width - 150) * 0.5;
- return frame;
-
- }];
-
- UIImage *im1 = [UIImage imageNamed:@"vqu_images_ali_loginN"];
- UIImage *im2 = [UIImage imageNamed:@"vqu_images_ali_loginS"];
- model.checkBoxImages = @[im1,im2];
- model.privacyOne = @[@"",@""];
- model.privacyConectTexts = @[@""];
- // model.checkBoxWH = 25;
- model.privacyColors = @[HexColorFromRGB(0x9F9DA5),HexColorFromRGB(0xffffff)];
-
- [model setPrivacyFrameBlock:^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
- frame.size.width = KScreenWidth;
- frame.size.height = 25;
- frame.origin.y = KScreenHeight-ScaleHeight(47+25)-StatusBarHeight-SafeHeight;
- frame.origin.x = 0;
- return frame;
- }];
- [model setCustomViewBlock:^(UIView * _Nonnull superCustomView) {
- superCustomView.backgroundColor = LCBkgColor;
-
- UIImageView*bgImageView = [[UIImageView alloc]init];
- [superCustomView addSubview:bgImageView];
- [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
- bgImageView.image = [UIImage imageNamed:@"vqu_images_ic_login_bg"];
- bgImageView.contentMode = UIViewContentModeScaleAspectFill;
-
- }];
- model.privacyAlignment = NSTextAlignmentCenter;
- __weak typeof(self) weakSelf = self;
-
- [[TXCommonHandler sharedInstance] getLoginTokenWithTimeout:3.0
- controller:self
- model:model
- complete:^(NSDictionary * _Nonnull resultDic) {
- NSString *resultCode = [resultDic objectForKey:@"resultCode"];
- if ([PNSCodeLoginControllerPresentSuccess isEqualToString:resultCode]) {
- NSLog(@"授权页拉起成功回调:%@", resultDic);
- [ZCHUDHelper dismiss];
- } else if ([PNSCodeLoginControllerClickCancel isEqualToString:resultCode] ||
- [PNSCodeLoginControllerClickChangeBtn isEqualToString:resultCode] ||
- [PNSCodeLoginControllerClickLoginBtn isEqualToString:resultCode] ||
- [PNSCodeLoginControllerClickCheckBoxBtn isEqualToString:resultCode] ||
- [PNSCodeLoginControllerClickProtocol isEqualToString:resultCode]) {
- if ([PNSCodeLoginControllerClickChangeBtn isEqualToString:resultCode]) {//其他登录
- // UINavigationController *navigationController = weakSelf.navigationController;
- // if (weakSelf.presentedViewController) {
- // //如果授权页成功拉起,这个时候则需要使用授权页的导航控制器进行跳转
- // navigationController = (UINavigationController *)weakSelf.presentedViewController;
- // }
-
- [self dismissViewControllerAnimated:NO completion:^{
-
- }];
- YOUPAILCLoginVC *vc = [YOUPAILCLoginVC new];
-
- [weakSelf.navigationController pushViewController:vc animated:NO];
-
-
- }else if ([PNSCodeLoginControllerClickLoginBtn isEqualToString:resultCode]) {
- if ([[resultDic objectForKey:@"isChecked"] boolValue] == NO) {
- [ZCHUDHelper showTitle:@"请阅读并同意服务条款"];
- } else {
-
- }
- }
- NSLog(@"页面点击事件回调:%@", resultDic);
- } else if ([PNSCodeSuccess isEqualToString:resultCode]) {
- NSLog(@"获取LoginToken成功回调:%@", resultDic);
- NSString *token = [resultDic objectForKey:@"token"];
- NSLog(@"接下来可以拿着Token去服务端换取手机号,有了手机号就可以登录,SDK提供服务到此结束");
- [weakSelf youpaifToOncePhoneLogin:token];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [[TXCommonHandler sharedInstance] cancelLoginVCAnimated:YES complete:nil];
- });
- } else {
-
- NSLog(@"获取LoginToken或拉起授权页失败回调:%@", resultDic);
- [ZCHUDHelper dismiss];
- YOUPAILCLoginVC *vc = [YOUPAILCLoginVC new];
- [weakSelf.navigationController pushViewController:vc animated:YES];
- //失败后可以跳转到短信登录界面
- // PNSSmsLoginController *controller = [[PNSSmsLoginController alloc] init];
- // controller.isHiddenNavgationBar = NO;
- // UINavigationController *navigationController = weakSelf.navigationController;
- // if (weakSelf.presentedViewController) {
- // //如果授权页成功拉起,这个时候则需要使用授权页的导航控制器进行跳转
- // navigationController = (UINavigationController *)weakSelf.presentedViewController;
- // }
- // [navigationController pushViewController:controller animated:YES];
- }
- }];
- }
- //一键手机登录
- -(void)youpaifToOncePhoneLogin:(NSString*)tokenStr{
-
-
- [ZCHUDHelper showWithStatus:@"正在登录,请等待..."];
- self.youpaippasteString = [LCTools getPasteString];
- NSMutableDictionary* params = [NSMutableDictionary dictionary];
- [params setObject:tokenStr forKey:@"accessToken"];
- [params setObject:@"1" forKey:@"agreement"];
- [params setObject:[LCTools getbindData]?[LCTools getbindData]:@"" forKey:@"invite_code"];
- [params setObject:[LCTools getbindData]?[LCTools getbindData]:@"" forKey:@"bindData"];
- [params setObject:[LCTools getchannelCode]?[LCTools getchannelCode]:@"" forKey:@"channelCode"];
- [LCHttpHelper requestWithURLString:OncePhoneLogin parameters:params needToken:NO type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- YOUPAILCUserModel* userModel = [YOUPAILCUserModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
- [LCSaveModel saveUserModel:userModel];
- [LCSaveData saveTokenString:userModel.youpaipuserinfo.youpaiptoken];//保存token
- [MobClick profileSignInWithPUID:userModel.youpaipuserinfo.youpaipuser_id];
- [LCHttpHelper requestWithURLString:GiftConfig parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSLog(@"GiftConfig == %@",dict);
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- NSMutableArray *giftArray = [NSMutableArray array];
- giftArray = [YOUPAILCGiftModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"gift_list"]];
- for (int i = 0; i< giftArray.count; i++) {
- YOUPAILCGiftModel *model = giftArray[i];
- if (model.youpaipsvga.length> 0 ) {
- [LCTools giftSVGAWithSvgaUrlStr:model.youpaipsvga];
- }
- }
- }
- } failure:^(NSError *error) {
- }];
- if (userModel.youpaipuserinfo.youpaiptype ==2) {
- //是特殊用户
- [LCSaveData saveIsspecial:YES];
- }
- if (userModel.youpaipuserinfo.youpaipfinish_status==0) {//未完善资料,进入完善资料页面
- YOUPAILCSelectSexVC *msg = [[YOUPAILCSelectSexVC alloc]init];
- self.youpaippasteString = [LCTools getPasteString];
- msg.youpaipinviteCodeStr = self.youpaippasteString;
- [self.navigationController pushViewController:msg animated:YES];
- }else{//已经完善资料
- // [LCSaveData saveLoginMark:YES];
- [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
- // [LCTools changeRootToTabbar];
- }
- [ZCHUDHelper showTitle:@"登录成功"];
- }
- } failure:^(NSError *error) {
- }];
- }
- /*
- 登陆
- */
- - (void)youpaifloginBtnClick{
-
- if (self.youpaipisAgree == NO) {
- [ZCHUDHelper showTitle:@"请先同意协议"];
- return;
- }
- [self youpaiftestALiLogin];
-
-
- }
- #pragma mark --UITextViewDelegate
- - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction{
- ZCBaseWebVC * vc = [[ZCBaseWebVC alloc]init];
- if ([[URL scheme]isEqualToString:@"protocol"]) {//进入协议页面
- vc.contentUrl = [NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserProtocolH5];
- [self.navigationController pushViewController:vc animated:YES];
- return NO;
- }
- if ([[URL scheme]isEqualToString:@"privacy"]) {////进入隐私政策
- vc.contentUrl = [NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserPrivacyH5];
- [self.navigationController pushViewController:vc animated:YES];
- return NO;
- }
- return YES;
- }
- #pragma mark --第三方登录
- - (void)youpaifthirdClick:(UIButton*)btn{
- if (self.youpaipisAgree == NO) {
- [ZCHUDHelper showTitle:@"请先同意协议"];
- return;
- }
-
- switch (btn.tag) {
- case 1://weixin
- // [self youpaifgetUserInfoForPlatform:(UMSocialPlatformType_QQ)];
- [self didAppleButton];
-
-
- break;
- case 2://apple id
- [self youpaifgetUserInfoForPlatform:(UMSocialPlatformType_WechatSession)];
- break;
- case 3://apple id
- [self youpaifgetUserInfoForPlatform:(UMSocialPlatformType_QQ)];
- break;
-
- default:
- break;
- }
-
- // if ([btn.btnString isEqualToString:@"vqu_images_sign_weixin"]) {
- // [self youpaifgetUserInfoForPlatform:(UMSocialPlatformType_WechatSession)];
- // }else if([btn.btnString isEqualToString:@"ic_sign_weibo"]){
- // [self youpaifgetUserInfoForPlatform:(UMSocialPlatformType_Sina)];
- // }else if([btn.btnString isEqualToString:@"vqu_images_sign_qq"]){
- // [self youpaifgetUserInfoForPlatform:(UMSocialPlatformType_QQ)];
- // }
- }
- #pragma mark --- appid登录
- - (void)didAppleButton {
- if (@available(iOS 13.0, *)) {
- // 基于用户的Apple ID授权用户,生成用户授权请求的一种机制
- ASAuthorizationAppleIDProvider *appleIDProvider = [[ASAuthorizationAppleIDProvider alloc] init];
- // 创建新的AppleID 授权请求
- ASAuthorizationAppleIDRequest *appleIDRequest = [appleIDProvider createRequest];
- // 在用户授权期间请求的联系信息
- appleIDRequest.requestedScopes = @[ASAuthorizationScopeFullName, ASAuthorizationScopeEmail];
- // 由ASAuthorizationAppleIDProvider创建的授权请求 管理授权请求的控制器
- ASAuthorizationController *authorizationController = [[ASAuthorizationController alloc] initWithAuthorizationRequests:@[appleIDRequest]];
- // 设置授权控制器通知授权请求的成功与失败的代理
- authorizationController.delegate = self;
- // 设置提供 展示上下文的代理,在这个上下文中 系统可以展示授权界面给用户
- authorizationController.presentationContextProvider = self;
- // 在控制器初始化期间启动授权流
- [authorizationController performRequests];
- }
-
- }
- #pragma mark - ASAuthorizationControllerDelegate
- /// Apple登录授权出错
- - (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error API_AVAILABLE(ios(13.0)) {
- NSString *errorMsg = nil;
- switch (error.code) {
- case ASAuthorizationErrorCanceled:
- errorMsg = @"取消了授权请求";
- break;
- case ASAuthorizationErrorFailed:
- errorMsg = @"授权请求失败";
- break;
- case ASAuthorizationErrorInvalidResponse:
- errorMsg = @"授权请求响应无效";
- break;
- case ASAuthorizationErrorNotHandled:
- errorMsg = @"未能处理授权请求";
- break;
- case ASAuthorizationErrorUnknown:
- errorMsg = @"授权请求失败未知原因";
- break;
-
- default:
- break;
- }
- if (errorMsg.length != 0) {
- [ZCHUDHelper showTitle:errorMsg];
- }
- }
- /// Apple登录授权成功
- - (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization API_AVAILABLE(ios(13.0)) {
- Class credentialClass = [authorization.credential class];
- if (credentialClass == [ASAuthorizationAppleIDCredential class]) {
- // 用户登录使用的是: ASAuthorizationAppleIDCredential,授权成功后可以取到苹果返回的全部数据,然后再与后台交互
- ASAuthorizationAppleIDCredential *credential = (ASAuthorizationAppleIDCredential *)authorization.credential;
-
- NSString *userID = credential.user;
- // NSString *state = credential.state;
- // NSArray<ASAuthorizationScope> *authorizedScopes = credential.authorizedScopes;
- // // refresh_token
- // NSString *authorizationCode = [[NSString alloc] initWithData:credential.authorizationCode encoding:NSUTF8StringEncoding];
- // access_token
- NSString *identityToken = [[NSString alloc] initWithData:credential.identityToken encoding:NSUTF8StringEncoding];
- // NSString *email = credential.email;
- // NSPersonNameComponents *fullName = credential.fullName;
- // ASUserDetectionStatus realUserStatus = credential.realUserStatus;
-
- [self youpaifbindThirdWithOpenid:userID typeStr:@"ios" accessToken:identityToken];
- //这里我只用到了userID,email,[NSString stringWithFormat:@"%@%@", fullName.familyName, fullName.givenName]
- //接下来就调用自己服务器接口
- } else if (credentialClass == [ASPasswordCredential class]) {
- // 用户登录使用的是: 现有密码凭证
- ASPasswordCredential *credential = (ASPasswordCredential *)authorization.credential;
- NSString *user = credential.user; // 密码凭证对象的用户标识(用户的唯一标识)
- NSString *password = credential.password;
- NSLog(@"Apple登录_现有密码凭证: %@, %@", user, password);
- }
- }
- - (void)youpaifgetUserInfoForPlatform:(UMSocialPlatformType)platformType
- {
- [[UMSocialManager defaultManager] getUserInfoWithPlatform:platformType currentViewController:nil completion:^(id result, NSError *error) {
- if (error) {
- NSLog(@"%@",error);
- } else {
- // UMSocialGlobal 默认isClearCacheWhenGetUserInfo 为 YES,每次都清除缓存
- UMSocialUserInfoResponse *resp = result;
- // 授权数据
- NSLog(@" uid: %@", resp.uid);
- NSLog(@" openid: %@", resp.openid);
- NSLog(@" accessToken: %@", resp.accessToken);
- NSLog(@" refreshToken: %@", resp.refreshToken);
- NSLog(@" expiration: %@", resp.expiration);
- // 用户数据
- NSLog(@" name: %@", resp.name);
- NSLog(@" iconurl: %@", resp.iconurl);
- NSLog(@" gender: %@", resp.gender);
- NSString* typeStr;
- if (resp.platformType == UMSocialPlatformType_QQ) {
- typeStr = @"qq";
- }else if(resp.platformType == UMSocialPlatformType_Sina){
- typeStr = @"weibo";
- }else if(resp.platformType == UMSocialPlatformType_WechatSession){
- typeStr = @"wechat";
- }
- // 第三方平台SDK原始数据
- NSLog(@" originalResponse: %@", resp.originalResponse);
- [self youpaifbindThirdWithOpenid:resp.uid typeStr:typeStr accessToken:resp.accessToken];
- }
- }];
- }
- - (void)youpaifbindThirdWithOpenid:(NSString *)openid typeStr:(NSString *)typeStr accessToken:(NSString *)access_token{
- // NSString* typeStr;
- // if (response.platformType == UMSocialPlatformType_QQ) {
- // typeStr = @"qq";
- // }else if(response.platformType == UMSocialPlatformType_Sina){
- // typeStr = @"weibo";
- // }else if(response.platformType == UMSocialPlatformType_WechatSession){
- // typeStr = @"wechat";
- // }
- self.youpaippasteString = [LCTools getPasteString];
- NSMutableDictionary* params = [NSMutableDictionary dictionary];
- [params setObject:[LCTools getbindData]?[LCTools getbindData]:@"" forKey:@"bindData"];
- [params setObject:[LCTools getchannelCode]?[LCTools getchannelCode]:@"" forKey:@"channelCode"];
-
- [params setObject:typeStr forKey:@"platform"];
- [params setObject:openid forKey:@"openid"];
- [params setObject:access_token forKey:@"access_token"];
- [params setObject:[LCTools getbindData]?[LCTools getbindData]:@"" forKey:@"invite_code"];
-
- [LCHttpHelper requestWithURLString:ThirdLogin parameters:params needToken:NO type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- YOUPAILCUserModel* userModel = [YOUPAILCUserModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
- [LCSaveModel saveUserModel:userModel];
- [LCSaveData saveTokenString:userModel.youpaipuserinfo.youpaiptoken];//保存token
- [MobClick profileSignInWithPUID:userModel.youpaipuserinfo.youpaipuser_id];
- if (userModel.youpaipuserinfo.youpaiptype ==2) {
- [LCSaveData saveIsspecial:YES];
- }
- if (userModel.youpaipuserinfo.youpaipfinish_status==0) {//未完善资料\
-
- [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
-
- // YOUPAILCFinishMsgVC *msg = [[YOUPAILCFinishMsgVC alloc]init];
- // [self.navigationController pushViewController:msg animated:YES];
- }else{//已经完善资料
- if(userModel.youpaipuserinfo.youpaipmobile!=nil&&userModel.youpaipuserinfo.youpaipmobile.length>9)
- {
- // [LCSaveData saveLoginMark:YES];
- [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
- // [LCTools changeRootToTabbar];
- }
- else
- {
- /*
- YOUPAILCBindPhoneAccountVC *bind = [[YOUPAILCBindPhoneAccountVC alloc]init];
- bind.inLogin = YES;
- [self.navigationController pushViewController:bind animated:YES];
- */
- // [LCSaveData saveLoginMark:YES];
- [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
- // [LCTools changeRootToTabbar];
- }
- }
- }
- } failure:^(NSError *error) {
- }];
- }
- @end
|