123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- //
- // KDPPhoneLoginViewController.m
- // KuDianProject
- //
- // Created by admin on 2019/7/8.
- // Copyright © 2019 KDP. All rights reserved.
- //
- #import "KDPPhoneLoginViewController.h"
- #import "KDPWebViewViewController.h"
- #import "KDPBindFastHandViewController.h"
- #import "KDPublicMethod.h"
- static int count = 0;
- @interface KDPPhoneLoginViewController ()
- @property (nonatomic, strong) UITextField *phoneTextField;
- @property (nonatomic, strong) UITextField *codeField;
- @property (nonatomic, strong) UIButton *sendCodeBtn;
- @property (nonatomic, strong) NSTimer *timer;
- // 保存的手机验证码
- @property (nonatomic, strong) NSString *saveCode;
- @end
- @implementation KDPPhoneLoginViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.view.backgroundColor = [UIColor whiteColor];
- self.navBar.hidden = YES;
- [self setSubViews];
- }
- - (void)setSubViews{
- // UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
- // UIImage *image = [[UIImage imageNamed:@"close_web"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- // [closeBtn setImage:image];
- // [closeBtn addTarget:self action:@selector(closeAction:) forControlEvents:UIControlEventTouchUpInside];
- // closeBtn.frame = CGRectMake(15, KDStatusHeight + 18, 16, 16);
- // [self.view addSubview:closeBtn];
-
- UILabel *phoneTipLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, KDStatusHeight + Fitsize(87) , 217, 42)];
- phoneTipLabel.textColor = [UIColor colorWithHex:0x333333];
- phoneTipLabel.font = [UIFont fontWithName:@"PingFangSC-Semibold" size: 30];
- phoneTipLabel.text = @"手机号快速登录";
- [self.view addSubview:phoneTipLabel];
-
- NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString: @"登录代表您已阅读并同意《酷店app隐私协议政策》"];
- text.yy_font = [UIFont systemFontOfSize:12];
- text.yy_color = [UIColor colorWithHex:0x4B4B4B];
- __weak typeof(self) weakself = self;
- [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) {
- KDPWebViewViewController *webVC = [[KDPWebViewViewController alloc] init];
- NSString *urlStr = @"https://tbk.726p.com/agreementh5/agreement/index.html?name=酷店app";
- webVC.webUrl = urlStr;
- [weakself presentViewController:webVC animated:YES completion:nil];
- }];
-
- YYLabel *privacyLabel = [[YYLabel alloc] initWithFrame:CGRectMake(32, phoneTipLabel.bottom+10, SCREEN_WIDTH-32, 17)];
- privacyLabel.attributedText = text;
- [self.view addSubview:privacyLabel];
-
- UITextField *phoneField = [[UITextField alloc] initWithFrame:CGRectMake(32, privacyLabel.bottom+Fitsize(102), 200, 22)];
- phoneField.keyboardType = UIKeyboardTypePhonePad;
- phoneField.textColor = [UIColor colorWithHex:0x333333];
- phoneField.font = FONT_SYS(16);
- phoneField.placeholder = @"请输入手机号";
- [phoneField addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
- self.phoneTextField = phoneField;
- [self.view addSubview:self.phoneTextField];
-
- self.sendCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- self.sendCodeBtn.frame = CGRectMake(SCREEN_WIDTH-120-36, phoneField.top, 120, 17);
- self.sendCodeBtn.centerY = phoneField.centerY;
- self.sendCodeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
- [self.sendCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
- [self.sendCodeBtn setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
- self.sendCodeBtn.titleLabel.font = FONT_SYS(12);
- [self.sendCodeBtn addTarget:self action:@selector(sendCodeClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:self.sendCodeBtn];
-
- UIView *phoneLine = [[UIView alloc] initWithFrame:CGRectMake(32, phoneField.bottom + 12, SCREEN_WIDTH-64, 1)];
- phoneLine.backgroundColor = [UIColor colorWithHex:0xD1D1D1];
- [self.view addSubview:phoneLine];
-
- self.codeField = [[UITextField alloc] initWithFrame:CGRectMake(32, phoneLine.bottom + 27, phoneLine.width, self.phoneTextField.height)];
- self.codeField.keyboardType = UIKeyboardTypePhonePad;
- self.codeField.textColor = [UIColor colorWithHex:0x333333];
- self.codeField.font = FONT_SYS(16);
- self.codeField.placeholder = @"请输入验证码";
- [self.view addSubview:self.codeField];
-
- UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(32, self.codeField.bottom + 12, SCREEN_WIDTH-64, 1)];
- lineView.backgroundColor = [UIColor colorWithHex:0xD1D1D1];
- [self.view addSubview:lineView];
-
- UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- loginBtn.frame = CGRectMake(32, lineView.bottom + Fitsize(80), SCREEN_WIDTH-64, 48);
- [loginBtn setGradientBackgroundWithColors:@[[UIColor colorWithHex:0xFF7676],[UIColor colorWithHex:0xFF235F]] locations:@[@0,@1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
- [loginBtn setTitle:@"登录" forState:UIControlStateNormal];
- [loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- loginBtn.titleLabel.font = FONT_SYS(17);
- [loginBtn addTarget:self action:@selector(loginBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- loginBtn.layer.cornerRadius = 24;
- loginBtn.layer.masksToBounds = YES;
- [self.view addSubview:loginBtn];
-
- UILabel *bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, loginBtn.bottom + 7, SCREEN_WIDTH, 18)];
- bottomLabel.textAlignment = NSTextAlignmentCenter;
- bottomLabel.textColor = [UIColor colorWithHex:0x5d5d5d];
- bottomLabel.font = FONT_SYS(13);
- bottomLabel.text = @"未注册的手机号码验证后自动注册";
- [self.view addSubview:bottomLabel];
- }
- - (void)closeAction:(UIButton *)sender{
- }
- - (void)loginBtnClick:(UIButton *)sender{
- if (self.phoneTextField.text.length < 11 || self.phoneTextField.text.length >13) {
- [MBProgressHUD showMessage:@"请输入正确的手机号"];
- return;
- }
- if (self.codeField.text.length) {
- [LoadingView show];
- NSDictionary *params=@{@"phone":self.phoneTextField.text,@"code":self.codeField.text};
- [KDPNetworkRequestHTTP postURL:LoginURL params:params success:^(id _Nonnull json) {
- [LoadingView dismiss];
- NSInteger has_kwai=[json[@"has_kwai"] integerValue];
- KDPAccountModel *accountModel = [KDPAccountModel yy_modelWithJSON:json];
- accountModel.phone = self.phoneTextField.text;
- [KDPAccountTool saveAccount:accountModel];
- //判断是否填写快手号,,
- if (has_kwai !=1) {//1的时候已经填写快手号
- KDPBindFastHandViewController *setV = [[KDPBindFastHandViewController alloc]init];
- [self presentViewController:[[UINavigationController alloc]initWithRootViewController:setV] animated:YES completion:nil];
- }else{
- UIViewController *vc = self;
- while (vc.presentingViewController) {
- vc = vc.presentingViewController;
- }
- [vc dismissViewControllerAnimated:YES completion:nil];
- }
- } failure:^(NSError * _Nonnull error) {
- [MBProgressHUD showError:@"验证码输入错误"];
- [LoadingView dismiss];
- }];
- } else{
- [MBProgressHUD showMessage:@"请输入验证码"];
- }
- }
- - (void)valueChanged:(UITextField *)textfield{
-
- }
- - (void)sendCodeClick:(UIButton *)sender{
- if (self.phoneTextField.text.length >= 11 && self.phoneTextField.text.length <= 13) {
- [LoadingView showInView:self.view];
- [self.phoneTextField resignFirstResponder];
- NSString *ttl = [KDPublicMethod getNowTimeTimestamp];
- NSString *sign = [NSString stringWithFormat:@"phone=%@&ttl=%@%@",self.phoneTextField.text,ttl,SignCode];
- NSString *md5Str = [KDPublicMethod md5:sign];
- NSDictionary *para = @{@"phone":self.phoneTextField.text,
- @"ttl":ttl,
- @"sign":md5Str
- };
- [KDPNetworkRequestHTTP postURL:GetCodeURL params:para success:^(id _Nonnull json) {
- [LoadingView dismiss];
- NSDictionary *dics =(NSDictionary *)json;
- count = [json[@"wait_time"]integerValue ];
- [self startTime];
- if ([json[@"success"] boolValue] == 1) {
- if ([dics.allKeys containsObject:@"code"]) {
- self.codeField.text=[NSString stringWithFormat:@"%@", json[@"code"]];
- }
-
- }
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- }];
- } else{
- [MBProgressHUD showMessage:@"请输入正确的手机号"];
- }
- }
- - (void)startTime{
- [_timer invalidate];
- [self changeCode];
- _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
- }
- - (void)changeCode{
- NSString *title = @"获取验证码";
- if (count > 0) {
- title = [NSString stringWithFormat:@"%d秒后可重新获取", count];
- [self.sendCodeBtn setTitleColor:[UIColor colorWithHex:0x999999] forState:UIControlStateNormal];
- self.sendCodeBtn.userInteractionEnabled = NO;
- }else{
- [self.sendCodeBtn setTitleColor:[UIColor baseColor] forState:UIControlStateNormal];
- }
-
- [self.sendCodeBtn setTitle:title forState:UIControlStateNormal];
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleDefault;
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;
- }
- - (void)updateTime {
- count --;
- [self changeCode];
- if (count <= 0) {
- self.sendCodeBtn.userInteractionEnabled = YES;
- [self.timer invalidate];
- self.timer = nil;
- }
- }
- @end
|