@@ -338,6 +338,16 @@ -(id)handleResponse:(id)responseJSON autoShowError:(BOOL)autoShowError{
338
338
});
339
339
}
340
340
}else {
341
+ NSDictionary *msgDict = [responseJSON valueForKey: @" msg" ];
342
+ __block BOOL need_captcha = NO ;
343
+ [[msgDict allKeys ] enumerateObjectsUsingBlock: ^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
344
+ if ([obj rangeOfString: @" need_captcha" ].location != NSNotFound ) {
345
+ need_captcha = YES ;
346
+ }
347
+ }];
348
+ if (need_captcha) {
349
+ [NSObject showCaptchaViewParams: nil ];
350
+ }
341
351
if (autoShowError) {
342
352
[NSObject showError: error];
343
353
}
@@ -347,25 +357,28 @@ -(id)handleResponse:(id)responseJSON autoShowError:(BOOL)autoShowError{
347
357
}
348
358
349
359
350
- + (void )showCaptchaView {
360
+ + (void )showCaptchaViewParams : (NSMutableDictionary *)params {
361
+ // Data
362
+ if (!params) {
363
+ params = @{}.mutableCopy ;
364
+ }
365
+ if (!params[@" type" ]) {
366
+ params[@" type" ] = @1 ;
367
+ }
368
+ NSString *path = @" api/request_valid" ;
369
+ NSURL *imageURL = [NSURL URLWithString: [NSString stringWithFormat: @" %@ api/getCaptcha?type=%@ " , [NSObject baseURLStr ], params[@" type" ]]];
370
+ // UI
351
371
SDCAlertController *alertV = [SDCAlertController alertControllerWithTitle: @" 提示" message: @" 亲,您操作这么快,不会是机器人吧?\n 来,输个验证码先?" preferredStyle: SDCAlertControllerStyleAlert];
352
-
353
372
UITextField *textF = [UITextField new ];
354
373
textF.layer .sublayerTransform = CATransform3DMakeTranslation (5 , 0 , 0 );
355
374
textF.backgroundColor = [UIColor whiteColor ];
356
375
[textF doBorderWidth: 0.5 color: nil cornerRadius: 2.0 ];
357
-
358
376
UIImageView *imageV = [UIImageView new ];
359
377
imageV.backgroundColor = [UIColor lightGrayColor ];
360
378
imageV.contentMode = UIViewContentModeScaleAspectFit;
361
379
imageV.clipsToBounds = YES ;
362
380
imageV.userInteractionEnabled = YES ;
363
381
[textF doBorderWidth: 0.5 color: nil cornerRadius: 2.0 ];
364
- __weak typeof (imageV) weakImageV = imageV;
365
- NSURL *imageURL = [NSURL URLWithString: [NSString stringWithFormat: @" %@ api/getCaptcha" , [NSObject baseURLStr ]]];
366
- [imageV bk_whenTapped: ^{
367
- [weakImageV sd_setImageWithURL: imageURL placeholderImage: nil options: (SDWebImageRetryFailed | SDWebImageRefreshCached | SDWebImageHandleCookies)];
368
- }];
369
382
[imageV sd_setImageWithURL: imageURL placeholderImage: nil options: (SDWebImageRetryFailed | SDWebImageRefreshCached | SDWebImageHandleCookies)];
370
383
371
384
[alertV.contentView addSubview: textF];
@@ -382,17 +395,31 @@ + (void)showCaptchaView{
382
395
make.height .mas_equalTo (25 );
383
396
make.centerY .equalTo (textF);
384
397
}];
385
- [alertV addAction: [SDCAlertAction actionWithTitle: @" 取消" style: SDCAlertActionStyleDefault handler: nil ]];
386
- [alertV addAction: [SDCAlertAction actionWithTitle: @" 还真不是" style: SDCAlertActionStyleDefault handler: ^(SDCAlertAction *action) {
387
- // 校验验证码的接口。。。。
388
-
389
- NSLog (@" textF.text ===== %@ " , textF.text );
390
- }]];
391
-
398
+ // Action
399
+ __weak typeof (imageV) weakImageV = imageV;
400
+ [imageV bk_whenTapped: ^{
401
+ [weakImageV sd_setImageWithURL: imageURL placeholderImage: nil options: (SDWebImageRetryFailed | SDWebImageRefreshCached | SDWebImageHandleCookies)];
402
+ }];
403
+ __weak typeof (alertV) weakAlertV = alertV;
404
+ [alertV addAction: [SDCAlertAction actionWithTitle: @" 取消" style: SDCAlertActionStyleCancel handler: nil ]];
405
+ [alertV addAction: [SDCAlertAction actionWithTitle: @" 还真不是" style: SDCAlertActionStyleDefault handler: nil ]];
406
+ alertV.shouldDismissBlock = ^BOOL (SDCAlertAction *action){
407
+ BOOL shouldDismiss = [action.title isEqualToString: @" 取消" ];
408
+ if (!shouldDismiss) {
409
+ params[@" j_captcha" ] = textF.text ;
410
+ [[CodingNetAPIClient sharedJsonClient ] requestJsonDataWithPath: path withParams: params withMethodType: Post andBlock: ^(id data, NSError *error) {
411
+ if (data) {
412
+ [weakAlertV dismissWithCompletion: ^{
413
+ [NSObject showHudTipStr: @" 验证码正确" ];
414
+ }];
415
+ }
416
+ }];
417
+ }
418
+ return shouldDismiss;
419
+ };
392
420
[alertV presentWithCompletion: ^{
393
421
[textF becomeFirstResponder ];
394
422
}];
395
423
}
396
424
397
-
398
425
@end
0 commit comments