登陆第三方

#import “MessageViewController.h”
#import <ReactiveObjC.h>
#import “UIButton+Count.h”
#import “NetRequestManager.h”
#import “ShowAlert.h”
#import “AppCheckOut.h”
#import <ShareSDK/ShareSDK.h>
//#import “PhoneNumberViewController.h”

#define APPWeak(object) __weak typeof(object) weak##object = object;

@interface MessageViewController ()
@property (weak, nonatomic) IBOutlet UITextField *phoneText;
@property (weak, nonatomic) IBOutlet UITextField *cedeText;
@property (weak, nonatomic) IBOutlet UIButton *getCedeBtn;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
@property (weak, nonatomic) IBOutlet UIButton *WXLogin;

@end

@implementation MessageViewController

-(void)viewDidLoad {
[super viewDidLoad];

// Do any additional setup after loading the view from its nib.

[_WXLogin setImage:[UIImage imageNamed:@"login"] forState:UIControlStateNormal];

//微信登录
[[self.WXLogin rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
    //1、吊起微信:
    [ShareSDK getUserInfo:SSDKPlatformTypeWechat
           onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error)
     {
         
         if (state == SSDKResponseStateSuccess)
         {
             NSLog(@"uid=%@",user.uid);
             NSLog(@"%@",user.credential);
             NSLog(@"token=%@",user.credential.token);
             NSLog(@"nickname=%@",user.nickname);
         }
         else
         {
             NSLog(@"%@",error);
         }
        
         
     }];
    
    
    //3、微信登录接口调用
    [NetRequestManager requestWithUrl:@"http://test.bit.api.meeboo.cc" withRequestType:GET postParameters:@{@"":@"",@"":@"",@"":@"",@"":@"",@"":@"",@"":@""} success:^(NSDictionary *resDict) {
        
    } failure:^(NSError *error) {
        
    }];
    
    
}];

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

//2、根据登录接口点击登录按钮
[[_loginBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
    //(1)非空
    if ([weakself.cedeText.text isEqualToString:@""]) {
        [ShowAlert showAlterWithMsg:@"请填入已经发送的验证码" withDely:2];
        return ;
    }
    
    //(2)、正则验证;
    BOOL isCodeNumber = [AppCheckOut checkSecurityCode:weakself.cedeText.text];
    if (!isCodeNumber) {
        [ShowAlert showAlterWithMsg:@"验证码不符合规范" withDely:2];
        return ;
    }
    //(3)、调用登录接口:
    [self login];
}];

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

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

}

-(void)login{

APPWeak(self);
NSDictionary *loginDic = @{@"method":@"app.passport.login",@"mobile":weakself.phoneText.text,@"code":self.cedeText.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) {
    
}];

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值