JXXiugaiPhoneNumVc.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // JXXiugaiPhoneNumVc.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/6/10.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXXiugaiPhoneNumVc.h"
  9. @interface JXXiugaiPhoneNumVc ()<UITextFieldDelegate>
  10. @property (weak, nonatomic) IBOutlet UITextField *phoneTF;
  11. @property (weak, nonatomic) IBOutlet UITextField *codeTF;
  12. //刷新验证码
  13. @property (weak, nonatomic) IBOutlet UIImageView *refuIMG;
  14. //发送验证码
  15. @property (weak, nonatomic) IBOutlet UIButton *sendCodeBtn;
  16. //图形验证码
  17. @property (weak, nonatomic) IBOutlet UIImageView *imgCode;
  18. @property (nonatomic,strong) NSTimer *timer;
  19. @property (weak, nonatomic) IBOutlet UIView *xiugaiBtn;
  20. @property (weak, nonatomic) IBOutlet UIView *backView;
  21. @property (weak, nonatomic) IBOutlet UITextField *code2TF;
  22. @property (nonatomic,assign) int seconds;
  23. @end
  24. @implementation JXXiugaiPhoneNumVc
  25. - (IBAction)gobackBtn:(id)sender {
  26. [g_navigation dismissViewController:self animated:YES];
  27. }
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. [_phoneTF addTarget:self action:@selector(textFieldDidChanged:) forControlEvents:UIControlEventTouchUpInside];
  31. _phoneTF.delegate=self;
  32. self.backView.layer.cornerRadius=5;
  33. self.backView.layer.masksToBounds=YES;
  34. [self.refuIMG addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(refulIMGClick)]];
  35. }
  36. // became first responder
  37. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
  38. [self getImgCodeImg];
  39. return YES;
  40. }
  41. //刷新图片
  42. - (void)refulIMGClick{
  43. [self getImgCodeImg];
  44. }
  45. //获取验证码
  46. -(void)getImgCodeImg{
  47. if([self isMobileNumber:_phoneTF.text]){
  48. // if ([self checkPhoneNum]) {
  49. //请求图片验证码
  50. NSString *areaCode = @"86";
  51. NSString * codeUrl = [g_server getImgCode:_phoneTF.text areaCode:areaCode];
  52. NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:codeUrl] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0];
  53. [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
  54. if (!connectionError) {
  55. UIImage * codeImage = [UIImage imageWithData:data];
  56. _imgCode.image = codeImage;
  57. }else{
  58. NSLog(@"%@",connectionError);
  59. [g_App showAlert:connectionError.localizedDescription];
  60. }
  61. }];
  62. }else{
  63. }
  64. }
  65. //验证手机号码格式
  66. - (BOOL)isMobileNumber:(NSString *)number{
  67. if ([g_config.isOpenSMSCode boolValue] && [g_config.regeditPhoneOrName intValue] != 1) {
  68. if ([_phoneTF.text length] == 0) {
  69. [g_App showAlert:Localized(@"JX_InputPhone")];
  70. return NO;
  71. }
  72. return YES;
  73. }
  74. return NO;
  75. }
  76. - (void)textFieldDidChanged:(UITextField *)textField {
  77. if (textField == _phoneTF) { // 限制手机号最多只能输入11位,为了适配外国电话,将不能显示手机号位数
  78. if ([g_config.regeditPhoneOrName intValue] == 1) {
  79. if (_phoneTF.text.length > 10) {
  80. _phoneTF.text = [_phoneTF.text substringToIndex:10];
  81. }
  82. }else {
  83. if (_phoneTF.text.length > 11) {
  84. _phoneTF.text = [_phoneTF.text substringToIndex:11];
  85. }
  86. }
  87. }
  88. }
  89. - (IBAction)senderSMS {
  90. if (_phoneTF.text.length==0) {
  91. [SVProgressHUD showWithStatus:@"手机号码不能为空"];
  92. [SVProgressHUD dismissWithDelay:1.0];
  93. return;
  94. }
  95. [self getImgCodeImg];
  96. [g_server sendSMS:[NSString stringWithFormat:@"%@",_phoneTF.text] areaCode:@"86" isRegister:NO imgCode:_codeTF.text toView:self];
  97. [_sendCodeBtn setTitle:Localized(@"JX_Sending") forState:UIControlStateNormal];
  98. //[_wait start:Localized(@"JX_SendNow")];
  99. //[g_server checkPhone:_phone.text areaCode:areaCode toView:self];
  100. }
  101. - (IBAction)xiugaiPwdBtn:(id)sender {
  102. if (_phoneTF.text.length==0) {
  103. [SVProgressHUD showWithStatus:@"手机号码不能为空"];
  104. [SVProgressHUD dismissWithDelay:1.0];
  105. return;
  106. }if (_codeTF.text.length==0) {
  107. [SVProgressHUD showWithStatus:@"图形验证码不能为空"];
  108. [SVProgressHUD dismissWithDelay:1.0];
  109. return;
  110. }if (_code2TF.text.length==0) {
  111. [SVProgressHUD showWithStatus:@"验证码不能为空"];
  112. [SVProgressHUD dismissWithDelay:1.0];
  113. return;
  114. }
  115. long time = (long)[[NSDate date] timeIntervalSince1970];
  116. time = (time *1000 + g_server.timeDifference);
  117. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  118. [g_server updateUserPhone:salt telephone:_phoneTF.text areaCode:_code2TF.text toView:self];
  119. }
  120. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  121. if([aDownload.action isEqualToString:act_SendSMS]){
  122. [JXMyTools showTipView:Localized(@"JXAlert_SendOK")];
  123. _sendCodeBtn.selected = YES;
  124. _sendCodeBtn.userInteractionEnabled = NO;
  125. // if ([dict objectForKey:@"code"]) {
  126. // _codeTF.text = [[dict objectForKey:@"code"] copy];
  127. // }else { // 没有返回短信验证码
  128. // _codeTF.text = @"-1";
  129. // }
  130. [_sendCodeBtn setTitle:@"60s" forState:UIControlStateSelected];
  131. [_sendCodeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  132. _seconds = 60;
  133. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showTime:) userInfo:_sendCodeBtn repeats:YES];
  134. //_phoneStr = _phone.text;
  135. //_imgCodeStr = _imgCode.text;
  136. }
  137. if([aDownload.action isEqualToString:act_updateUserPhone]){
  138. [g_navigation dismissViewController:self animated:YES];
  139. }
  140. if([aDownload.action isEqualToString:act_CheckPhone]){
  141. /*
  142. if (self.isCheckToSMS) {
  143. self.isCheckToSMS = NO;
  144. [self onSend];
  145. return;
  146. }
  147. if ([g_config.isOpenSMSCode boolValue] && [g_config.regeditPhoneOrName intValue] != 1) {
  148. [self onClick];
  149. }else {
  150. [self onTest];
  151. }
  152. */
  153. }
  154. }
  155. -(void)showTime:(NSTimer *)timer{
  156. UIButton *but = (UIButton*)[_timer userInfo];
  157. _seconds--;
  158. [but setTitle:[NSString stringWithFormat:@"%ds",_seconds] forState:UIControlStateSelected];
  159. if(_seconds<=0){
  160. but.selected = NO;
  161. but.userInteractionEnabled = YES;
  162. but.backgroundColor = g_theme.themeColor;
  163. [_sendCodeBtn setTitle:@"发送" forState:UIControlStateNormal];
  164. if (_timer) {
  165. _timer = nil;
  166. [_timer invalidate];
  167. }
  168. _seconds = 60;
  169. }
  170. }
  171. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  172. if([aDownload.action isEqualToString:act_SendSMS]){
  173. // [_send setTitle:Localized(@"JX_Send") forState:UIControlStateNormal];
  174. // [g_App showAlert:dict[@"resultMsg"]];
  175. // [self getImgCodeImg];
  176. return hide_error;
  177. }
  178. return show_error;
  179. }
  180. @end