123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- //
- // BindVC.m
- // jiaPeiC
- //
- // Created by apple on 16/8/15.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "BindVC.h"
- #import "Tools.h"
- //#import <SMS_SDK/SMSSDK.h>
- @interface BindVC ()<UIAlertViewDelegate>
- {
- UITextField *telNumField;
- UITextField *bindNumField;
- UIButton *getBindNumBtn;
- UILabel *countDownLabel;
-
- NSTimer *timer;
- NSInteger second;
- }
- @end
- @implementation BindVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"手机绑定";
- self.view.backgroundColor = backGroundColor;
- [self configNavigationBar];
-
- [self myInit];
- }
- /**
- 1 每部手机只能绑定一次,绑定后本手机只能用于绑定用户实操和先学后付计时
- 2 绑定手机后,如因特殊情况如手机丢失,可向驾校申请,由运管审批后可以更改绑定
- 3 学员只有绑定后才能进行实操计时
- 4 绑定流程:输入手机号码-获取绑定码-确认绑定
- */
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self.view endEditing:YES];
-
- if (timer) {
- [timer invalidate];
- timer = nil;
- }
- }
- -(void)configNavigationBarDismissNav
- {
- UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNav)];
- [backBbi setTintColor:defGreen];
- self.navigationController.navigationBar.translucent = NO;
- [self.navigationItem setLeftBarButtonItem:backBbi];
- }
- -(void)dismissNav
- {
- [self.view endEditing:YES];
- [self.navigationController dismissViewControllerAnimated:NO completion:nil];
- }
- -(void)myInit
- {
- UIScrollView *scrV = [[UIScrollView alloc]initWithFrame:kFrame];
- scrV.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
- UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchScrollView)];
- [scrV addGestureRecognizer:recognizer];
- [self.view addSubview:scrV];
-
- CGFloat x,y,w,h;
-
- x = 20;
- w = kSize.width - 40;
- y = 20;
- h = 40;
- UITextField *textField = [[UITextField alloc] setxywh];
- textField.borderStyle = UITextBorderStyleNone;
- textField.placeholder = @"请输入手机号";
- textField.keyboardType = UIKeyboardTypeNumberPad;
- textField.backgroundColor = [UIColor clearColor];
- [scrV addSubview:textField];
- telNumField = textField;
-
- y += h + 10;
- x = 20;
- w = kSize.width - 40;
- h = 40;
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = setDIYFrame;
- [btn target:self tag:1];
- [btn setTitle:@"点击获取验证码" textColor:[UIColor whiteColor] font:FontTitle fotState:UIControlStateNormal];
- btn.backgroundColor = defGreen;
- [btn borderColor:defGreen width:1 cornorRadios:10];
- [scrV addSubview:btn];
- getBindNumBtn = btn;
-
- countDownLabel = [[UILabel alloc] initWithFrame:setDIYFrame];
- [countDownLabel setText:@"" Font:FontTitle TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
- countDownLabel.backgroundColor = [UIColor clearColor];
- [scrV addSubview:countDownLabel];
- countDownLabel.hidden = YES;
-
- x = 20;
- w = kSize.width - 40;
- y += h + 30;
- h = 40;
- textField = [[UITextField alloc] setxywh];
- textField.borderStyle = UITextBorderStyleRoundedRect;
- textField.clearButtonMode = UITextFieldViewModeAlways;
- textField.placeholder = @"请输入验证码";
- textField.keyboardType = UIKeyboardTypeNumberPad;
- [scrV addSubview:textField];
- bindNumField = textField;
-
- y += h + 10;
- x = 20;
- w = kSize.width - 40;
- h = 40;
- btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = setDIYFrame;
- [btn target:self tag:2];
- [btn setTitle:@"绑定" textColor:[UIColor whiteColor] font:FontTitle fotState:UIControlStateNormal];
- btn.backgroundColor = defGreen;
- [btn borderColor:defGreen width:1 cornorRadios:10];
- [scrV addSubview:btn];
-
- y += 20 + h;
- h = 0;
- UILabel *label = [[UILabel alloc] setxywh];
- label.numberOfLines = 0;
- [label setText:@"1 每部手机只能绑定一次,绑定成功后该手机只能用于绑定用户计学时;\n2 如因特殊情况(如手机丢失),可向驾校申请重新绑定;\n3 学员只有绑定后才能进行计学时;\n4该手机号为学员报名时登记的手机号。如果手机号码有误,请联系驾校修改 \n5 绑定流程:点击获取验证码-输入验证码-点击绑定" Font:NormalFont TextColor:contentTextColor];
- [label sizeToFit];
- [scrV addSubview:label];
-
- [scrV setContentSize:CGSizeMake(0, CGRectGetMaxY(label.frame))];
-
- telNumField.text = defUser.userDict[@"telphone"];
- telNumField.userInteractionEnabled = NO;
- }
- -(void)btnClick:(UIButton *)sender
- {
- [self.view endEditing:YES];
- if (sender.tag == 1) {
- //获取验证码
- if ([Tools isMobileNumber:telNumField.text]) {
- [self applyAppBindStudent];
- }else{
- ShowMsg(@"请核对电话号码");
- }
- }
- if (sender.tag == 2) {
-
- if (telNumField.text.length < 1) {
- ShowMsg(@"请输入手机号获取验证码");
- return;
- }
- if (bindNumField.text.length < 1) {
- ShowMsg(@"请输入验证码!");
- return;
- }
-
- //绑定
- [self clickToSubmit];
- }
- }
- -(void)timeRun
- {
- second --;
- countDownLabel.text = [NSString stringWithFormat:@"重新获取验证码(%d秒)",(int)second];
-
- if (second <1) {
- [timer invalidate];
- timer = nil;
- [getBindNumBtn setTitle:@"点击获取验证码" forState:UIControlStateNormal];
- countDownLabel.hidden = YES;
- getBindNumBtn.userInteractionEnabled = YES;
- }
- }
- -(void)bindSuccessWithBlock:(BlockTypeVo)aBlock
- {
- bindBlock = aBlock;
- }
- -(void)applyAppBindStudent
- {
- // if (![Util connectedToNetWork]) {
- // showMsgUnconnect();
- // return;
- // }
- //
- // getBindNumBtn.userInteractionEnabled = NO;
- // [MBProgressHUD showLoadToView:self.view];
- // [RQ_SHARE_FUNCTION checkMobPolicyOnResult:^(BOOL success) {
- // [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:telNumField.text zone:@"86" template:nil result:^(NSError *error) {
- // [MBProgressHUD hideHUDForView:self.view];
- //
- // if (error)
- // {
- // if (error.code == 477) {
- // ShowMsg(@"当天验证次数已超上限");
- // }else{
- // ShowMsg(@"请检查手机号码是否正确");
- // }
- //
- // getBindNumBtn.userInteractionEnabled = YES;
- // return;
- // }
- // ShowMsg(@"验证码已发送。请注意查收");
- // second = 60;
- // timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeRun) userInfo:nil repeats:YES];
- // countDownLabel.hidden = NO;
- // [getBindNumBtn setTitle:@"" forState:UIControlStateNormal];
- // }];
- // }];
- }
- -(void)clickToSubmit
- {
- // //验证验证码是否正确
- // if (![Util connectedToNetWork]) {
- // showMsgUnconnect();
- // return;
- // }
- //
- // [MBProgressHUD showLoadToView:self.view];
- // [SMSSDK commitVerificationCode:bindNumField.text phoneNumber:telNumField.text zone:@"86" result:^(NSError *error) {
- //
- // if (error) {
- // [MBProgressHUD hideHUDForView:self.view];
- // ShowMsg(@"验证码错误,请重新输入验证码");
- // } else {
- // //验证成功 发起绑定
- // //ShowMsg(@"短信验证成功,正在进行绑定。。。");
- // [self uploadBindStuImei];
- // }
- // }];
- //
- }
- - (void)uploadBindStuImei {
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
- [arr addPro:@"sfzhm" Value:defUser.sfzmhm];
- [arr addPro:@"tel" Value:telNumField.text];
- if ([Tools getIDFAWithType:GetIDFAType_Default]) {
- [arr addPro:@"imei" Value:[Tools getIDFAWithType:GetIDFAType_Default]];
- }else {
- return;
- }
- [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
-
- NSString* method = @"bindImei";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
-
- [MBProgressHUD hideHUDForView:self.view];
- if (!root) {
- ShowMsg(@"绑定失败,请重试");
- return;
- }
-
- if ([root[@"code"] isEqualToString:@"0"]) {
- showMsgByAlertWithSureBlock(self, @"绑定成功", ^{
- [self.navigationController dismissViewControllerAnimated:NO completion:nil];
- if (bindBlock) {
- bindBlock();
- }
- });
- }else{
- showMsgByAlert(self, root[@"msg"]);
- }
- }];
- }
- -(void)touchScrollView{
- [self.view endEditing:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|