酷店

KDPPhoneLoginViewController.m 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // KDPPhoneLoginViewController.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/8.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPPhoneLoginViewController.h"
  9. #import "KDPWebViewViewController.h"
  10. #import "KDPBindFastHandViewController.h"
  11. #import "KDPublicMethod.h"
  12. static int count = 0;
  13. @interface KDPPhoneLoginViewController ()
  14. @property (nonatomic, strong) UITextField *phoneTextField;
  15. @property (nonatomic, strong) UITextField *codeField;
  16. @property (nonatomic, strong) UIButton *sendCodeBtn;
  17. @property (nonatomic, strong) NSTimer *timer;
  18. @end
  19. @implementation KDPPhoneLoginViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. self.view.backgroundColor = [UIColor whiteColor];
  24. self.navBar.hidden = YES;
  25. [self setSubViews];
  26. }
  27. - (void)setSubViews{
  28. // UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  29. // UIImage *image = [[UIImage imageNamed:@"close_web"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  30. // [closeBtn setImage:image];
  31. // [closeBtn addTarget:self action:@selector(closeAction:) forControlEvents:UIControlEventTouchUpInside];
  32. // closeBtn.frame = CGRectMake(15, KDStatusHeight + 18, 16, 16);
  33. // [self.view addSubview:closeBtn];
  34. UILabel *phoneTipLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, KDStatusHeight + Fitsize(87) , 217, 42)];
  35. phoneTipLabel.textColor = [UIColor colorWithHex:0x333333];
  36. phoneTipLabel.font = [UIFont fontWithName:@"PingFangSC-Semibold" size: 30];
  37. phoneTipLabel.text = @"手机号快速登录";
  38. [self.view addSubview:phoneTipLabel];
  39. NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString: @"登录代表您已阅读并同意《酷店app隐私协议政策》"];
  40. text.yy_font = [UIFont systemFontOfSize:12];
  41. text.yy_color = [UIColor colorWithHex:0x4B4B4B];
  42. __weak typeof(self) weakself = self;
  43. [text yy_setTextHighlightRange:NSMakeRange(11, text.length-11) color:[UIColor colorWithHex:0x208EEA] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  44. KDPWebViewViewController *webVC = [[KDPWebViewViewController alloc] init];
  45. NSString *urlStr = @"https://tbk.726p.com/agreementh5/agreement/index.html?name=酷店app";
  46. webVC.webUrl = urlStr;
  47. [weakself presentViewController:webVC animated:YES completion:nil];
  48. }];
  49. YYLabel *privacyLabel = [[YYLabel alloc] initWithFrame:CGRectMake(32, phoneTipLabel.bottom+10, SCREEN_WIDTH-32, 17)];
  50. privacyLabel.attributedText = text;
  51. [self.view addSubview:privacyLabel];
  52. UITextField *phoneField = [[UITextField alloc] initWithFrame:CGRectMake(32, privacyLabel.bottom+Fitsize(102), 200, 22)];
  53. phoneField.keyboardType = UIKeyboardTypePhonePad;
  54. phoneField.textColor = [UIColor colorWithHex:0x333333];
  55. phoneField.font = FONT_SYS(16);
  56. phoneField.placeholder = @"请输入手机号";
  57. [phoneField addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  58. self.phoneTextField = phoneField;
  59. [self.view addSubview:self.phoneTextField];
  60. self.sendCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  61. self.sendCodeBtn.frame = CGRectMake(SCREEN_WIDTH-120-36, phoneField.top, 120, 17);
  62. self.sendCodeBtn.centerY = phoneField.centerY;
  63. self.sendCodeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  64. [self.sendCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
  65. [self.sendCodeBtn setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
  66. self.sendCodeBtn.titleLabel.font = FONT_SYS(12);
  67. [self.sendCodeBtn addTarget:self action:@selector(sendCodeClick:) forControlEvents:UIControlEventTouchUpInside];
  68. [self.view addSubview:self.sendCodeBtn];
  69. UIView *phoneLine = [[UIView alloc] initWithFrame:CGRectMake(32, phoneField.bottom + 12, SCREEN_WIDTH-64, 1)];
  70. phoneLine.backgroundColor = [UIColor colorWithHex:0xD1D1D1];
  71. [self.view addSubview:phoneLine];
  72. self.codeField = [[UITextField alloc] initWithFrame:CGRectMake(32, phoneLine.bottom + 27, self.phoneTextField.width, self.phoneTextField.height)];
  73. self.codeField.keyboardType = UIKeyboardTypePhonePad;
  74. self.codeField.textColor = [UIColor colorWithHex:0x333333];
  75. self.codeField.font = FONT_SYS(16);
  76. self.codeField.placeholder = @"请输入验证码";
  77. [self.view addSubview:self.codeField];
  78. UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(32, self.codeField.bottom + 12, SCREEN_WIDTH-64, 1)];
  79. lineView.backgroundColor = [UIColor colorWithHex:0xD1D1D1];
  80. [self.view addSubview:lineView];
  81. UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  82. loginBtn.frame = CGRectMake(32, lineView.bottom + Fitsize(80), SCREEN_WIDTH-64, 48);
  83. [loginBtn setGradientBackgroundWithColors:@[[UIColor colorWithHex:0xFF7676],[UIColor colorWithHex:0xFF235F]] locations:@[@0,@1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
  84. [loginBtn setTitle:@"登录" forState:UIControlStateNormal];
  85. [loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  86. loginBtn.titleLabel.font = FONT_SYS(17);
  87. [loginBtn addTarget:self action:@selector(loginBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  88. loginBtn.layer.cornerRadius = 24;
  89. loginBtn.layer.masksToBounds = YES;
  90. [self.view addSubview:loginBtn];
  91. UILabel *bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, loginBtn.bottom + 7, SCREEN_WIDTH, 18)];
  92. bottomLabel.textAlignment = NSTextAlignmentCenter;
  93. bottomLabel.textColor = [UIColor colorWithHex:0x5d5d5d];
  94. bottomLabel.font = FONT_SYS(13);
  95. bottomLabel.text = @"未注册的手机号码验证后自动注册";
  96. [self.view addSubview:bottomLabel];
  97. }
  98. - (void)closeAction:(UIButton *)sender{
  99. }
  100. - (void)loginBtnClick:(UIButton *)sender{
  101. if (self.phoneTextField.text.length < 11 || self.phoneTextField.text.length >13) {
  102. [MBProgressHUD showMessage:@"请输入正确的手机号"];
  103. return;
  104. }
  105. if (self.codeField.text.length) {
  106. [LoadingView show];
  107. NSDictionary *params=@{@"phone":self.phoneTextField.text,@"code":self.codeField.text};
  108. [KDPNetworkRequestHTTP postURL:LoginURL params:params success:^(id _Nonnull json) {
  109. [LoadingView dismiss];
  110. NSInteger has_kwai=[json[@"has_kwai"] integerValue];
  111. KDPAccountModel *accountModel = [KDPAccountModel yy_modelWithJSON:json];
  112. accountModel.phone = self.phoneTextField.text;
  113. [KDPAccountTool saveAccount:accountModel];
  114. //判断是否填写快手号,,
  115. if (has_kwai !=1) {//1的时候已经填写快手号
  116. KDPBindFastHandViewController *setV = [[KDPBindFastHandViewController alloc]init];
  117. [self.navigationController presentViewController:[[UINavigationController alloc]initWithRootViewController:setV] animated:YES completion:nil];
  118. }else{
  119. UIViewController *vc = self;
  120. while (vc.presentingViewController) {
  121. vc = vc.presentingViewController;
  122. }
  123. [vc dismissViewControllerAnimated:YES completion:nil];
  124. }
  125. } failure:^(NSError * _Nonnull error) {
  126. [LoadingView dismiss];
  127. }];
  128. } else{
  129. [MBProgressHUD showMessage:@"请输入验证码"];
  130. }
  131. }
  132. - (void)valueChanged:(UITextField *)textfield{
  133. }
  134. - (void)sendCodeClick:(UIButton *)sender{
  135. if (self.phoneTextField.text.length >= 11 && self.phoneTextField.text.length <= 13) {
  136. [LoadingView showInView:self.view];
  137. [self.phoneTextField resignFirstResponder];
  138. NSString *ttl = [KDPublicMethod getNowTimeTimestamp];
  139. NSString *sign = [NSString stringWithFormat:@"phone=%@&ttl=%@%@",self.phoneTextField.text,ttl,SignCode];
  140. NSString *md5Str = [KDPublicMethod md5:sign];
  141. NSDictionary *para = @{@"phone":self.phoneTextField.text,
  142. @"ttl":ttl,
  143. @"sign":md5Str
  144. };
  145. [KDPNetworkRequestHTTP postURL:GetCodeURL params:para success:^(id _Nonnull json) {
  146. [LoadingView dismiss];
  147. NSDictionary *dics =(NSDictionary *)json;
  148. count = [json[@"wait_time"]integerValue ];
  149. [self startTime];
  150. if ([json[@"success"] boolValue] == 1) {
  151. if ([dics.allKeys containsObject:@"code"]) {
  152. self.codeField.text=[NSString stringWithFormat:@"%@", json[@"code"]];
  153. }
  154. }
  155. } failure:^(NSError * _Nonnull error) {
  156. [LoadingView dismiss];
  157. }];
  158. } else{
  159. [MBProgressHUD showMessage:@"请输入正确的手机号"];
  160. }
  161. }
  162. - (void)startTime{
  163. [_timer invalidate];
  164. [self changeCode];
  165. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
  166. }
  167. - (void)changeCode{
  168. NSString *title = @"获取验证码";
  169. if (count > 0) {
  170. title = [NSString stringWithFormat:@"%d秒后可重新获取", count];
  171. [self.sendCodeBtn setTitleColor:[UIColor colorWithHex:0x999999] forState:UIControlStateNormal];
  172. self.sendCodeBtn.userInteractionEnabled = NO;
  173. }else{
  174. [self.sendCodeBtn setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
  175. }
  176. [self.sendCodeBtn setTitle:title forState:UIControlStateNormal];
  177. }
  178. - (void)updateTime {
  179. count --;
  180. [self changeCode];
  181. if (count <= 0) {
  182. self.sendCodeBtn.userInteractionEnabled = YES;
  183. [self.timer invalidate];
  184. self.timer = nil;
  185. }
  186. }
  187. @end