手机验证

cocopods
pod ‘mob_sharesdk’
pod ‘ReactiveObjC’

AppDelegate.m

导头文件 oneViewController.h
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[oneViewController new]];

oneViewController.h
@property (weak, nonatomic) IBOutlet UITextField *text1;
@property (weak, nonatomic) IBOutlet UITextField *text2;
@property (weak, nonatomic) IBOutlet UIButton *btn1;
@property (weak, nonatomic) IBOutlet UIButton *btn2;

oneViewController.m

#import <ShareSDK/ShareSDK.h>
#import “UIButton+Count.h”
#import “NetRequestManager.h”
#import “ShowAlert.h”
#import “AppCheckOut.h”
#import <ReactiveObjC.h>
#define APPWeak(object) __weak typeof(object) weak##object = object;
@interface oneViewController ()

@end

@implementation oneViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    APPWeak(self);
    //1.获取验证码:
    [[_btn1 rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {

      //(1)、判断手机号是否为空:
      if ([weakself.text1.text isEqualToString:@""]) {
          [ShowAlert showAlterWithMsg:@"手机号不正确" withDely:2];
          return ;
      }
      
      //(2)、判断手机号是否正确:
      BOOL isPhoneNumber = [AppCheckOut checkMobile:weakself.text1.text];
      if (!isPhoneNumber) {
          [ShowAlert showAlterWithMsg:@"手机号格式不正确" withDely:2];
          return ;
      }
      
      //(3)、点击获取验证码按钮开始倒计时:
      [self.btn1 countDownWithTimeInterval:60];
      
      //(4)、根据验证码接口请求验证码:
      [NetRequestManager requestWithUrl:@"http://buluokes.huimor.com/api" withRequestType:GET postParameters:@{@"method":@"app.passport.sendsms",@"mobile":weakself.text1.text,@"type":@"1",@"user_token":@""} success:^(NSDictionary *resDict) {
          NSLog(@"=========%@",resDict);
      } failure:^(NSError *error) {
          NSLog(@"======%@",error);
      }];
    

    }];

    //2、根据登录接口点击登录按钮
    [[_btn2 rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
    //(1)非空
    if ([weakself.text2.text isEqualToString:@""]) {
    [ShowAlert showAlterWithMsg:@“请填入已经发送的验证码” withDely:2];
    return ;
    }

      //(2)、正则验证;
      BOOL isCodeNumber = [AppCheckOut checkSecurityCode:weakself.text2.text];
      if (!isCodeNumber) {
          [ShowAlert showAlterWithMsg:@"验证码不符合规范" withDely:2];
          return ;
      }
      //(3)、调用登录接口:
      [self login];
    

    }];

    [[self.text1 rac_textSignal]subscribeNext:^(NSString * _Nullable x) {
    //两个都为空:
    if (![weakself.text2.text isEqualToString:@""] && ![x isEqualToString:@""]) {
    weakself.btn2.enabled = YES;
    weakself.btn2.backgroundColor = [UIColor blueColor];
    }else{
    weakself.btn2.enabled = NO;
    weakself.btn2.backgroundColor = [UIColor cyanColor];
    }

    }];

    [[self.text2 rac_textSignal]subscribeNext:^(NSString * _Nullable x) {
    //两个都为空:
    if (![weakself.text1.text isEqualToString:@""] && ![x isEqualToString:@""]) {
    weakself.btn2.enabled = YES;
    weakself.btn2.backgroundColor = [UIColor blueColor];
    }else{
    weakself.btn2.enabled = NO;
    weakself.btn2.backgroundColor = [UIColor cyanColor];
    }
    }];
    }

  • (void)login{
    APPWeak(self);
    NSDictionary *loginDic = @{@“method”?“app.passport.login”,@“mobile”:weakself.text1.text,@“code”:self.text2.text,@“device”?“ios”,@“device_id”?“123123123123”,@“parent_id”?“1”,@“registration_id”?"",@“user_token”?""};
    [NetRequestManager requestWithUrl:@“http://buluokes.huimor.com/api” withRequestType:GET postParameters:loginDic success:^(NSDictionary *resDict) {
    NSLog(@"+++++++++%@",resDict);
    } failure:^(NSError *error) {

    }];
    }

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    }
    */

@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值