MOPwdAndSMSLoginVC.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. //
  2. // MOPwdAndSMSLoginVC.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/10/15.
  6. //
  7. #import "MOPwdAndSMSLoginVC.h"
  8. #import "MOSelectPartitionVC.h"
  9. #import "MOSetPasswordSMS.h"
  10. #import "NSString+YYAdd.h"
  11. #import "MOFirstInfoSetVC.h"
  12. #import "MOCountDownButton.h"
  13. #import "UIImage+YYAdd.h"
  14. #import <AdjustSdk/AdjustSdk.h>
  15. #import "TencentCaptcha.h"
  16. #import <WebKit/WebKit.h>
  17. @interface MOPwdAndSMSLoginVC ()<WKNavigationDelegate>
  18. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *backTop;
  19. @property (weak, nonatomic) IBOutlet UIImageView *bgImgView;
  20. @property (weak, nonatomic) IBOutlet UIImageView *topLogoImg;
  21. /** 提示标题 */
  22. @property (weak, nonatomic) IBOutlet UILabel *tipsLab;
  23. /** 手机号背景 */
  24. @property (weak, nonatomic) IBOutlet UIView *mobileBgView;
  25. /** 选择国家按钮 (+86) */
  26. @property (weak, nonatomic) IBOutlet UIButton *chooseCountryBtn;
  27. /** 手机号输入框 */
  28. @property (weak, nonatomic) IBOutlet UITextField *mobileTef;
  29. /** sms背景 */
  30. @property (weak, nonatomic) IBOutlet UIView *smsBgView;
  31. /** sms验证码输入框 */
  32. @property (weak, nonatomic) IBOutlet UITextField *smsTef;
  33. /** 帮助提示语 */
  34. @property (weak, nonatomic) IBOutlet UILabel *helpLab;
  35. /** 登录按钮 */
  36. @property (weak, nonatomic) IBOutlet UIButton *loginBtn;
  37. /** 更换登录方式 */
  38. @property (weak, nonatomic) IBOutlet UIButton *changeTypBtn;
  39. /** 密码输入背景view */
  40. @property (weak, nonatomic) IBOutlet UIView *pswBgView;
  41. /** 密码输入框 */
  42. @property (weak, nonatomic) IBOutlet UITextField *pswTef;
  43. @property (weak, nonatomic) IBOutlet UIButton *forgetBtn;
  44. @property (nonatomic, strong) MOCountDownButton *smsBtn;
  45. @property (weak, nonatomic) IBOutlet UILabel *codeTipLab;
  46. @property (weak, nonatomic) IBOutlet UILabel *pswTipLab;
  47. /** 当前界面是否是密码输入的状态 */
  48. @property (nonatomic, assign) BOOL isPsw;
  49. /** 是否越狱 */
  50. @property (nonatomic, assign) BOOL isRootMobile;
  51. /** 是否虚拟设备 */
  52. @property (nonatomic, assign) BOOL isVirtual;
  53. @property (nonatomic, strong) WKWebView *webView;
  54. @property (nonatomic, strong) UIView *webBgView;
  55. @end
  56. @implementation MOPwdAndSMSLoginVC
  57. - (void)viewWillAppear:(BOOL)animated{
  58. [super viewWillAppear:animated];
  59. [self.navigationController setNavigationBarHidden:YES animated:animated];
  60. }
  61. - (void)viewDidLoad {
  62. [super viewDidLoad];
  63. // Do any additional setup after loading the view from its nib.
  64. self.isPsw = NO;
  65. [self setupUI];
  66. self.isRootMobile = [SecurityBridge isJailbroken];//是否越狱
  67. self.isVirtual = [SecurityBridge isRunningInEmulator];//是否虚拟机
  68. }
  69. - (void)setupUI{
  70. [self.chooseCountryBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
  71. [self.mobileTef setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
  72. [self.tipsLab setFont:[MOTextTools getTheFontWithSize:24.0 AndFontName:kNormalContentFontStr]];
  73. [self.codeTipLab setFont:[MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr]];
  74. [self.smsTef setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
  75. [self.pswTipLab setFont:[MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr]];
  76. [self.pswTef setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
  77. [self.helpLab setFont:[MOTextTools getTheFontWithSize:10.0 AndFontName:kNormalContentFontStr]];
  78. [self.loginBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
  79. [self.changeTypBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
  80. [self.forgetBtn setFont:[MOTextTools getTheFontWithSize:11.0 AndFontName:kNormalContentFontStr]];
  81. CGFloat statusBarHeight = STATUS_BAR_HEIGHT;
  82. self.backTop.constant = statusBarHeight + 12.0;
  83. NSArray *colorArr = @[[MOTools colorWithHexString:@"#EDF1FD" alpha:1.0],[MOTools colorWithHexString:@"#FAFAFC" alpha:1.0]];
  84. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT) Colors:colorArr GradientType:1];
  85. [self.bgImgView setImage:image];
  86. [self.topLogoImg setImage:[[UIImage imageNamed:@"icon_login_logo_white"] imageByTintColor:[MOTools colorWithHexString:@"#49C1FF" alpha:1.0]]];
  87. [self.smsBgView addSubview:self.smsBtn];
  88. [self.smsBtn mas_makeConstraints:^(MASConstraintMaker *make)
  89. {
  90. make.centerY.equalTo(self.smsBgView.mas_centerY);
  91. make.right.offset(-5.0);
  92. make.width.mas_greaterThanOrEqualTo(80);
  93. make.height.mas_equalTo(35);
  94. }];
  95. // self.mobileBgView.layer.cornerRadius = 50.0 / 2.0;
  96. // self.mobileBgView.layer.masksToBounds = YES;
  97. // self.mobileBgView.layer.borderWidth = 0.5;
  98. // self.mobileBgView.layer.borderColor = [MOTools colorWithHexString:@"#E5D7E3" alpha:0.5].CGColor;
  99. //修改placeHolder的颜色
  100. NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_hint_phone") attributes:@{NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#E5D7E3" alpha:0.5]}];
  101. self.mobileTef.attributedPlaceholder = placeholderString;
  102. // self.smsBgView.layer.cornerRadius = 50.0 / 2.0;
  103. // self.smsBgView.layer.masksToBounds = YES;
  104. // self.smsBgView.layer.borderWidth = 0.5;
  105. // self.smsBgView.layer.borderColor = [MOTools colorWithHexString:@"#E5D7E3" alpha:0.5].CGColor;
  106. //修改placeHolder的颜色
  107. placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_hint_verify_code") attributes:@{NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#E5D7E3" alpha:0.5]}];
  108. self.smsTef.attributedPlaceholder = placeholderString;
  109. // self.pswBgView.layer.cornerRadius = 50.0 / 2.0;
  110. // self.pswBgView.layer.masksToBounds = YES;
  111. // self.pswBgView.layer.borderWidth = 0.5;
  112. // self.pswBgView.layer.borderColor = [MOTools colorWithHexString:@"#E5D7E3" alpha:0.5].CGColor;
  113. placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_hint_password") attributes:@{NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#E5D7E3" alpha:0.5]}];
  114. //修改placeHolder的颜色
  115. self.pswTef.attributedPlaceholder = placeholderString;
  116. NSArray *loginColorArr = @[kBaseColorLeft,kBaseColorRight];
  117. UIImage *loginImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 30.0 * 2), 60.0) Colors:loginColorArr GradientType:0];
  118. [self.loginBtn setBackgroundImage:loginImage forState:UIControlStateNormal];
  119. self.loginBtn.layer.cornerRadius = 60.0 / 2.0;
  120. self.loginBtn.layer.masksToBounds = YES;
  121. self.tipsLab.text = NSLocalString(@"mimo_login_sms");
  122. [self.loginBtn setTitle:NSLocalString(@"mimo_login") forState:UIControlStateNormal];
  123. [self.changeTypBtn setTitle:NSLocalString(@"mimo_login_pwd") forState:UIControlStateNormal];
  124. [self.forgetBtn setTitle:NSLocalString(@"mimo_login_forget") forState:UIControlStateNormal];
  125. self.helpLab.text = NSLocalString(@"mimo_login_hint_register_tip");
  126. self.smsTef.keyboardType = UIKeyboardTypeNumberPad;
  127. // self.smsTef.secureTextEntry = YES;
  128. self.pswTef.keyboardType = UIKeyboardTypeDefault;
  129. self.pswTef.secureTextEntry = YES;
  130. self.chooseCountryBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  131. self.chooseCountryBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0);
  132. self.chooseCountryBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 8);
  133. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_forget") attributes:@{NSFontAttributeName:[MOTextTools getTheFontWithSize:11.0 AndFontName:kNormalContentFontStr],NSForegroundColorAttributeName: [MOTools colorWithHexString:@"#727272" alpha:1.0],NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle)}];
  134. self.forgetBtn.titleLabel.attributedText = attributedString;
  135. self.forgetBtn.hidden = YES;
  136. }
  137. - (void)setIsPsw:(BOOL)isPsw{
  138. _isPsw = isPsw;
  139. if(isPsw){
  140. //密码登录
  141. self.smsBgView.hidden = YES;
  142. self.pswBgView.hidden = NO;
  143. self.forgetBtn.hidden = NO;
  144. self.tipsLab.text = NSLocalString(@"mimo_login_pwd");
  145. [self.changeTypBtn setTitle:NSLocalString(@"mimo_login_sms") forState:UIControlStateNormal];
  146. self.helpLab.hidden = YES;
  147. }
  148. else{
  149. //验证码登录
  150. self.smsBgView.hidden = NO;
  151. self.pswBgView.hidden = YES;
  152. self.forgetBtn.hidden = YES;
  153. self.tipsLab.text = NSLocalString(@"mimo_login_sms");
  154. [self.changeTypBtn setTitle:NSLocalString(@"mimo_login_pwd") forState:UIControlStateNormal];
  155. self.helpLab.hidden = NO;
  156. }
  157. }
  158. - (IBAction)chooseCountryClick:(id)sender {
  159. MOSelectPartitionVC *vc = [[MOSelectPartitionVC alloc] init];
  160. //MARK: 选择区号回调
  161. WEAKSELF
  162. vc.selectCellBlock = ^(MOCountryList * _Nonnull model) {
  163. __strong typeof(weakSelf) self = weakSelf;
  164. [self.chooseCountryBtn setTitle:model.num forState:UIControlStateNormal];
  165. };
  166. [self.navigationController pushViewController:vc animated:YES];
  167. }
  168. - (IBAction)backBtnClick:(id)sender {
  169. [self.navigationController popViewControllerAnimated:YES];
  170. }
  171. - (IBAction)forgetBtnClick:(id)sender {
  172. if(self.mobileTef.text.length == 0)
  173. {
  174. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
  175. return;
  176. }
  177. MOSetPasswordSMS *vc = [[MOSetPasswordSMS alloc] init];
  178. vc.code = self.chooseCountryBtn.titleLabel.text;
  179. vc.num = self.mobileTef.text;
  180. vc.vcType = MOEnterCodePasswordType;
  181. [self.navigationController pushViewController:vc animated:YES];
  182. }
  183. -(void)sendSmsClickAndBlock:(void (^)(BOOL isSuccess))block{
  184. if(self.mobileTef.text.length == 0)
  185. {
  186. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
  187. return;
  188. }
  189. [MBProgressHUD showActivityMessageInView:@""];
  190. WEAKSELF
  191. NSDictionary *dic = @{@"code":self.chooseCountryBtn.titleLabel.text,
  192. @"num":self.mobileTef.text};
  193. [kHttpManager loginAndGetMobileCodeWithParams:dic andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  194. [MBProgressHUD hideHUD];
  195. if(kCode_Success){
  196. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_verify_code")];
  197. [weakSelf.smsTef becomeFirstResponder];
  198. block ? block(YES) : nil;
  199. }
  200. else{
  201. kShowNetError(data)
  202. block ? block(NO) : nil;
  203. }
  204. }];
  205. }
  206. //登录按钮点击
  207. - (IBAction)loginBtnClick:(id)sender {
  208. if(self.isPsw){
  209. //密码登录
  210. //验证码登录
  211. if(self.mobileTef.text.length == 0)
  212. {
  213. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
  214. return;
  215. }
  216. if(self.pswTef.text.length == 0){
  217. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_password")];
  218. return;
  219. }
  220. [MBProgressHUD showActivityMessageInView:@""];
  221. WEAKSELF
  222. NSDictionary *mobileDict = @{@"code":self.chooseCountryBtn.titleLabel.text,
  223. @"num":self.mobileTef.text};
  224. NSString *pswStr = [self.pswTef.text md5String];
  225. NSDictionary *dict = @{@"mobile":mobileDict,
  226. @"pwd":pswStr,
  227. @"root":@(weakSelf.isRootMobile),
  228. @"virtual":@(weakSelf.isVirtual)};
  229. [weakSelf toLoginWithPswWithParams:dict];
  230. }
  231. else{
  232. //验证码登录
  233. if(self.mobileTef.text.length == 0)
  234. {
  235. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
  236. return;
  237. }
  238. if(self.smsTef.text.length == 0){
  239. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_verify_code")];
  240. return;
  241. }
  242. [MBProgressHUD showActivityMessageInView:@""];
  243. WEAKSELF
  244. NSDictionary *mobileDict = @{@"code":self.chooseCountryBtn.titleLabel.text,
  245. @"num":self.mobileTef.text};
  246. NSDictionary *dict = @{@"mobile":mobileDict,
  247. @"code":self.smsTef.text,
  248. @"root":@(weakSelf.isRootMobile),
  249. @"virtual":@(weakSelf.isVirtual)};
  250. [weakSelf toLoginWithMobileWithParams:dict];
  251. }
  252. }
  253. - (void)toLoginWithMobileWithParams:(NSDictionary *)dict {
  254. WEAKSELF
  255. [kHttpManager logineWithMobileWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  256. [MBProgressHUD hideHUD];
  257. if(kCode_Success){
  258. [weakSelf toNextVCWithData:data];
  259. }
  260. else{
  261. NSInteger code = [data[@"code"] integerValue];
  262. if(code == 90001){
  263. [MOTools dismissKeyboard];
  264. //腾讯验证码
  265. [weakSelf toShowTentcentCaptchaWebViewAndBlock:^(NSDictionary *result) {
  266. if (!result) {
  267. return;
  268. }
  269. kMainThreadBlock((^{
  270. NSMutableDictionary *newDict = [dict mutableCopy];
  271. NSString *appidStr = [MODataManager objectOrNilForKey:@"appid" fromDictionary:result];
  272. NSString *randStr = [MODataManager objectOrNilForKey:@"randstr" fromDictionary:result];
  273. NSString *ticketStr = [MODataManager objectOrNilForKey:@"ticket" fromDictionary:result];
  274. NSDictionary *verify = @{@"appid":appidStr,@"ticket":ticketStr,@"randStr":randStr};
  275. [newDict setObject:verify forKey:@"verify"];
  276. [weakSelf toLoginWithMobileWithParams:newDict];
  277. }))
  278. }];
  279. }
  280. else{
  281. NSString *errorString = [MODataManager objectOrNilForKey:@"msg" fromDictionary:data];
  282. [MBProgressHUD showTipMessageInView:errorString];
  283. }
  284. }
  285. }];
  286. }
  287. - (void)toLoginWithPswWithParams:(NSDictionary *)dict {
  288. WEAKSELF
  289. [kHttpManager loginWithPwdWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  290. [MBProgressHUD hideHUD];
  291. if(kCode_Success){
  292. [weakSelf toNextVCWithData:data];
  293. }
  294. else{
  295. NSInteger code = [data[@"code"] integerValue];
  296. if(code == 90001){
  297. [MOTools dismissKeyboard];
  298. //腾讯验证码
  299. [weakSelf toShowTentcentCaptchaWebViewAndBlock:^(NSDictionary *result) {
  300. if (!result) {
  301. return;
  302. }
  303. kMainThreadBlock((^{
  304. NSMutableDictionary *newDict = [dict mutableCopy];
  305. NSString *appidStr = [MODataManager objectOrNilForKey:@"appid" fromDictionary:result];
  306. NSString *randStr = [MODataManager objectOrNilForKey:@"randstr" fromDictionary:result];
  307. NSString *ticketStr = [MODataManager objectOrNilForKey:@"ticket" fromDictionary:result];
  308. NSDictionary *verify = @{@"appid":appidStr,@"ticket":ticketStr,@"randStr":randStr};
  309. [newDict setObject:verify forKey:@"verify"];
  310. [weakSelf toLoginWithPswWithParams:newDict];
  311. }))
  312. }];
  313. }
  314. else{
  315. NSString *errorString = [MODataManager objectOrNilForKey:@"msg" fromDictionary:data];
  316. [MBProgressHUD showTipMessageInView:errorString];
  317. }
  318. }
  319. }];
  320. }
  321. - (void)toNextVCWithData:(id)data{
  322. [MODataManager saveUserInfo:data];
  323. BOOL isRegister = [[MODataManager objectOrNilForKey:@"register" fromDictionary:data[@"data"]] boolValue];
  324. if(isRegister){
  325. //注册
  326. // ADJEvent *event = [ADJEvent eventWithEventToken:@"27ymyz"];
  327. ADJEvent *event = [[ADJEvent alloc] initWithEventToken:@"27ymyz"];
  328. NSString *userId = GetUserId;
  329. if(userId.length != 0){
  330. [event addCallbackParameter:@"userId" value:userId];
  331. }
  332. [Adjust trackEvent:event];
  333. MOFirstInfoSetVC *vc = [[MOFirstInfoSetVC alloc] init];
  334. [self.navigationController pushViewController:vc animated:YES];
  335. }
  336. else{
  337. MOMainTabController *mainTabbar = [MOMainTabController sharedSingleton];
  338. [mainTabbar toResetSetupTabbar];
  339. [UIApplication sharedApplication].keyWindow.rootViewController = mainTabbar;
  340. [mainTabbar ChangeNeedShowAlert];
  341. }
  342. }
  343. //切换登录模式
  344. - (IBAction)changeLoginType:(id)sender {
  345. self.isPsw = !self.isPsw;
  346. }
  347. - (MOCountDownButton *)smsBtn
  348. {
  349. if (!_smsBtn)
  350. {
  351. _smsBtn = [[MOCountDownButton alloc] init];
  352. _smsBtn.accessibilityIdentifier = @"smsBtn";
  353. _smsBtn.backgroundColor = kBaseBtnBgColor;
  354. [_smsBtn setTitle:[NSString stringWithFormat:@"%@",NSLocalString(@"mimo_verify_code_send")] forState:UIControlStateNormal];
  355. [_smsBtn setTitleColor:UIColorFromHex(0xFFFFFF) forState:UIControlStateNormal];
  356. _smsBtn.titleLabel.font = [MOTextTools getTheFontWithSize:16.0 AndFontName:kNormalContentFontStr];;
  357. _smsBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
  358. _smsBtn.layer.cornerRadius = 35.0 / 2.0;
  359. _smsBtn.layer.masksToBounds = YES;
  360. // NSArray *colorArr = @[[MOTools colorWithHexString:@"#FF62EE" alpha:1.0],[MOTools colorWithHexString:@"#9923FF" alpha:1.0]];
  361. // UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 80.0, 35.0) Colors:colorArr GradientType:0];
  362. // [_smsBtn setBackgroundImage:image forState:UIControlStateNormal];
  363. UIImage *grayImg = [MOTools createImageWithColor:[MOTools colorWithHexString:@"#ABABAB" alpha:1.0]];
  364. [_smsBtn setBackgroundImage:grayImg forState:UIControlStateDisabled];
  365. WEAKSELF
  366. //use case 8
  367. [_smsBtn countDownChanging:^NSString *(MOCountDownButton *countDownButton,NSUInteger second)
  368. {
  369. NSString *title = [NSString stringWithFormat:@"%@(%lus)",NSLocalString(@"mimo_login_resend"),(unsigned long)second];
  370. return title;
  371. }];
  372. [_smsBtn countDownFinished:^NSString *(MOCountDownButton *countDownButton, NSUInteger second)
  373. {
  374. countDownButton.enabled = YES;
  375. [countDownButton setTitleColor:UIColorFromHex(0xFFFFFF) forState:UIControlStateNormal];
  376. return NSLocalString(@"mimo_verify_code_send");
  377. }];
  378. [_smsBtn countDownButtonHandler:^(MOCountDownButton*sender, NSInteger tag)
  379. {
  380. if(weakSelf.mobileTef.text.length == 0)
  381. {
  382. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
  383. return;
  384. }
  385. [weakSelf sendSmsClickAndBlock:^(BOOL isSuccess) {
  386. if(isSuccess){
  387. sender.enabled = NO;
  388. [sender startCountDownWithSecond:60];
  389. }
  390. }];
  391. }];
  392. }
  393. return _smsBtn;
  394. }
  395. - (void)toShowTentcentCaptchaWebViewAndBlock:(void (^)(NSDictionary *dict))block{
  396. [self.view addSubview:self.webBgView];
  397. [self.webBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  398. make.edges.equalTo(self.view);
  399. }];
  400. [self.webBgView addSubview:self.webView];
  401. [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
  402. make.center.equalTo(self.webBgView);
  403. make.width.equalTo(@360);
  404. make.height.equalTo(@360);
  405. }];
  406. self.webBgView.hidden = NO;
  407. WEAKSELF
  408. TencentCaptchaOptions *options = [[TencentCaptchaOptions alloc] init];
  409. options.loadingEnabled = TencentCaptchaOptionsSwitchOff;
  410. options.type = @"popup";
  411. options.optionsCallback = ^(NSString * _Nonnull functionName, NSDictionary<NSString *,id> * _Nonnull data) {};
  412. NSString *currentLanguage = [NSBundle currentLanguage];
  413. if ([currentLanguage containsString:@"zh"]){
  414. currentLanguage = @"zh-cn";
  415. }
  416. options.userLanguage = currentLanguage;
  417. [options setExtractParameter:@(YES) forName:@"enableAutoCheck"];
  418. [[TencentCaptcha sharedService] requestCaptchaWithWebView:self.webView options:options withCompletionHandler:^(NSError * _Nullable error, NSDictionary * _Nullable result) {
  419. if(error == nil) {
  420. //成功
  421. MOLogV(@"验证成功");
  422. weakSelf.webBgView.hidden = YES;
  423. block(result);
  424. }
  425. else{
  426. block(nil);
  427. }
  428. }];
  429. }
  430. - (WKWebView *)webView {
  431. if (!_webView) {
  432. WKUserContentController *contentController = [[WKUserContentController alloc] init];
  433. WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
  434. config.userContentController = contentController;
  435. _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 360, 360) configuration:config];
  436. _webView.navigationDelegate = self;
  437. _webView.backgroundColor = [UIColor clearColor];
  438. _webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  439. }
  440. return _webView;
  441. }
  442. - (UIView *)webBgView{
  443. if(!_webBgView){
  444. _webBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, (SCREENHEIGHT - NAV_BAR_HEIGHT))];
  445. _webBgView.backgroundColor = [UIColor clearColor];
  446. }
  447. return _webBgView;
  448. }
  449. - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message{
  450. MOLogV(@"Received message: %@", message.body);
  451. }
  452. // 网页加载完成回调
  453. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
  454. // JS 获取页面高度
  455. [webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
  456. if (!error && result) {
  457. CGFloat height = [result doubleValue];
  458. MOLogV(@"页面内容高度: %f", height);
  459. // 你可以根据这个高度调整 webView 的高度或外部容器视图
  460. // CGRect frame = webView.frame;
  461. // frame.size.height = height;
  462. // webView.frame = frame;
  463. }
  464. }];
  465. }
  466. @end