RegistTestVC.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. //
  2. // RegistTestVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 2017/9/26.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "RegistTestVC.h"
  9. #import "Message_SMS_VC.h"
  10. #import "QGPassWordTextField.h"
  11. @interface RegistTestVC ()
  12. {
  13. QGPassWordTextField *pswTextField;
  14. UIButton *registBtn;
  15. UIButton *reSendBtn;
  16. NSTimer *timer;
  17. int seconds;
  18. int pswLength;
  19. NSString *pswString;
  20. }
  21. @end
  22. @implementation RegistTestVC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.view.backgroundColor = [UIColor whiteColor];
  26. self.title = @"验证手机";
  27. [self configNavigationBar];
  28. pswString = @"";
  29. pswLength = 4;
  30. CGFloat x,y,w,h;
  31. x = y = 20;
  32. w = kSize.width - 2*x;
  33. h = 50;
  34. UILabel *label = [[UILabel alloc] setxywh];
  35. [label setText:[NSString stringWithFormat:@"验证码已发送至%@,请输入以完成注册",_phoneString] Font:Font17 TextColor:kTitleColor];
  36. label.numberOfLines = 0;
  37. [self.view addSubview:label];
  38. y += h + 10;
  39. h = 40.0;
  40. w = h * pswLength;
  41. x = (kSize.width - w)/2.0;
  42. pswTextField = [[QGPassWordTextField alloc]setxywh];
  43. pswTextField.showNumber = YES;
  44. pswTextField.showHorizontal = YES;
  45. pswTextField.passWordCount = pswLength;
  46. pswTextField.notJudgeComplete = YES;
  47. [pswTextField finishInput:^(NSString *password) {
  48. // NSLog(@"输入了----->>>>%@",password);
  49. pswString = password;
  50. if (password.length < pswLength) {
  51. registBtn.backgroundColor = contentTextColor;
  52. }else {
  53. registBtn.backgroundColor = defGreen;
  54. }
  55. }];
  56. [self.view addSubview:pswTextField];
  57. y += h + 20;
  58. x = 20;
  59. w = kSize.width - 2*x;
  60. UIButton *btn = [[UIButton alloc] setxywh];
  61. [btn setTitle:@"60秒后可重发" textColor:contentTextColor font:Font17 fotState:UIControlStateNormal];
  62. [btn target:self tag:1];
  63. [self.view addSubview:btn];
  64. reSendBtn = btn;
  65. y += h + 5;
  66. btn = [[UIButton alloc] setxywh];
  67. btn.backgroundColor = contentTextColor;
  68. [btn setTitle:@"注册" textColor:[UIColor whiteColor] font:Font17 fotState:UIControlStateNormal];
  69. [btn borderColor:defGreen width:0.7 cornorRadios:4];
  70. [btn target:self tag:2];
  71. [self.view addSubview:btn];
  72. registBtn = btn;
  73. //下发验证码
  74. // [self sendVerityAction];
  75. }
  76. - (void)changeReSendBtn {
  77. seconds --;
  78. if (seconds > 0) {
  79. [reSendBtn setTitle:[NSString stringWithFormat:@"%d秒后可重发",seconds] forState:UIControlStateNormal];
  80. }else {
  81. //可以重新发送了
  82. if (timer) {
  83. [timer invalidate];
  84. timer = nil;
  85. }
  86. [reSendBtn setTitle:@"重新发送" forState:UIControlStateNormal];
  87. }
  88. }
  89. - (void)btnClick:(UIButton *)sender {
  90. if (sender.tag == 1) {//发送验证码
  91. if (sender > 0) {
  92. [self showAlertWithMsg:@"验证码还在路上,请耐心等待"];
  93. }else {
  94. // [self sendVerityAction];
  95. }
  96. return;
  97. }
  98. if (sender.tag == 2) {//注册
  99. if (pswString.length < pswLength) {
  100. [self showAlertWithMsg:@"请输入完整验证码!"];
  101. }else {
  102. [self.view endEditing:YES];
  103. //验证 成功注册 失败返回上一级 提示验证失败
  104. [self checkVerityCode];
  105. }
  106. }
  107. }
  108. - (void)showAlertWithMsg:(NSString *)msg {
  109. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  110. [alert show];
  111. }
  112. #pragma mark shareSDK 短信验证
  113. //发送验证码
  114. //- (void)sendVerityAction {
  115. //
  116. // if (![Util connectedToNetWork]) {
  117. // showMsgUnconnect();
  118. // return;
  119. // }
  120. // //获取Plist文件路径
  121. // NSString *path = [[NSBundle mainBundle] pathForResource:@"SMSSDKError" ofType:@"plist"];
  122. // //获取Plist文件内容
  123. // NSDictionary *SMSSDKErrorDict = [NSDictionary dictionaryWithContentsOfFile:path];
  124. // [MBProgressHUD showLoadToView:self.view];
  125. // [RQ_SHARE_FUNCTION checkMobPolicyOnResult:^(BOOL success) {
  126. // [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:_phoneString zone:@"86" template:nil result:^(NSError *error) {
  127. // [MBProgressHUD hideHUDForView:self.view];
  128. //
  129. // if (error) {
  130. // NSString *errorCode = [NSString stringWithFormat:@"%ld",(long)error.code];
  131. // if ([SMSSDKErrorDict.allKeys containsObject:errorCode]) {
  132. // [self showAlertWithMsg:[SMSSDKErrorDict objectForKey:errorCode]];
  133. // }else {
  134. // [self showAlertWithMsg:[NSString stringWithFormat:@"验证码发送错误%@",error]];
  135. // }
  136. // } else {
  137. // //NSLog(@"验证码已发送");
  138. // [self showAlertWithMsg:@"验证码已发送"];
  139. //
  140. // //这个放在下发验证码成功的地方
  141. // seconds = 60;
  142. // timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeReSendBtn) userInfo:nil repeats:YES];
  143. // [timer fire];
  144. // }
  145. // }];
  146. // }];
  147. //}
  148. //判断验证码是否正确
  149. - (void)checkVerityCode {
  150. // if (![Util connectedToNetWork]) {
  151. // showMsgUnconnect();
  152. // return;
  153. // }
  154. // [MBProgressHUD showLoadToView:self.view];
  155. // [SMSSDK commitVerificationCode:pswString phoneNumber:_phoneString zone:@"86" result:^(NSError *error) {
  156. //
  157. // if (error) {
  158. // [MBProgressHUD hideHUDForView:self.view];
  159. // [self showAlertWithMsg:@"验证码错误,注册失败!"];
  160. // UIViewController *vc = [self.navigationController.viewControllers firstObject];
  161. // [self.navigationController popToViewController:vc animated:YES];
  162. // } else {
  163. // //验证成功 调注册接口
  164. // [self stuRegister];
  165. // }
  166. // }];
  167. }
  168. -(void)stuRegister
  169. {
  170. NSMutableArray *arr=[NSMutableArray array];
  171. [arr addPro:@"tel" Value:_phoneString];
  172. [arr addPro:@"pwd" Value:[_passwordString md5Encrypt]];
  173. NSString* method = @"register";
  174. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  175. [MBProgressHUD hideHUDForView:self.view];
  176. //NSLog(@"密码返回数据->%@",root);
  177. if (!root) {
  178. ShowMsgFailed();
  179. return;
  180. }
  181. if ( 1 == [root[@"code"] integerValue]) {
  182. ShowMsg(root[@"body"]);
  183. return;
  184. }
  185. ShowMsg(@"注册成功,请登录!");
  186. [self.navigationController dismissViewControllerAnimated:NO completion:nil];
  187. }];
  188. }
  189. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  190. [self.view endEditing:YES];
  191. }
  192. - (void)didReceiveMemoryWarning {
  193. [super didReceiveMemoryWarning];
  194. }
  195. @end