BindVC.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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.text = @"123456";
  79. textField.keyboardType = UIKeyboardTypeNumberPad;
  80. // [self.view addSubview:textField];
  81. bindNumField = textField;
  82. y += h + 10;
  83. x = 20;
  84. w = kSize.width - 40;
  85. h = 40;
  86. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  87. btn.frame = setDIYFrame;
  88. [btn target:self Tag:2];
  89. [btn setTitle:@"绑定" textColor:[UIColor whiteColor] font:Font16 fotState:UIControlStateNormal];
  90. btn.backgroundColor = defGreen;
  91. [btn borderColor:defGreen width:1 cornorRadios:10];
  92. [self.view addSubview:btn];
  93. y += 20 + h;
  94. h = 150;
  95. UILabel *label = [[UILabel alloc] setxywh];
  96. label.numberOfLines = 0;
  97. [label setText:@"1 教练只有绑定后才能带教学员\n2 绑定手机后,如因特殊情况如手机丢失,可向驾校申请,由运管审批后可以更改绑定\n3 每部手机只能绑定一次,绑定后本手机只能用于绑定用户带教学员\n4 绑定流程:输入手机号码获取验证码-确认验证码-绑定成功" Font:Font16 TextColor:contentTextColor];
  98. [self.view addSubview:label];
  99. }
  100. -(void)btnClick:(UIButton *)sender
  101. {
  102. [self.view endEditing:YES];
  103. if (sender.tag == 1) {
  104. //获取验证码
  105. if ([Tools isMobileNumber:telNumField.text]) {
  106. [self applyAppBindStudent];
  107. }else{
  108. ShowMsg(@"请核对电话号码");
  109. }
  110. return;
  111. }
  112. if (sender.tag == 2) {
  113. //绑定
  114. if (telNumField.text.length < 1) {
  115. // ShowMsg(@"请输入手机号获取验证码");
  116. ShowMsg(@"请输入终端对应的手机号码");
  117. return;
  118. }
  119. if (bindNumField.text.length < 1) {
  120. ShowMsg(@"请输入验证码!");
  121. return;
  122. }
  123. NSString *idfaString = [Tools getIDFV];
  124. if ([idfaString isEqualToString:@"00000000-0000-0000-0000-000000000000"] || [idfaString isEqualToString:@"00000000000000000000000000000000"]) {
  125. //要打开广告标识位 打开“设置”菜单 下滑,选择“隐私”菜单 点击“广告”菜单,系统检测开启状态 如果选项是灰色,说明“限制广告跟踪”功能是关闭,往右划动即可开启。 “限制广告跟踪”功能开启后,iphone就阻止了第三方软件获取您的隐私Cookie信息。保证您的个人隐私安全。
  126. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"获取标识失败,请在“设置-隐私-广告”中,关闭“限制广告跟踪”。" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  127. [alert show];
  128. return;
  129. }
  130. //绑定
  131. // [self clickToSubmit];
  132. [self doBindCoachImei]; //去掉短信验证
  133. }
  134. }
  135. -(void)timeRun
  136. {
  137. second --;
  138. countDownLabel.text = [NSString stringWithFormat:@"重新获取验证码(%d秒)",(int)second];
  139. if (second <1) {
  140. [timer invalidate];
  141. timer = nil;
  142. [getBindNumBtn setTitle:@"点击获取验证码" forState:UIControlStateNormal];
  143. countDownLabel.hidden = YES;
  144. getBindNumBtn.userInteractionEnabled = YES;
  145. }
  146. }
  147. -(void)bindSuccessWithBlock:(BlockTypeVo)aBlock
  148. {
  149. bindBlock = aBlock;
  150. }
  151. -(void)applyAppBindStudent
  152. {
  153. [LoadingView showHUD];
  154. if (![Util connectedToNetWork]) {
  155. showMsgUnconnect();
  156. return;
  157. }
  158. getBindNumBtn.userInteractionEnabled = NO;
  159. [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:telNumField.text zone:@"86" result:^(NSError *error) {
  160. RemoveHUD();
  161. //NSLog(@"验证码请求---->%@---%@",arr,root);
  162. if (error)
  163. {
  164. if (error.code == 477) {
  165. ShowMsg(@"当天验证次数已超上限");
  166. }else{
  167. ShowMsg(@"请检查手机号码是否正确");
  168. }
  169. getBindNumBtn.userInteractionEnabled = YES;
  170. return;
  171. }
  172. ShowMsg(@"验证码已发送。请注意查收");
  173. second = 60;
  174. timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeRun) userInfo:nil repeats:YES];
  175. countDownLabel.hidden = NO;
  176. [getBindNumBtn setTitle:@"" forState:UIControlStateNormal];
  177. }];
  178. }
  179. -(void)clickToSubmit
  180. {
  181. ShowHUD();
  182. //验证验证码是否正确
  183. if (![Util connectedToNetWork]) {
  184. showMsgUnconnect();
  185. return;
  186. }
  187. [SMSSDK commitVerificationCode:bindNumField.text phoneNumber:telNumField.text zone:@"86" result:^(NSError *error) {
  188. RemoveHUD();
  189. if (error) {
  190. ShowMsg(@"验证码错误,请重新输入验证码");
  191. } else {
  192. //验证成功 发起绑定
  193. //ShowMsg(@"短信验证成功,正在进行绑定。。。");
  194. [self doBindCoachImei];
  195. }
  196. }];
  197. }
  198. -(void)doBindCoachImei
  199. {
  200. if (![Util connectedToNetWork]) {
  201. showMsgUnconnect();
  202. return;
  203. }
  204. NSString *systemName = [[UIDevice currentDevice] systemName];
  205. NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
  206. NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
  207. NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
  208. NSMutableArray *arr=[NSMutableArray array];
  209. [arr addPro:@"coachOutId" Value:defUser.userDict[@"outId"]];
  210. [arr addPro:@"sim" Value:telNumField.text];
  211. [arr addPro:@"imei" Value:[Tools getIDFV]];
  212. [arr addPro:@"softVersion" Value:[NSString stringWithFormat:@"教练管家 %@",currentVersion]];
  213. [arr addPro:@"firmware" Value:[NSString stringWithFormat:@"%@ %@",systemName,systemVersion]];
  214. [arr addPro:@"jxbh" Value:defUser.userDict[@"jxbh"]];
  215. [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
  216. NSString* method = @"doBindCoachImei";
  217. [LoadingView showHUD];
  218. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  219. RemoveHUD();
  220. if (!root) {
  221. ShowMsg(@"绑定失败,请重试");
  222. return;
  223. }
  224. if ([root[@"code"] isEqualToString:@"1"]) {
  225. ShowMsg(root[@"body"]);
  226. return;
  227. }
  228. ShowMsg(@"绑定成功");
  229. [self.view endEditing:1];
  230. [self.navigationController popViewControllerAnimated:NO];
  231. if (bindBlock) {
  232. bindBlock();
  233. }
  234. }];
  235. }
  236. -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  237. {
  238. [self.view endEditing:YES];
  239. }
  240. - (void)didReceiveMemoryWarning {
  241. [super didReceiveMemoryWarning];
  242. }
  243. @end