269 lines
9.3 KiB
Objective-C
269 lines
9.3 KiB
Objective-C
//
|
||
// ChangeModelDoneController.m
|
||
// Ifish
|
||
//
|
||
// Created by imac on 15/9/28.
|
||
// Copyright © 2015年 imac. All rights reserved.
|
||
//
|
||
|
||
#import "ChangeModelDoneController.h"
|
||
#import "AFNetworking.h"
|
||
#import "SetViewController.h"
|
||
#import "MyMD5.h"
|
||
#import "XWCountryCodeController.h"
|
||
@interface ChangeModelDoneController ()
|
||
@property (weak, nonatomic) IBOutlet UIButton *timerbtn;
|
||
@property (weak, nonatomic) IBOutlet UIButton *wanchengBtn;
|
||
@property(nonatomic,copy)NSString*verifyData;
|
||
@property(nonatomic,copy) NSString *areaCode;
|
||
@end
|
||
extern BOOL firstLogIn;
|
||
@implementation ChangeModelDoneController
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
[self addTitleViewWithTitle:@"更换手机号"];
|
||
_timerbtn.backgroundColor=COLOR_LABEL_TITLE;
|
||
_wanchengBtn.backgroundColor=COLOR_LABEL_TITLE;
|
||
self.areaCode = @"86";
|
||
self.view.backgroundColor= [UIColor colorWithPatternImage:[UIImage imageNamed:@"enter_background"]];
|
||
|
||
[_timerbtn addTarget:self action:@selector(taptime) forControlEvents:UIControlEventTouchUpInside];
|
||
|
||
[self setTextStyle];
|
||
[self.counttiyCodeBtn addTarget:self action:@selector(countryCodeAction) forControlEvents:UIControlEventTouchUpInside];
|
||
self.view.backgroundColor = [UIColor whiteColor];
|
||
}
|
||
-(void)setTextStyle{
|
||
self.xinModelNumber.layer.masksToBounds=YES;
|
||
self.xinModelNumber.layer.cornerRadius=5;
|
||
self.yanzhengfeild.layer.masksToBounds=YES;
|
||
self.yanzhengfeild.layer.cornerRadius=5;
|
||
_timerbtn.layer.masksToBounds=YES;
|
||
_timerbtn.layer.cornerRadius=5;
|
||
_wanchengBtn.layer.masksToBounds = YES;
|
||
_wanchengBtn.layer.cornerRadius = 5;
|
||
self.countryView.layer.masksToBounds = YES;
|
||
self.countryView.layer.cornerRadius = 5;
|
||
|
||
|
||
UIView*phoneView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 10, 10)];
|
||
self.xinModelNumber.leftView=phoneView;
|
||
self.xinModelNumber.leftViewMode=UITextFieldViewModeAlways;
|
||
UIView*phoneView1=[[UIView alloc]initWithFrame:CGRectMake(0,0, 10, 10)];
|
||
self.yanzhengfeild.leftView=phoneView1;
|
||
self.yanzhengfeild.leftViewMode=UITextFieldViewModeAlways;
|
||
|
||
}
|
||
|
||
-(void)taptime{
|
||
|
||
|
||
__block int timeout=60; //倒计时时间
|
||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||
dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
|
||
dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
|
||
dispatch_source_set_event_handler(_timer, ^{
|
||
if(timeout<=0){ //倒计时结束,关闭
|
||
dispatch_source_cancel(_timer);
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
//设置界面的按钮显示 根据自己需求设置
|
||
[_timerbtn setTitle:@"获取验证码" forState:UIControlStateNormal];
|
||
_timerbtn.backgroundColor = COLOR_LABEL_TITLE;
|
||
|
||
_timerbtn.userInteractionEnabled = YES;
|
||
});
|
||
}else{
|
||
// int minutes = timeout / 60;
|
||
int seconds = timeout % 60;
|
||
NSString *strTime=@"";
|
||
if (seconds==0) {
|
||
strTime=@"60";
|
||
}else{
|
||
strTime = [NSString stringWithFormat:@"%.2d", seconds];
|
||
}
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
//设置界面的按钮显示 根据自己需求设置
|
||
NSLog(@"____%@",strTime);
|
||
[_timerbtn setTitle:[NSString stringWithFormat:@"%@秒",strTime] forState:UIControlStateNormal];
|
||
_timerbtn.userInteractionEnabled = NO;
|
||
_timerbtn.backgroundColor=[UIColor lightGrayColor];
|
||
});
|
||
timeout--;
|
||
|
||
}
|
||
});
|
||
dispatch_resume(_timer);
|
||
|
||
[self getVerifycode];
|
||
|
||
}
|
||
|
||
#pragma mark - 获取验证码新(SMS)
|
||
|
||
-(void)getVerifycode{
|
||
|
||
if ([self.xinModelNumber.text isEqualToString:@""]) {
|
||
|
||
[self.view makeToast:@"请输入正确手机号"];
|
||
return;
|
||
}
|
||
|
||
[IFISHHTTPTOOL getverifyWithTimerButton:_timerbtn addphoneNumber:self.xinModelNumber.text zone:self.areaCode result:^(NSError *err) {
|
||
|
||
}];
|
||
|
||
}
|
||
#define mark - 获取阿里验证码 已去
|
||
|
||
-(void)getAliVerify:(dispatch_source_t)timer{
|
||
if ([self.xinModelNumber.text isEqualToString:@""]) {
|
||
|
||
[self.view makeToast:@"请输入正确手机号"];
|
||
return;
|
||
}
|
||
AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager];
|
||
mannager.responseSerializer=[AFHTTPResponseSerializer serializer];
|
||
|
||
BOOL isMacth=[dataContorl valiMobile:self.xinModelNumber.text];
|
||
|
||
if (isMacth==YES) {
|
||
|
||
NSDictionary*dic=@{@"phoneNumber":self.xinModelNumber.text,@"sendType":@"1"};
|
||
NSLog(@"dic2:%@",dic);
|
||
|
||
[AFHttpTool getSecurityCodeWithPhoneNumber:self.xinModelNumber.text sendType:@"1" success:^(id response) {
|
||
if (response) {
|
||
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
|
||
|
||
_verifyData=reDic[@"data"];
|
||
NSLog(@"_verifyData%@",_verifyData);
|
||
if ([reDic[@"result"] isEqualToString:@"100"]) {
|
||
|
||
[self.view makeToast:@"更换成功"];
|
||
UserModel*userModel=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
|
||
userModel.phoneNumber=self.xinModelNumber.text;
|
||
|
||
|
||
}else if([reDic[@"result"] isEqualToString:@"101"]){
|
||
dispatch_source_cancel(timer);
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
//设置界面的按钮显示 根据自己需求设置
|
||
[_timerbtn setTitle:@"获取验证码" forState:UIControlStateNormal];
|
||
_timerbtn.userInteractionEnabled = YES;
|
||
});
|
||
|
||
[self.view makeToast:@"获取验证失败"];
|
||
// 获取验证失败
|
||
}else if ([reDic[@"result"] isEqualToString:@"201"]){
|
||
|
||
dispatch_source_cancel(timer);
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
//设置界面的按钮显示 根据自己需求设置
|
||
[_timerbtn setTitle:@"获取验证码" forState:UIControlStateNormal];
|
||
_timerbtn.userInteractionEnabled = YES;
|
||
});
|
||
|
||
[self.view makeToast:@"手机已经注册过"];
|
||
}else{
|
||
|
||
}
|
||
}
|
||
|
||
|
||
} failure:^(NSError *err) {
|
||
|
||
UIAlertView *alter =[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请检查您的网络" delegate:self cancelButtonTitle:@"取消" otherButtonTitles: nil];
|
||
[alter show];
|
||
|
||
}];
|
||
|
||
|
||
}else{
|
||
|
||
[self.view makeToast:@"请输入正确手机号"];
|
||
}
|
||
|
||
|
||
}
|
||
|
||
- (void)didReceiveMemoryWarning {
|
||
[super didReceiveMemoryWarning];
|
||
}
|
||
#pragma mark-处理收键盘
|
||
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
|
||
[textField resignFirstResponder];
|
||
return YES;
|
||
|
||
}
|
||
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
|
||
[self hiddenKeybord];
|
||
|
||
}
|
||
-(void)hiddenKeybord{
|
||
[self.xinModelNumber resignFirstResponder];
|
||
[self.yanzhengfeild resignFirstResponder];
|
||
}
|
||
|
||
- (IBAction)doneBtn:(id)sender {
|
||
|
||
// BOOL isMacth=[dataContorl valiMobile:self.xinModelNumber.text];
|
||
//
|
||
// if ((!isMacth)|(self.yanzhengfeild.text.length ==0)){
|
||
//
|
||
// [self.view makeToast:@"请输入正确手机号和验证码"];
|
||
//
|
||
// return;
|
||
// }
|
||
|
||
[SMSSDK commitVerificationCode:self.yanzhengfeild.text phoneNumber:self.xinModelNumber.text zone:self.areaCode result:^(SMSSDKUserInfo *userInfo, NSError *error) {
|
||
|
||
{
|
||
if (!error)
|
||
{
|
||
|
||
NSLog(@"验证成功");
|
||
if (firstLogIn) {
|
||
|
||
[self.navigationController popToRootViewControllerAnimated:YES];
|
||
}else{
|
||
|
||
//[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
|
||
|
||
[self.navigationController popToRootViewControllerAnimated:YES];
|
||
}
|
||
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
NSLog(@"错误信息:%@",error);
|
||
NSString *str =@"验证码验证失败";
|
||
[self.view makeToast:str];
|
||
}
|
||
}
|
||
}];
|
||
|
||
|
||
|
||
}
|
||
|
||
-(void)countryCodeAction
|
||
{
|
||
XWCountryCodeController *CountryCodeVC = [[XWCountryCodeController alloc] init];
|
||
//CountryCodeVC.deleagete = self;
|
||
|
||
[CountryCodeVC toReturnCountryCode:^(NSString *countryCodeStr) {
|
||
|
||
[self.counttiyCodeBtn setTitle:countryCodeStr forState:UIControlStateNormal];
|
||
|
||
NSArray *array = [countryCodeStr componentsSeparatedByString:@"+"];
|
||
self.areaCode = array[1];
|
||
}];
|
||
[self presentViewController:CountryCodeVC animated:YES completion:nil];
|
||
|
||
}
|
||
|
||
@end
|