123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- //
- // 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 configNavBar];
-
- [self myInit];
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self.view endEditing:YES];
-
- if (timer) {
- [timer invalidate];
- timer = nil;
- }
-
- [LoadingView removeHUD];
- }
- -(void)myInit
- {
- CGFloat x,y,w,h;
-
- x = 20;
- w = kSize.width - 40;
- y = 20 + kNavOffSet;
- h = 40;
- UITextField *textField = [[UITextField alloc] setxywh];
- textField.borderStyle = UITextBorderStyleRoundedRect;
- textField.clearButtonMode = UITextFieldViewModeAlways;
- textField.placeholder = @"请输入手机号";
- textField.keyboardType = UIKeyboardTypeNumberPad;
- [self.view 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:Font16 fotState:UIControlStateNormal];
- btn.backgroundColor = defGreen;
- [btn borderColor:defGreen width:1 cornorRadios:10];
- [self.view addSubview:btn];
- getBindNumBtn = btn;
-
- countDownLabel = [[UILabel alloc] initWithFrame:setDIYFrame];
- [countDownLabel setText:@"" Font:Font16 TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
- countDownLabel.backgroundColor = [UIColor clearColor];
- [self.view 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;
- [self.view 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:Font16 fotState:UIControlStateNormal];
- btn.backgroundColor = defGreen;
- [btn borderColor:defGreen width:1 cornorRadios:10];
- [self.view addSubview:btn];
-
- y += 20 + h;
- h = 150;
- UILabel *label = [[UILabel alloc] setxywh];
- label.numberOfLines = 0;
- [label setText:@"1 教练只有绑定后才能带教学员\n2 绑定手机后,如因特殊情况如手机丢失,可向驾校申请,由运管审批后可以更改绑定\n3 每部手机只能绑定一次,绑定后本手机只能用于绑定用户带教学员\n4 绑定流程:输入手机号码获取验证码-确认验证码-绑定成功" Font:Font16 TextColor:contentTextColor];
- [self.view addSubview:label];
- }
- -(void)btnClick:(UIButton *)sender
- {
- [self.view endEditing:YES];
- if (sender.tag == 1) {
- //获取验证码
-
- if ([Tools isMobileNumber:telNumField.text]) {
- [self applyAppBindStudent];
- }else{
- ShowMsg(@"请核对电话号码");
- }
- return;
- }
- if (sender.tag == 2) {
- //绑定
- if (telNumField.text.length < 1) {
- ShowMsg(@"请输入手机号获取验证码");
- return;
- }
- if (bindNumField.text.length < 1) {
- ShowMsg(@"请输入验证码!");
- return;
- }
-
- NSString *idfaString = [Tools getIDFV];
- if ([idfaString isEqualToString:@"00000000-0000-0000-0000-000000000000"] || [idfaString isEqualToString:@"00000000000000000000000000000000"]) {
- //要打开广告标识位 打开“设置”菜单 下滑,选择“隐私”菜单 点击“广告”菜单,系统检测开启状态 如果选项是灰色,说明“限制广告跟踪”功能是关闭,往右划动即可开启。 “限制广告跟踪”功能开启后,iphone就阻止了第三方软件获取您的隐私Cookie信息。保证您的个人隐私安全。
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"获取标识失败,请在“设置-隐私-广告”中,关闭“限制广告跟踪”。" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
- [alert show];
-
- 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
- {
- [LoadingView showHUD];
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- getBindNumBtn.userInteractionEnabled = NO;
-
- [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:telNumField.text zone:@"86" result:^(NSError *error) {
- RemoveHUD();
- //NSLog(@"验证码请求---->%@---%@",arr,root);
- 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
- {
- ShowHUD();
- //验证验证码是否正确
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- [SMSSDK commitVerificationCode:bindNumField.text phoneNumber:telNumField.text zone:@"86" result:^(NSError *error) {
- RemoveHUD();
-
- if (error) {
- ShowMsg(@"验证码错误,请重新输入验证码");
-
- } else {
- //验证成功 发起绑定
- //ShowMsg(@"短信验证成功,正在进行绑定。。。");
- [self doBindCoachImei];
- }
- }];
-
- }
- -(void)doBindCoachImei
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
-
- NSString *systemName = [[UIDevice currentDevice] systemName];
- NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
-
- NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
- NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"coachOutId" Value:defUser.userDict[@"outId"]];
- [arr addPro:@"sim" Value:telNumField.text];
- [arr addPro:@"imei" Value:[Tools getIDFV]];
- [arr addPro:@"softVersion" Value:[NSString stringWithFormat:@"优易学车教练版 %@",currentVersion]];
- [arr addPro:@"firmware" Value:[NSString stringWithFormat:@"%@ %@",systemName,systemVersion]];
- [arr addPro:@"jxbh" Value:defUser.userDict[@"jxbh"]];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
- NSString* method = @"doBindCoachImei";
- [LoadingView showHUD];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
-
- RemoveHUD();
- if (!root) {
- ShowMsg(@"绑定失败,请重试");
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsg(root[@"body"]);
- return;
- }
-
- ShowMsg(@"绑定成功");
- [self.view endEditing:1];
- [self.navigationController popViewControllerAnimated:NO];
- if (bindBlock) {
- bindBlock();
- }
- }];
- }
- -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- [self.view endEditing:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|