BindVC.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. //
  2. // BindVC.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/8/15.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "BindVC.h"
  9. #import "Tools.h"
  10. #import <SMS_SDK/SMSSDK.h>
  11. @interface BindVC ()<UIAlertViewDelegate>
  12. {
  13. UITextField *telNumField;
  14. UITextField *bindNumField;
  15. UIButton *getBindNumBtn;
  16. UILabel *countDownLabel;
  17. NSTimer *timer;
  18. NSInteger second;
  19. }
  20. @end
  21. @implementation BindVC
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.title = @"手机绑定";
  25. self.view.backgroundColor = backGroundColor;
  26. [self configNavBar];
  27. [self myInit];
  28. }
  29. -(void)viewWillDisappear:(BOOL)animated
  30. {
  31. [super viewWillDisappear:animated];
  32. [self.view endEditing:YES];
  33. if (timer) {
  34. [timer invalidate];
  35. timer = nil;
  36. }
  37. [LoadingView removeHUD];
  38. }
  39. -(void)myInit
  40. {
  41. CGFloat x,y,w,h;
  42. x = 20;
  43. w = kSize.width - 40;
  44. y = 20 + kNavOffSet;
  45. h = 40;
  46. UITextField *textField = [[UITextField alloc] setxywh];
  47. textField.borderStyle = UITextBorderStyleRoundedRect;
  48. textField.clearButtonMode = UITextFieldViewModeAlways;
  49. textField.placeholder = @"请输入手机号";
  50. textField.keyboardType = UIKeyboardTypeNumberPad;
  51. [self.view addSubview:textField];
  52. telNumField = textField;
  53. y += h + 10;
  54. x = 20;
  55. w = kSize.width - 40;
  56. h = 40;
  57. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  58. btn.frame = setDIYFrame;
  59. [btn target:self Tag:1];
  60. [btn setTitle:@"点击获取验证码" textColor:[UIColor whiteColor] font:Font16 fotState:UIControlStateNormal];
  61. btn.backgroundColor = defGreen;
  62. [btn borderColor:defGreen width:1 cornorRadios:10];
  63. [self.view addSubview:btn];
  64. getBindNumBtn = btn;
  65. countDownLabel = [[UILabel alloc] initWithFrame:setDIYFrame];
  66. [countDownLabel setText:@"" Font:Font16 TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
  67. countDownLabel.backgroundColor = [UIColor clearColor];
  68. [self.view addSubview:countDownLabel];
  69. countDownLabel.hidden = YES;
  70. x = 20;
  71. w = kSize.width - 40;
  72. y += h + 30;
  73. h = 40;
  74. textField = [[UITextField alloc] setxywh];
  75. textField.borderStyle = UITextBorderStyleRoundedRect;
  76. textField.clearButtonMode = UITextFieldViewModeAlways;
  77. textField.placeholder = @"请输入验证码";
  78. textField.keyboardType = UIKeyboardTypeNumberPad;
  79. [self.view addSubview:textField];
  80. bindNumField = textField;
  81. y += h + 10;
  82. x = 20;
  83. w = kSize.width - 40;
  84. h = 40;
  85. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  86. btn.frame = setDIYFrame;
  87. [btn target:self Tag:2];
  88. [btn setTitle:@"绑定" textColor:[UIColor whiteColor] font:Font16 fotState:UIControlStateNormal];
  89. btn.backgroundColor = defGreen;
  90. [btn borderColor:defGreen width:1 cornorRadios:10];
  91. [self.view addSubview:btn];
  92. y += 20 + h;
  93. h = 150;
  94. UILabel *label = [[UILabel alloc] setxywh];
  95. label.numberOfLines = 0;
  96. [label setText:@"1 教练只有绑定后才能带教学员\n2 绑定手机后,如因特殊情况如手机丢失,可向驾校申请,由运管审批后可以更改绑定\n3 每部手机只能绑定一次,绑定后本手机只能用于绑定用户带教学员\n4 绑定流程:输入手机号码获取验证码-确认验证码-绑定成功" Font:Font16 TextColor:contentTextColor];
  97. [self.view addSubview:label];
  98. }
  99. -(void)btnClick:(UIButton *)sender
  100. {
  101. [self.view endEditing:YES];
  102. if (sender.tag == 1) {
  103. //获取验证码
  104. if ([Tools isMobileNumber:telNumField.text]) {
  105. [self applyAppBindStudent];
  106. }else{
  107. ShowMsg(@"请核对电话号码");
  108. }
  109. return;
  110. }
  111. if (sender.tag == 2) {
  112. //绑定
  113. if (telNumField.text.length < 1) {
  114. ShowMsg(@"请输入手机号获取验证码");
  115. return;
  116. }
  117. if (bindNumField.text.length < 1) {
  118. ShowMsg(@"请输入验证码!");
  119. return;
  120. }
  121. NSString *idfaString = [Tools getIDFV];
  122. if ([idfaString isEqualToString:@"00000000-0000-0000-0000-000000000000"] || [idfaString isEqualToString:@"00000000000000000000000000000000"]) {
  123. //要打开广告标识位 打开“设置”菜单 下滑,选择“隐私”菜单 点击“广告”菜单,系统检测开启状态 如果选项是灰色,说明“限制广告跟踪”功能是关闭,往右划动即可开启。 “限制广告跟踪”功能开启后,iphone就阻止了第三方软件获取您的隐私Cookie信息。保证您的个人隐私安全。
  124. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"获取标识失败,请在“设置-隐私-广告”中,关闭“限制广告跟踪”。" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  125. [alert show];
  126. return;
  127. }
  128. //绑定
  129. [self clickToSubmit];
  130. }
  131. }
  132. -(void)timeRun
  133. {
  134. second --;
  135. countDownLabel.text = [NSString stringWithFormat:@"重新获取验证码(%d秒)",(int)second];
  136. if (second <1) {
  137. [timer invalidate];
  138. timer = nil;
  139. [getBindNumBtn setTitle:@"点击获取验证码" forState:UIControlStateNormal];
  140. countDownLabel.hidden = YES;
  141. getBindNumBtn.userInteractionEnabled = YES;
  142. }
  143. }
  144. -(void)bindSuccessWithBlock:(BlockTypeVo)aBlock
  145. {
  146. bindBlock = aBlock;
  147. }
  148. -(void)applyAppBindStudent
  149. {
  150. [LoadingView showHUD];
  151. if (![Util connectedToNetWork]) {
  152. showMsgUnconnect();
  153. return;
  154. }
  155. getBindNumBtn.userInteractionEnabled = NO;
  156. [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:telNumField.text zone:@"86" result:^(NSError *error) {
  157. RemoveHUD();
  158. //NSLog(@"验证码请求---->%@---%@",arr,root);
  159. if (error)
  160. {
  161. if (error.code == 477) {
  162. ShowMsg(@"当天验证次数已超上限");
  163. }else{
  164. ShowMsg(@"请检查手机号码是否正确");
  165. }
  166. getBindNumBtn.userInteractionEnabled = YES;
  167. return;
  168. }
  169. ShowMsg(@"验证码已发送。请注意查收");
  170. second = 60;
  171. timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeRun) userInfo:nil repeats:YES];
  172. countDownLabel.hidden = NO;
  173. [getBindNumBtn setTitle:@"" forState:UIControlStateNormal];
  174. }];
  175. }
  176. -(void)clickToSubmit
  177. {
  178. ShowHUD();
  179. //验证验证码是否正确
  180. if (![Util connectedToNetWork]) {
  181. showMsgUnconnect();
  182. return;
  183. }
  184. [SMSSDK commitVerificationCode:bindNumField.text phoneNumber:telNumField.text zone:@"86" result:^(NSError *error) {
  185. RemoveHUD();
  186. if (error) {
  187. ShowMsg(@"验证码错误,请重新输入验证码");
  188. } else {
  189. //验证成功 发起绑定
  190. //ShowMsg(@"短信验证成功,正在进行绑定。。。");
  191. [self doBindCoachImei];
  192. }
  193. }];
  194. }
  195. -(void)doBindCoachImei
  196. {
  197. if (![Util connectedToNetWork]) {
  198. showMsgUnconnect();
  199. return;
  200. }
  201. NSString *systemName = [[UIDevice currentDevice] systemName];
  202. NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
  203. NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
  204. NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
  205. NSMutableArray *arr=[NSMutableArray array];
  206. [arr addPro:@"coachOutId" Value:defUser.userDict[@"outId"]];
  207. [arr addPro:@"sim" Value:telNumField.text];
  208. [arr addPro:@"imei" Value:[Tools getIDFV]];
  209. [arr addPro:@"softVersion" Value:[NSString stringWithFormat:@"优易学车教练版 %@",currentVersion]];
  210. [arr addPro:@"firmware" Value:[NSString stringWithFormat:@"%@ %@",systemName,systemVersion]];
  211. [arr addPro:@"jxbh" Value:defUser.userDict[@"jxbh"]];
  212. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  213. NSString* method = @"doBindCoachImei";
  214. [LoadingView showHUD];
  215. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  216. RemoveHUD();
  217. if (!root) {
  218. ShowMsg(@"绑定失败,请重试");
  219. return;
  220. }
  221. if ([root[@"code"] isEqualToString:@"1"]) {
  222. ShowMsg(root[@"body"]);
  223. return;
  224. }
  225. ShowMsg(@"绑定成功");
  226. [self.view endEditing:1];
  227. [self.navigationController popViewControllerAnimated:NO];
  228. if (bindBlock) {
  229. bindBlock();
  230. }
  231. }];
  232. }
  233. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  234. {
  235. [self.view endEditing:YES];
  236. }
  237. - (void)didReceiveMemoryWarning {
  238. [super didReceiveMemoryWarning];
  239. }
  240. @end