// // YOUPAILCVerCodeVC.m // VQU // // Created by 肖浩然的mac on 2021/8/2. // Copyright © 2021 leo. All rights reserved. // #import "YOUPAILCVerCodeVC.h" #import "YOUPAILCFinishMsgVC.h" #import #import "YOUPAILCBindPhoneAccountVC.h" #import "YOUPAILCSelectSexVC.h" #import "YOUPAIHWTFCursorView.h" #import "YOUPAILCWriteMesVC.h" @interface YOUPAILCVerCodeVC () /* 获取验证码 */ @property (strong, nonatomic) UIButton *youpaipverifyGetBtn; @property(nonatomic,strong)NSString* youpaippasteString; @property (nonatomic, weak) YOUPAIHWTFCursorView *youpaipcodeView; @end @implementation YOUPAILCVerCodeVC - (void)viewDidLoad { [super viewDidLoad]; [self youpaifsetupUI]; [self youpaifverifyGetBtnClick]; self.view.backgroundColor = [UIColor whiteColor]; } -(void)youpaifsetupUI{ //title UILabel *titleLabel = [UILabel new]; [self.view addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(40+NavBarHeight); make.left.mas_equalTo(27); }]; titleLabel.font = LCBoldFont(27); titleLabel.textColor = LZ273145Color; titleLabel.text = @"填写验证码"; //已发送提示 UILabel *hintLabel = [UILabel new]; [self.view addSubview:hintLabel]; [hintLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(titleLabel.mas_bottom).offset(21); make.left.mas_equalTo(titleLabel); }]; hintLabel.attributedText = [LCTools setRichTextWithTitle:@"已发送验证码至" subTitle:self.youpaipphoneNum titleColor:LZA3AABEColor subTitleColor:LZ273145Color titleFontSize:15 subTitleFontSize:15]; YOUPAIHWTFCursorView *codeView = [[YOUPAIHWTFCursorView alloc] initWithCount:4 margin:7 haveBorder:YES]; codeView.frame = CGRectMake(27, 140+NavBarHeight, KScreenWidth-54, 56); [codeView setBackgroundColor:[UIColor clearColor]]; [self.view addSubview:codeView]; codeView.delegate =self; self.youpaipcodeView = codeView; //获取验证码按钮 UIButton* showBtn = [[UIButton alloc]init]; [self.view addSubview:showBtn]; [showBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(codeView.mas_bottom).offset(100); make.left.mas_equalTo(ScaleSize(27)); make.right.mas_equalTo(-ScaleSize(27)); make.height.mas_equalTo(56); }]; self.youpaipverifyGetBtn = showBtn; showBtn.layer.cornerRadius = 56/2; showBtn.layer.masksToBounds = YES; showBtn.titleLabel.font = [UIFont systemFontOfSize:17]; showBtn.adjustsImageWhenHighlighted = NO; [showBtn setTitle:@"获取验证码" forState:UIControlStateNormal]; [showBtn setTitleColor:LZ273145Color forState:UIControlStateNormal]; [showBtn addTarget:self action:@selector(youpaifverifyGetBtnClick) forControlEvents:(UIControlEventTouchUpInside)]; [showBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth-ScaleSize(54), 56) FromColors:@[LZF7F8FAColor,LZF7F8FAColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)]; } -(void)youpaifinputFinished:(NSString *)inputStr{ [self youpaifloginBtnClick:inputStr]; } /* 手机号验证码登录 */ - (void)youpaifloginBtnClick:(NSString*)code{ // YOUPAILCSelectSexVC *msg = [[YOUPAILCSelectSexVC alloc]init]; // // [self.navigationController pushViewController:msg animated:YES]; //去掉手机号码的空格 [ZCHUDHelper showWithStatus:@"正在登录,请等待..."]; if ([ZCRegularHelper regularPhoneNumber:self.youpaipphoneNum]) { // if ([ZCRegularHelper regularVerifyCode4:self.pwdTextField.text]) { NSMutableDictionary* params = [NSMutableDictionary dictionary]; self.youpaippasteString = [LCTools getPasteString]; [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"]; [params setObject:@"1" forKey:@"agreement"]; [params setObject:self.youpaipphoneNum forKey:@"mobile"]; [params setObject:code forKey:@"phone_code"]; [LCHttpHelper requestWithURLString:PhoneCodeLogin 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 [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) {//未完善资料,进入完善资料页面 // YOUPAILCFinishMsgVC *msg = [[YOUPAILCFinishMsgVC alloc]init]; // YOUPAILCSelectSexVC *msg = [[YOUPAILCSelectSexVC alloc]init]; // msg.youpaipinviteCodeStr = self.youpaippasteString; // [self.navigationController pushViewController:msg animated:YES]; YOUPAILCWriteMesVC *vc = [YOUPAILCWriteMesVC new]; vc.youpaipinviteCodeStr = self.youpaippasteString; [self.navigationController pushViewController:vc animated:YES]; }else{//已经完善资料 // [LCSaveData saveLoginMark:YES]; [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token]; [LCTools changeRootToTabbar]; } [ZCHUDHelper showTitle:@"登录成功"]; }else{ [ZCHUDHelper showTitle:dict[@"message"]]; } } failure:^(NSError *error) { // [ZCHUDHelper dismiss]; [SVProgressHUD dismiss]; [SVProgressHUD showWithStatus:[NSString stringWithFormat:@"登陆失败:%@",[error localizedDescription]]]; // [ZCHUDHelper showTitle:[NSString stringWithFormat:@"登陆失败:%@",[error localizedDescription]]]; }]; // } } } -(void)youpaifverifyGetBtnClick{ if ([ZCRegularHelper regularPhoneNumber:self.youpaipphoneNum]) {//首先手机格式保证正确 [LCHttpHelper requestWithURLString:PhoneCode parameters:@{@"mobile":self.youpaipphoneNum,@"type":@"login"} needToken:NO type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [ZCHUDHelper showTitle:@"验证码已发送"]; __block int timeout=120; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue); dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行 dispatch_source_set_event_handler(_timer, ^{ if(timeout<=0){ dispatch_source_cancel(_timer); dispatch_async(dispatch_get_main_queue(), ^{ [self.youpaipverifyGetBtn setTitle:@"获取验证码" forState:UIControlStateNormal]; self.youpaipverifyGetBtn.userInteractionEnabled = YES; [self.youpaipverifyGetBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [self.youpaipverifyGetBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth-ScaleSize(54), 56) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)]; }); }else{ NSString *strTime = [NSString stringWithFormat:@"%.2dS",timeout]; dispatch_async(dispatch_get_main_queue(), ^{ //设置界面的按钮显示 根据自己需求设置 [self.youpaipverifyGetBtn setTitle:strTime forState:UIControlStateNormal]; self.youpaipverifyGetBtn.userInteractionEnabled = NO; [self.youpaipverifyGetBtn setTitleColor:LZ273145Color forState:UIControlStateNormal]; [self.youpaipverifyGetBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth-ScaleSize(54), 56) FromColors:@[LZF7F8FAColor,LZF7F8FAColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)]; }); timeout--; } }); dispatch_resume(_timer); } } failure:^(NSError *error) { }]; } } @end