// // JXXiugaiPhoneNumVc.m // shiku_im // // Created by 123 on 2020/6/10. // Copyright © 2020 Reese. All rights reserved. // #import "JXXiugaiPhoneNumVc.h" @interface JXXiugaiPhoneNumVc () @property (weak, nonatomic) IBOutlet UITextField *phoneTF; @property (weak, nonatomic) IBOutlet UITextField *codeTF; //刷新验证码 @property (weak, nonatomic) IBOutlet UIImageView *refuIMG; //发送验证码 @property (weak, nonatomic) IBOutlet UIButton *sendCodeBtn; //图形验证码 @property (weak, nonatomic) IBOutlet UIImageView *imgCode; @property (nonatomic,strong) NSTimer *timer; @property (weak, nonatomic) IBOutlet UIView *xiugaiBtn; @property (weak, nonatomic) IBOutlet UIView *backView; @property (weak, nonatomic) IBOutlet UITextField *code2TF; @property (nonatomic,assign) int seconds; @end @implementation JXXiugaiPhoneNumVc - (IBAction)gobackBtn:(id)sender { [g_navigation dismissViewController:self animated:YES]; } - (void)viewDidLoad { [super viewDidLoad]; [_phoneTF addTarget:self action:@selector(textFieldDidChanged:) forControlEvents:UIControlEventTouchUpInside]; _phoneTF.delegate=self; self.backView.layer.cornerRadius=5; self.backView.layer.masksToBounds=YES; [self.refuIMG addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(refulIMGClick)]]; } // became first responder - (BOOL)textFieldShouldEndEditing:(UITextField *)textField{ [self getImgCodeImg]; return YES; } //刷新图片 - (void)refulIMGClick{ [self getImgCodeImg]; } //获取验证码 -(void)getImgCodeImg{ if([self isMobileNumber:_phoneTF.text]){ // if ([self checkPhoneNum]) { //请求图片验证码 NSString *areaCode = @"86"; NSString * codeUrl = [g_server getImgCode:_phoneTF.text areaCode:areaCode]; NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:codeUrl] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) { if (!connectionError) { UIImage * codeImage = [UIImage imageWithData:data]; _imgCode.image = codeImage; }else{ NSLog(@"%@",connectionError); [g_App showAlert:connectionError.localizedDescription]; } }]; }else{ } } //验证手机号码格式 - (BOOL)isMobileNumber:(NSString *)number{ if ([g_config.isOpenSMSCode boolValue] && [g_config.regeditPhoneOrName intValue] != 1) { if ([_phoneTF.text length] == 0) { [g_App showAlert:Localized(@"JX_InputPhone")]; return NO; } return YES; } return NO; } - (void)textFieldDidChanged:(UITextField *)textField { if (textField == _phoneTF) { // 限制手机号最多只能输入11位,为了适配外国电话,将不能显示手机号位数 if ([g_config.regeditPhoneOrName intValue] == 1) { if (_phoneTF.text.length > 10) { _phoneTF.text = [_phoneTF.text substringToIndex:10]; } }else { if (_phoneTF.text.length > 11) { _phoneTF.text = [_phoneTF.text substringToIndex:11]; } } } } - (IBAction)senderSMS { if (_phoneTF.text.length==0) { [SVProgressHUD showWithStatus:@"手机号码不能为空"]; [SVProgressHUD dismissWithDelay:1.0]; return; } [self getImgCodeImg]; [g_server sendSMS:[NSString stringWithFormat:@"%@",_phoneTF.text] areaCode:@"86" isRegister:NO imgCode:_codeTF.text toView:self]; [_sendCodeBtn setTitle:Localized(@"JX_Sending") forState:UIControlStateNormal]; //[_wait start:Localized(@"JX_SendNow")]; //[g_server checkPhone:_phone.text areaCode:areaCode toView:self]; } - (IBAction)xiugaiPwdBtn:(id)sender { if (_phoneTF.text.length==0) { [SVProgressHUD showWithStatus:@"手机号码不能为空"]; [SVProgressHUD dismissWithDelay:1.0]; return; }if (_codeTF.text.length==0) { [SVProgressHUD showWithStatus:@"图形验证码不能为空"]; [SVProgressHUD dismissWithDelay:1.0]; return; }if (_code2TF.text.length==0) { [SVProgressHUD showWithStatus:@"验证码不能为空"]; [SVProgressHUD dismissWithDelay:1.0]; return; } long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; [g_server updateUserPhone:salt telephone:_phoneTF.text areaCode:_code2TF.text toView:self]; } -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{ if([aDownload.action isEqualToString:act_SendSMS]){ [JXMyTools showTipView:Localized(@"JXAlert_SendOK")]; _sendCodeBtn.selected = YES; _sendCodeBtn.userInteractionEnabled = NO; // if ([dict objectForKey:@"code"]) { // _codeTF.text = [[dict objectForKey:@"code"] copy]; // }else { // 没有返回短信验证码 // _codeTF.text = @"-1"; // } [_sendCodeBtn setTitle:@"60s" forState:UIControlStateSelected]; [_sendCodeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected]; _seconds = 60; _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showTime:) userInfo:_sendCodeBtn repeats:YES]; //_phoneStr = _phone.text; //_imgCodeStr = _imgCode.text; } if([aDownload.action isEqualToString:act_updateUserPhone]){ [g_navigation dismissViewController:self animated:YES]; } if([aDownload.action isEqualToString:act_CheckPhone]){ /* if (self.isCheckToSMS) { self.isCheckToSMS = NO; [self onSend]; return; } if ([g_config.isOpenSMSCode boolValue] && [g_config.regeditPhoneOrName intValue] != 1) { [self onClick]; }else { [self onTest]; } */ } } -(void)showTime:(NSTimer *)timer{ UIButton *but = (UIButton*)[_timer userInfo]; _seconds--; [but setTitle:[NSString stringWithFormat:@"%ds",_seconds] forState:UIControlStateSelected]; if(_seconds<=0){ but.selected = NO; but.userInteractionEnabled = YES; but.backgroundColor = g_theme.themeColor; [_sendCodeBtn setTitle:@"发送" forState:UIControlStateNormal]; if (_timer) { _timer = nil; [_timer invalidate]; } _seconds = 60; } } -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{ if([aDownload.action isEqualToString:act_SendSMS]){ // [_send setTitle:Localized(@"JX_Send") forState:UIControlStateNormal]; // [g_App showAlert:dict[@"resultMsg"]]; // [self getImgCodeImg]; return hide_error; } return show_error; } @end