123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- //
- // RegistTestVC.m
- // jiaPei
- //
- // Created by apple on 2017/9/26.
- // Copyright © 2017年 JCZ. All rights reserved.
- //
- #import "RegistTestVC.h"
- #import "Message_SMS_VC.h"
- #import "QGPassWordTextField.h"
- @interface RegistTestVC ()
- {
- QGPassWordTextField *pswTextField;
- UIButton *registBtn;
- UIButton *reSendBtn;
-
-
- NSTimer *timer;
- int seconds;
- int pswLength;
- NSString *pswString;
- }
- @end
- @implementation RegistTestVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
- self.title = @"验证手机";
- [self configNavigationBar];
-
-
- pswString = @"";
- pswLength = 4;
-
- CGFloat x,y,w,h;
- x = y = 20;
- w = kSize.width - 2*x;
- h = 50;
- UILabel *label = [[UILabel alloc] setxywh];
- [label setText:[NSString stringWithFormat:@"验证码已发送至%@,请输入以完成注册",_phoneString] Font:Font17 TextColor:kTitleColor];
- label.numberOfLines = 0;
- [self.view addSubview:label];
-
-
- y += h + 10;
- h = 40.0;
- w = h * pswLength;
- x = (kSize.width - w)/2.0;
- pswTextField = [[QGPassWordTextField alloc]setxywh];
- pswTextField.showNumber = YES;
- pswTextField.showHorizontal = YES;
- pswTextField.passWordCount = pswLength;
- pswTextField.notJudgeComplete = YES;
- [pswTextField finishInput:^(NSString *password) {
- // NSLog(@"输入了----->>>>%@",password);
-
- pswString = password;
- if (password.length < pswLength) {
- registBtn.backgroundColor = contentTextColor;
- }else {
- registBtn.backgroundColor = defGreen;
- }
- }];
- [self.view addSubview:pswTextField];
-
-
- y += h + 20;
- x = 20;
- w = kSize.width - 2*x;
- UIButton *btn = [[UIButton alloc] setxywh];
- [btn setTitle:@"60秒后可重发" textColor:contentTextColor font:Font17 fotState:UIControlStateNormal];
- [btn target:self tag:1];
- [self.view addSubview:btn];
- reSendBtn = btn;
-
-
- y += h + 5;
- btn = [[UIButton alloc] setxywh];
- btn.backgroundColor = contentTextColor;
- [btn setTitle:@"注册" textColor:[UIColor whiteColor] font:Font17 fotState:UIControlStateNormal];
- [btn borderColor:defGreen width:0.7 cornorRadios:4];
- [btn target:self tag:2];
- [self.view addSubview:btn];
- registBtn = btn;
-
- //下发验证码
- // [self sendVerityAction];
- }
- - (void)changeReSendBtn {
-
- seconds --;
- if (seconds > 0) {
- [reSendBtn setTitle:[NSString stringWithFormat:@"%d秒后可重发",seconds] forState:UIControlStateNormal];
- }else {
- //可以重新发送了
- if (timer) {
- [timer invalidate];
- timer = nil;
- }
- [reSendBtn setTitle:@"重新发送" forState:UIControlStateNormal];
- }
- }
- - (void)btnClick:(UIButton *)sender {
-
- if (sender.tag == 1) {//发送验证码
- if (sender > 0) {
- [self showAlertWithMsg:@"验证码还在路上,请耐心等待"];
- }else {
- // [self sendVerityAction];
- }
- return;
- }
-
- if (sender.tag == 2) {//注册
- if (pswString.length < pswLength) {
- [self showAlertWithMsg:@"请输入完整验证码!"];
- }else {
- [self.view endEditing:YES];
- //验证 成功注册 失败返回上一级 提示验证失败
- [self checkVerityCode];
- }
- }
- }
- - (void)showAlertWithMsg:(NSString *)msg {
-
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
- [alert show];
- }
- #pragma mark shareSDK 短信验证
- //发送验证码
- //- (void)sendVerityAction {
- //
- // if (![Util connectedToNetWork]) {
- // showMsgUnconnect();
- // return;
- // }
- // //获取Plist文件路径
- // NSString *path = [[NSBundle mainBundle] pathForResource:@"SMSSDKError" ofType:@"plist"];
- // //获取Plist文件内容
- // NSDictionary *SMSSDKErrorDict = [NSDictionary dictionaryWithContentsOfFile:path];
- // [MBProgressHUD showLoadToView:self.view];
- // [RQ_SHARE_FUNCTION checkMobPolicyOnResult:^(BOOL success) {
- // [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:_phoneString zone:@"86" template:nil result:^(NSError *error) {
- // [MBProgressHUD hideHUDForView:self.view];
- //
- // if (error) {
- // NSString *errorCode = [NSString stringWithFormat:@"%ld",(long)error.code];
- // if ([SMSSDKErrorDict.allKeys containsObject:errorCode]) {
- // [self showAlertWithMsg:[SMSSDKErrorDict objectForKey:errorCode]];
- // }else {
- // [self showAlertWithMsg:[NSString stringWithFormat:@"验证码发送错误%@",error]];
- // }
- // } else {
- // //NSLog(@"验证码已发送");
- // [self showAlertWithMsg:@"验证码已发送"];
- //
- // //这个放在下发验证码成功的地方
- // seconds = 60;
- // timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeReSendBtn) userInfo:nil repeats:YES];
- // [timer fire];
- // }
- // }];
- // }];
- //}
- //判断验证码是否正确
- - (void)checkVerityCode {
-
- // if (![Util connectedToNetWork]) {
- // showMsgUnconnect();
- // return;
- // }
- // [MBProgressHUD showLoadToView:self.view];
- // [SMSSDK commitVerificationCode:pswString phoneNumber:_phoneString zone:@"86" result:^(NSError *error) {
- //
- // if (error) {
- // [MBProgressHUD hideHUDForView:self.view];
- // [self showAlertWithMsg:@"验证码错误,注册失败!"];
- // UIViewController *vc = [self.navigationController.viewControllers firstObject];
- // [self.navigationController popToViewController:vc animated:YES];
- // } else {
- // //验证成功 调注册接口
- // [self stuRegister];
- // }
- // }];
- }
- -(void)stuRegister
- {
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"tel" Value:_phoneString];
- [arr addPro:@"pwd" Value:[_passwordString md5Encrypt]];
- NSString* method = @"register";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
- [MBProgressHUD hideHUDForView:self.view];
- //NSLog(@"密码返回数据->%@",root);
- if (!root) {
- ShowMsgFailed();
- return;
- }
- if ( 1 == [root[@"code"] integerValue]) {
- ShowMsg(root[@"body"]);
- return;
- }
- ShowMsg(@"注册成功,请登录!");
- [self.navigationController dismissViewControllerAnimated:NO completion:nil];
- }];
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
-
- [self.view endEditing:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|