YOUPAILCVerCodeVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // YOUPAILCVerCodeVC.m
  3. // VQU
  4. //
  5. // Created by 肖浩然的mac on 2021/8/2.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILCVerCodeVC.h"
  9. #import "YOUPAILCFinishMsgVC.h"
  10. #import <UMShare/UMShare.h>
  11. #import "YOUPAILCBindPhoneAccountVC.h"
  12. #import "YOUPAILCSelectSexVC.h"
  13. #import "YOUPAIHWTFCursorView.h"
  14. #import "YOUPAILCWriteMesVC.h"
  15. @interface YOUPAILCVerCodeVC ()<TFCodeViewDelegate>
  16. /* 获取验证码 */
  17. @property (strong, nonatomic) UIButton *youpaipverifyGetBtn;
  18. @property(nonatomic,strong)NSString* youpaippasteString;
  19. @property (nonatomic, weak) YOUPAIHWTFCursorView *youpaipcodeView;
  20. @end
  21. @implementation YOUPAILCVerCodeVC
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self youpaifsetupUI];
  25. [self youpaifverifyGetBtnClick];
  26. self.view.backgroundColor = [UIColor whiteColor];
  27. }
  28. -(void)youpaifsetupUI{
  29. //title
  30. UILabel *titleLabel = [UILabel new];
  31. [self.view addSubview:titleLabel];
  32. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.top.mas_equalTo(40+NavBarHeight);
  34. make.left.mas_equalTo(27);
  35. }];
  36. titleLabel.font = LCBoldFont(27);
  37. titleLabel.textColor = LZ273145Color;
  38. titleLabel.text = @"填写验证码";
  39. //已发送提示
  40. UILabel *hintLabel = [UILabel new];
  41. [self.view addSubview:hintLabel];
  42. [hintLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.top.mas_equalTo(titleLabel.mas_bottom).offset(21);
  44. make.left.mas_equalTo(titleLabel);
  45. }];
  46. hintLabel.attributedText = [LCTools setRichTextWithTitle:@"已发送验证码至" subTitle:self.youpaipphoneNum titleColor:LZA3AABEColor subTitleColor:LZ273145Color titleFontSize:15 subTitleFontSize:15];
  47. YOUPAIHWTFCursorView *codeView = [[YOUPAIHWTFCursorView alloc] initWithCount:4 margin:7 haveBorder:YES];
  48. codeView.frame = CGRectMake(27, 140+NavBarHeight, KScreenWidth-54, 56);
  49. [codeView setBackgroundColor:[UIColor clearColor]];
  50. [self.view addSubview:codeView];
  51. codeView.delegate =self;
  52. self.youpaipcodeView = codeView;
  53. //获取验证码按钮
  54. UIButton* showBtn = [[UIButton alloc]init];
  55. [self.view addSubview:showBtn];
  56. [showBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.top.mas_equalTo(codeView.mas_bottom).offset(100);
  58. make.left.mas_equalTo(ScaleSize(27));
  59. make.right.mas_equalTo(-ScaleSize(27));
  60. make.height.mas_equalTo(56);
  61. }];
  62. self.youpaipverifyGetBtn = showBtn;
  63. showBtn.layer.cornerRadius = 56/2;
  64. showBtn.layer.masksToBounds = YES;
  65. showBtn.titleLabel.font = [UIFont systemFontOfSize:17];
  66. showBtn.adjustsImageWhenHighlighted = NO;
  67. [showBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
  68. [showBtn setTitleColor:LZ273145Color forState:UIControlStateNormal];
  69. [showBtn addTarget:self action:@selector(youpaifverifyGetBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  70. [showBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth-ScaleSize(54), 56) FromColors:@[LZF7F8FAColor,LZF7F8FAColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
  71. }
  72. -(void)youpaifinputFinished:(NSString *)inputStr{
  73. [self youpaifloginBtnClick:inputStr];
  74. }
  75. /*
  76. 手机号验证码登录
  77. */
  78. - (void)youpaifloginBtnClick:(NSString*)code{
  79. // YOUPAILCSelectSexVC *msg = [[YOUPAILCSelectSexVC alloc]init];
  80. //
  81. // [self.navigationController pushViewController:msg animated:YES];
  82. //去掉手机号码的空格
  83. [ZCHUDHelper showWithStatus:@"正在登录,请等待..."];
  84. if ([ZCRegularHelper regularPhoneNumber:self.youpaipphoneNum]) {
  85. // if ([ZCRegularHelper regularVerifyCode4:self.pwdTextField.text]) {
  86. NSMutableDictionary* params = [NSMutableDictionary dictionary];
  87. self.youpaippasteString = [LCTools getPasteString];
  88. [params setObject:[LCTools getbindData]?[LCTools getbindData]:@"" forKey:@"invite_code"];
  89. [params setObject:[LCTools getbindData]?[LCTools getbindData]:@"" forKey:@"bindData"];
  90. [params setObject:[LCTools getchannelCode]?[LCTools getchannelCode]:@"" forKey:@"channelCode"];
  91. [params setObject:@"1" forKey:@"agreement"];
  92. [params setObject:self.youpaipphoneNum forKey:@"mobile"];
  93. [params setObject:code forKey:@"phone_code"];
  94. [LCHttpHelper requestWithURLString:PhoneCodeLogin parameters:params needToken:NO type:(HttpRequestTypePost) success:^(id responseObject) {
  95. NSDictionary* dict = (NSDictionary*)responseObject;
  96. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  97. if (code==0) {//成功
  98. YOUPAILCUserModel* userModel = [YOUPAILCUserModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  99. [LCSaveModel saveUserModel:userModel];
  100. [LCSaveData saveTokenString:userModel.youpaipuserinfo.youpaiptoken];//保存token
  101. [LCHttpHelper requestWithURLString:GiftConfig parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  102. NSDictionary* dict = (NSDictionary*)responseObject;
  103. NSLog(@"GiftConfig == %@",dict);
  104. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  105. if (code==0) {//成功
  106. NSMutableArray *giftArray = [NSMutableArray array];
  107. giftArray = [YOUPAILCGiftModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"gift_list"]];
  108. for (int i = 0; i< giftArray.count; i++) {
  109. YOUPAILCGiftModel *model = giftArray[i];
  110. if (model.youpaipsvga.length> 0 ) {
  111. [LCTools giftSVGAWithSvgaUrlStr:model.youpaipsvga];
  112. }
  113. }
  114. }
  115. } failure:^(NSError *error) {
  116. }];
  117. if (userModel.youpaipuserinfo.youpaiptype ==2) {
  118. //是特殊用户
  119. [LCSaveData saveIsspecial:YES];
  120. }
  121. if (userModel.youpaipuserinfo.youpaipfinish_status==0) {//未完善资料,进入完善资料页面
  122. // YOUPAILCFinishMsgVC *msg = [[YOUPAILCFinishMsgVC alloc]init];
  123. // YOUPAILCSelectSexVC *msg = [[YOUPAILCSelectSexVC alloc]init];
  124. // msg.youpaipinviteCodeStr = self.youpaippasteString;
  125. // [self.navigationController pushViewController:msg animated:YES];
  126. YOUPAILCWriteMesVC *vc = [YOUPAILCWriteMesVC new];
  127. vc.youpaipinviteCodeStr = self.youpaippasteString;
  128. [self.navigationController pushViewController:vc animated:YES];
  129. }else{//已经完善资料
  130. // [LCSaveData saveLoginMark:YES];
  131. [[YOUPAILCIMLoginManager sharedCenter]IMLogin:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id token:[LCSaveModel getUserModel].youpaipuserinfo.youpaipim_token];
  132. [LCTools changeRootToTabbar];
  133. }
  134. [ZCHUDHelper showTitle:@"登录成功"];
  135. }else{
  136. [ZCHUDHelper showTitle:dict[@"message"]];
  137. }
  138. } failure:^(NSError *error) {
  139. // [ZCHUDHelper dismiss];
  140. [SVProgressHUD dismiss];
  141. [SVProgressHUD showWithStatus:[NSString stringWithFormat:@"登陆失败:%@",[error localizedDescription]]];
  142. // [ZCHUDHelper showTitle:[NSString stringWithFormat:@"登陆失败:%@",[error localizedDescription]]];
  143. }];
  144. // }
  145. }
  146. }
  147. -(void)youpaifverifyGetBtnClick{
  148. if ([ZCRegularHelper regularPhoneNumber:self.youpaipphoneNum]) {//首先手机格式保证正确
  149. [LCHttpHelper requestWithURLString:PhoneCode parameters:@{@"mobile":self.youpaipphoneNum,@"type":@"login"} needToken:NO type:(HttpRequestTypePost) success:^(id responseObject) {
  150. NSDictionary* dict = (NSDictionary*)responseObject;
  151. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  152. if (code==0) {//成功
  153. [ZCHUDHelper showTitle:@"验证码已发送"];
  154. __block int timeout=120;
  155. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  156. dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
  157. dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
  158. dispatch_source_set_event_handler(_timer, ^{
  159. if(timeout<=0){
  160. dispatch_source_cancel(_timer);
  161. dispatch_async(dispatch_get_main_queue(), ^{
  162. [self.youpaipverifyGetBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
  163. self.youpaipverifyGetBtn.userInteractionEnabled = YES;
  164. [self.youpaipverifyGetBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  165. [self.youpaipverifyGetBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth-ScaleSize(54), 56) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
  166. });
  167. }else{
  168. NSString *strTime = [NSString stringWithFormat:@"%.2dS",timeout];
  169. dispatch_async(dispatch_get_main_queue(), ^{
  170. //设置界面的按钮显示 根据自己需求设置
  171. [self.youpaipverifyGetBtn setTitle:strTime forState:UIControlStateNormal];
  172. self.youpaipverifyGetBtn.userInteractionEnabled = NO;
  173. [self.youpaipverifyGetBtn setTitleColor:LZ273145Color forState:UIControlStateNormal];
  174. [self.youpaipverifyGetBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth-ScaleSize(54), 56) FromColors:@[LZF7F8FAColor,LZF7F8FAColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
  175. });
  176. timeout--;
  177. }
  178. });
  179. dispatch_resume(_timer);
  180. }
  181. } failure:^(NSError *error) {
  182. }];
  183. }
  184. }
  185. @end