BogoThirdLoginViewController.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. //
  2. // BogoThirdLoginViewController.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/9/29.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoThirdLoginViewController.h"
  9. #import "BogoCountryChoiceViewController.h"
  10. @interface BogoThirdLoginViewController ()<UITextFieldDelegate,UITextViewDelegate>
  11. @property (weak, nonatomic) IBOutlet UITextField *phoneT;
  12. @property (weak, nonatomic) IBOutlet QMUIButton *codeBtn;
  13. @property (weak, nonatomic) IBOutlet QMUIButton *areaBtn;
  14. @property (weak, nonatomic) IBOutlet UIButton *confirmBtn;
  15. @property (weak, nonatomic) IBOutlet UITextField *codeT;
  16. @property (weak, nonatomic) IBOutlet UIImageView *headImgView;
  17. @property (weak, nonatomic) IBOutlet UILabel *nicknameL;
  18. @property (weak, nonatomic) IBOutlet UILabel *titleL;
  19. @property(nonatomic, strong) BogoChoiceAreaModel *areaModel;
  20. @end
  21. @implementation BogoThirdLoginViewController{
  22. NSTimer *_timer; //定时器
  23. int _timeCount; //定时器时间
  24. }
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. // Do any additional setup after loading the view from its nib.
  28. [self.titleL setText:ASLocalizedString(@"绑定手机号")];
  29. UITapGestureRecognizer *tapView = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickBgView:)];
  30. [self.view addGestureRecognizer:tapView];
  31. if (!self.areaModel) {
  32. self.areaModel = [BogoChoiceAreaModel new];
  33. self.areaModel.area_code = @"+86";
  34. }
  35. self.headImgView.layer.cornerRadius = 60 / 2;
  36. self.headImgView.layer.masksToBounds = YES;
  37. self.phoneT.delegate = self;
  38. [self.phoneT addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  39. self.phoneT.keyboardType = UIKeyboardTypeNumberPad;
  40. self.codeT.delegate = self;
  41. [self.codeT addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  42. self.codeT.keyboardType = UIKeyboardTypeNumberPad;
  43. self.areaBtn.imagePosition = QMUIButtonImagePositionRight;
  44. self.areaBtn.spacingBetweenImageAndTitle = 3;
  45. [self setPlaceholderTextWithTextfield:self.phoneT];
  46. [self setPlaceholderTextWithTextfield:self.codeT];
  47. [self.headImgView sd_setImageWithURL:[NSURL URLWithString:self.userInfo.iconurl] completed:nil];
  48. self.nicknameL.text = self.userInfo.name;
  49. _timeCount = 60;
  50. }
  51. -(void)clickBgView:(UITapGestureRecognizer *)sender{
  52. [self.view endEditing:YES];
  53. }
  54. - (void)setUserInfo:(UMSocialUserInfoResponse *)userInfo{
  55. _userInfo = userInfo;
  56. }
  57. -(void)textFieldDidChange:(UITextField *)textField{
  58. if (textField.text.length > 11) {
  59. self.phoneT.text = [textField.text substringToIndex:11];
  60. [FanweMessage alertHUD:ASLocalizedString(@"手机号限制11位数!")];
  61. }
  62. if (self.phoneT.text.length > 10 && self.codeT.text.length > 3) {
  63. self.confirmBtn.enabled = YES;
  64. }else{
  65. self.confirmBtn.enabled = NO;
  66. }
  67. }
  68. - (IBAction)getConfirmCodeBtn:(QMUIButton *)codeBtn {
  69. if (self.phoneT.text.length < 1)
  70. {
  71. [FanweMessage alert:ASLocalizedString(@"手机号限制11位数!")];
  72. return;
  73. }
  74. codeBtn.enabled = NO;
  75. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timego) userInfo:nil repeats:YES];
  76. [self timego];
  77. FWWeakify(self)
  78. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  79. [parmDict setObject:@"login" forKey:@"ctl"];
  80. [parmDict setObject:@"send_mobile_verify_international" forKey:@"act"];
  81. // [parmDict setObject:@"1" forKey:@"wx_binding"];
  82. [parmDict setObject:self.phoneT.text forKey:@"mobile"];
  83. [self showMyHud];
  84. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  85. {
  86. FWStrongify(self)
  87. [self hideMyHud];
  88. [GlobalVariables sharedInstance].otp_message_id = [NSString stringWithFormat:@"%@",[responseJson toString:@"otp_message_id"]];
  89. if ([responseJson toInt:@"status"] != 1)
  90. {
  91. codeBtn.enabled = YES;
  92. [codeBtn setTitle:ASLocalizedString(@"发送验证码") forState:UIControlStateNormal];
  93. [_timer invalidate];
  94. _timer = nil;
  95. }else{
  96. }
  97. } FailureBlock:^(NSError *error) {
  98. FWStrongify(self)
  99. [self hideMyHud];
  100. [codeBtn setTitle:ASLocalizedString(@"发送验证码") forState:UIControlStateNormal];
  101. [FanweMessage alert:ASLocalizedString(@"发送失败")];
  102. codeBtn.enabled = YES;
  103. }];
  104. }
  105. - (IBAction)clickConfirmBtn:(UIButton *)sender {
  106. if (self.phoneT.text.length < 1)
  107. {
  108. [FanweMessage alert:ASLocalizedString(@"手机号限制11位数!")];
  109. return;
  110. }
  111. if (self.codeT.text.length == 0)
  112. {
  113. [FanweMessage alert:ASLocalizedString(@"验证码不能为空!")];
  114. return;
  115. }
  116. FWWeakify(self)
  117. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  118. [parmDict setObject:@"login" forKey:@"ctl"];
  119. [parmDict setObject:@"bound_mobile" forKey:@"act"];
  120. [parmDict setObject:self.phoneT.text forKey:@"mobile"];
  121. [parmDict setObject:self.codeT.text forKey:@"code"];
  122. [parmDict setObject:self.areaModel.area_code forKey:@"tel_code"];
  123. [parmDict setObject:SafeStr(self.model.user_id) forKey:@"uid"];
  124. [parmDict setObject:SafeStr(self.model.access_token) forKey:@"access_token"];
  125. [self showMyHud];
  126. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  127. {
  128. FWStrongify(self)
  129. [self hideMyHud];
  130. if ([responseJson toInt:@"status"] == 1)
  131. {
  132. [BGIMLoginManager sharedInstance].loginParam.identifier = [responseJson toString:@"user_id"];
  133. [BGIMLoginManager sharedInstance].loginParam.isAgree = [responseJson toInt:@"is_agree"];
  134. self.BuguLive.appModel.first_login = [responseJson toString:@"first_login"];
  135. self.BuguLive.appModel.new_level = [responseJson toInt:@"new_level"];
  136. self.BuguLive.appModel.login_send_score = [responseJson toString:@"login_send_score"];
  137. [GlobalVariables sharedInstance].token = [responseJson toString:@"token"];
  138. [[BGIMLoginManager sharedInstance] getUserSig:^{
  139. [[AppDelegate sharedAppDelegate] enterMainUI];
  140. [self hideMyHud];
  141. } failed:^(int errId, NSString *errMsg) {
  142. [self hideMyHud];
  143. }];
  144. }
  145. } FailureBlock:^(NSError *error) {
  146. // FWStrongify(self)
  147. [FanweMessage alertHUD:error.description];
  148. }];
  149. }
  150. - (IBAction)clickCancleBtn:(QMUIButton *)sender {
  151. [self.navigationController popViewControllerAnimated:YES];
  152. }
  153. #pragma mark 获取验证码的倒计时
  154. - (void)timego
  155. {
  156. [self timerDec:_timeCount];
  157. }
  158. - (void)timerDec:(NSInteger)time
  159. {
  160. if(time > 0)
  161. {
  162. [self.codeBtn setTitle:[NSString stringWithFormat:ASLocalizedString(@"重新获取(%lds)"),(long)time] forState:UIControlStateNormal];
  163. // [self.loginView.codeBtn setTitleColor:kAppGrayColor1 forState:UIControlStateDisabled];
  164. _timeCount --;
  165. }else if(time == 0)
  166. {
  167. self.codeBtn.enabled = YES;
  168. [self.codeBtn setTitle:[NSString stringWithFormat:ASLocalizedString(@"重新获取验证码")] forState:UIControlStateNormal];
  169. [_timer invalidate];
  170. _timeCount = 60;
  171. }
  172. }
  173. -(void)setPlaceholderTextWithTextfield:(UITextField *)textField{
  174. if (@available(iOS 13.0,*)) {
  175. // Ivar ivar = class_getInstanceVariable([UITextField class],@"_placeholderLabel");
  176. UILabel *placeholderLabel = [self getIvar:textField ivarName:@"_placeholderLabel"];
  177. // object_getIvar(textField, ivar);
  178. placeholderLabel.textColor = [UIColor colorWithHexString:@"#AAAAAA"];
  179. placeholderLabel.font = [UIFont boldSystemFontOfSize:14];
  180. placeholderLabel.alpha = 0.8;
  181. }else{
  182. [textField setValue:[UIColor colorWithHexString:@"#AAAAAA"] forKeyPath:@"_placeholderLabel.textColor"];
  183. [textField setValue:[UIFont systemFontOfSize:14]forKeyPath:@"_placeholderLabel.font"];
  184. }
  185. }
  186. - (id)getIvar:(id)obj ivarName:(NSString *)name {
  187. unsigned int numIvars; // 成员变量个数
  188. Ivar *vars = class_copyIvarList([obj class], &numIvars);
  189. id resultObj;
  190. for(int i =0; i < numIvars; i++) {
  191. if ([[NSString stringWithUTF8String:ivar_getName(vars[i])] isEqualToString:name]) {
  192. ptrdiff_t offset = ivar_getOffset(vars[i]);
  193. // 核心代码就只有下面这一句,类似的其他类的其他变量,你懂的...
  194. resultObj = (__bridge id)((void *)(*((long *)((__bridge void *)obj + offset))));
  195. break;
  196. }
  197. }
  198. free(vars);
  199. return resultObj;
  200. }
  201. @end