Skip to content

Commit f7102dd

Browse files
committed
发短信需要图片验证码
1 parent ea245a3 commit f7102dd

8 files changed

Lines changed: 188 additions & 18 deletions

File tree

Coding_iOS/Coding_iOS-Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</dict>
3737
</array>
3838
<key>CFBundleVersion</key>
39-
<string>4.9.201712051200</string>
39+
<string>4.9.201712061200</string>
4040
<key>ITSAppUsesNonExemptEncryption</key>
4141
<false/>
4242
<key>LSApplicationQueriesSchemes</key>

Coding_iOS/Controllers/Login/CannotLoginViewController.m

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,74 @@ - (void)phoneCodeBtnClicked:(PhoneCodeButton *)sender withCaptcha:(NSString *)ca
225225
return;
226226
}
227227
sender.enabled = NO;
228-
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/account/password/forget" withParams:@{@"account": _userStr, @"phoneCountryCode": @"+86"} withMethodType:Post andBlock:^(id data, NSError *error) {
228+
NSMutableDictionary *params = @{@"account": _userStr,
229+
@"phoneCountryCode": @"+86"}.mutableCopy;
230+
if (captcha.length > 0) {
231+
params[@"j_captcha"] = captcha;
232+
}
233+
__weak typeof(self) weakSelf = self;
234+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/account/password/forget" withParams:params withMethodType:Post andBlock:^(id data, NSError *error) {
229235
if (data) {
230236
[NSObject showHudTipStr:@"验证码发送成功"];
231237
[sender startUpTimer];
232238
}else{
233239
[sender invalidateTimer];
240+
if (error && error.userInfo[@"msg"] && [[error.userInfo[@"msg"] allKeys] containsObject:@"j_captcha_error"]) {
241+
[weakSelf p_showCaptchaAlert:sender];
242+
}
234243
}
235244
}];
236245
}
237246

247+
- (void)p_showCaptchaAlert:(PhoneCodeButton *)sender{
248+
SDCAlertController *alertV = [SDCAlertController alertControllerWithTitle:@"提示" message:@"请输入图片验证码" preferredStyle:SDCAlertControllerStyleAlert];
249+
UITextField *textF = [UITextField new];
250+
textF.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);
251+
textF.backgroundColor = [UIColor whiteColor];
252+
[textF doBorderWidth:0.5 color:nil cornerRadius:2.0];
253+
UIImageView *imageV = [UIImageView new];
254+
imageV.backgroundColor = [UIColor lightGrayColor];
255+
imageV.contentMode = UIViewContentModeScaleAspectFit;
256+
imageV.clipsToBounds = YES;
257+
imageV.userInteractionEnabled = YES;
258+
[textF doBorderWidth:0.5 color:nil cornerRadius:2.0];
259+
NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@api/getCaptcha", [NSObject baseURLStr]]];
260+
[imageV sd_setImageWithURL:imageURL placeholderImage:nil options:(SDWebImageRetryFailed | SDWebImageRefreshCached | SDWebImageHandleCookies)];
261+
262+
[alertV.contentView addSubview:textF];
263+
[alertV.contentView addSubview:imageV];
264+
[textF mas_makeConstraints:^(MASConstraintMaker *make) {
265+
make.left.equalTo(alertV.contentView).offset(15);
266+
make.height.mas_equalTo(25);
267+
make.bottom.equalTo(alertV.contentView).offset(-10);
268+
}];
269+
[imageV mas_makeConstraints:^(MASConstraintMaker *make) {
270+
make.right.equalTo(alertV.contentView).offset(-15);
271+
make.left.equalTo(textF.mas_right).offset(10);
272+
make.width.mas_equalTo(60);
273+
make.height.mas_equalTo(25);
274+
make.centerY.equalTo(textF);
275+
}];
276+
//Action
277+
__weak typeof(imageV) weakImageV = imageV;
278+
[imageV bk_whenTapped:^{
279+
[weakImageV sd_setImageWithURL:imageURL placeholderImage:nil options:(SDWebImageRetryFailed | SDWebImageRefreshCached | SDWebImageHandleCookies)];
280+
}];
281+
__weak typeof(self) weakSelf = self;
282+
[alertV addAction:[SDCAlertAction actionWithTitle:@"取消" style:SDCAlertActionStyleCancel handler:nil]];
283+
[alertV addAction:[SDCAlertAction actionWithTitle:@"确定" style:SDCAlertActionStyleDefault handler:nil]];
284+
alertV.shouldDismissBlock = ^BOOL (SDCAlertAction *action){
285+
if (![action.title isEqualToString:@"取消"]) {
286+
[weakSelf phoneCodeBtnClicked:sender withCaptcha:textF.text];
287+
}
288+
return YES;
289+
};
290+
[alertV presentWithCompletion:^{
291+
[textF becomeFirstResponder];
292+
}];
293+
}
294+
295+
238296
- (void)footerBtnClicked:(id)sender{
239297
if (_stepIndex == 0) {
240298
CannotLoginViewController *vc = [CannotLoginViewController vcWithMethodType:[_userStr isPhoneNo]? CannotLoginMethodPhone: CannotLoginMethodEamil stepIndex:1 userStr:_userStr];

Coding_iOS/Controllers/Login/Close2FAViewController.m

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,68 @@ - (void)phoneCodeBtnClicked:(PhoneCodeButton *)sender withCaptcha:(NSString *)ca
123123
return;
124124
}
125125
sender.enabled = NO;
126-
[[Coding_NetAPIManager sharedManager] post_Close2FAGeneratePhoneCode:self.phone block:^(id data, NSError *error) {
126+
__weak typeof(self) weakSelf = self;
127+
[[Coding_NetAPIManager sharedManager] post_Close2FAGeneratePhoneCode:self.phone withCaptcha:captcha block:^(id data, NSError *error) {
127128
if (data) {
128129
[NSObject showHudTipStr:@"验证码发送成功"];
129130
[sender startUpTimer];
130131
}else{
131132
[sender invalidateTimer];
133+
if (error && error.userInfo[@"msg"] && [[error.userInfo[@"msg"] allKeys] containsObject:@"j_captcha_error"]) {
134+
[weakSelf p_showCaptchaAlert:sender];
135+
}
136+
}
137+
}];
138+
}
139+
140+
- (void)p_showCaptchaAlert:(PhoneCodeButton *)sender{
141+
SDCAlertController *alertV = [SDCAlertController alertControllerWithTitle:@"提示" message:@"请输入图片验证码" preferredStyle:SDCAlertControllerStyleAlert];
142+
UITextField *textF = [UITextField new];
143+
textF.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);
144+
textF.backgroundColor = [UIColor whiteColor];
145+
[textF doBorderWidth:0.5 color:nil cornerRadius:2.0];
146+
UIImageView *imageV = [UIImageView new];
147+
imageV.backgroundColor = [UIColor lightGrayColor];
148+
imageV.contentMode = UIViewContentModeScaleAspectFit;
149+
imageV.clipsToBounds = YES;
150+
imageV.userInteractionEnabled = YES;
151+
[textF doBorderWidth:0.5 color:nil cornerRadius:2.0];
152+
NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@api/getCaptcha", [NSObject baseURLStr]]];
153+
[imageV sd_setImageWithURL:imageURL placeholderImage:nil options:(SDWebImageRetryFailed | SDWebImageRefreshCached | SDWebImageHandleCookies)];
154+
155+
[alertV.contentView addSubview:textF];
156+
[alertV.contentView addSubview:imageV];
157+
[textF mas_makeConstraints:^(MASConstraintMaker *make) {
158+
make.left.equalTo(alertV.contentView).offset(15);
159+
make.height.mas_equalTo(25);
160+
make.bottom.equalTo(alertV.contentView).offset(-10);
161+
}];
162+
[imageV mas_makeConstraints:^(MASConstraintMaker *make) {
163+
make.right.equalTo(alertV.contentView).offset(-15);
164+
make.left.equalTo(textF.mas_right).offset(10);
165+
make.width.mas_equalTo(60);
166+
make.height.mas_equalTo(25);
167+
make.centerY.equalTo(textF);
168+
}];
169+
//Action
170+
__weak typeof(imageV) weakImageV = imageV;
171+
[imageV bk_whenTapped:^{
172+
[weakImageV sd_setImageWithURL:imageURL placeholderImage:nil options:(SDWebImageRetryFailed | SDWebImageRefreshCached | SDWebImageHandleCookies)];
173+
}];
174+
__weak typeof(self) weakSelf = self;
175+
[alertV addAction:[SDCAlertAction actionWithTitle:@"取消" style:SDCAlertActionStyleCancel handler:nil]];
176+
[alertV addAction:[SDCAlertAction actionWithTitle:@"确定" style:SDCAlertActionStyleDefault handler:nil]];
177+
alertV.shouldDismissBlock = ^BOOL (SDCAlertAction *action){
178+
if (![action.title isEqualToString:@"取消"]) {
179+
[weakSelf phoneCodeBtnClicked:sender withCaptcha:textF.text];
132180
}
181+
return YES;
182+
};
183+
[alertV presentWithCompletion:^{
184+
[textF becomeFirstResponder];
133185
}];
134186
}
187+
135188
- (void)footerBtnClicked:(id)sender{
136189
[self.footerBtn startQueryAnimate];
137190
[[Coding_NetAPIManager sharedManager] post_Close2FAWithPhone:self.phone code:self.phoneCode block:^(id data, NSError *error) {

Coding_iOS/Controllers/Login/RegisterViewController.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,15 @@ - (void)phoneCodeBtnClicked:(PhoneCodeButton *)sender withCaptcha:(NSString *)ca
355355
[sender startUpTimer];
356356
}else{
357357
[sender invalidateTimer];
358-
// if (error && error.userInfo[@"msg"] && [error.userInfo[@"msg"] containsObject:@"j_captcha_error"]) {
359-
// [weakSelf p_showCaptchaAlert:sender];
360-
// }
358+
if (error && error.userInfo[@"msg"] && [[error.userInfo[@"msg"] allKeys] containsObject:@"j_captcha_error"]) {
359+
[weakSelf p_showCaptchaAlert:sender];
360+
}
361361
}
362362
}];
363363
}
364364

365365
- (void)p_showCaptchaAlert:(PhoneCodeButton *)sender{
366-
SDCAlertController *alertV = [SDCAlertController alertControllerWithTitle:@"提示" message:@"亲,您操作这么快,不会是机器人吧?\n来,输个验证码先?" preferredStyle:SDCAlertControllerStyleAlert];
366+
SDCAlertController *alertV = [SDCAlertController alertControllerWithTitle:@"提示" message:@"请输入图片验证码" preferredStyle:SDCAlertControllerStyleAlert];
367367
UITextField *textF = [UITextField new];
368368
textF.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);
369369
textF.backgroundColor = [UIColor whiteColor];
@@ -398,7 +398,7 @@ - (void)p_showCaptchaAlert:(PhoneCodeButton *)sender{
398398
}];
399399
__weak typeof(self) weakSelf = self;
400400
[alertV addAction:[SDCAlertAction actionWithTitle:@"取消" style:SDCAlertActionStyleCancel handler:nil]];
401-
[alertV addAction:[SDCAlertAction actionWithTitle:@"还真不是" style:SDCAlertActionStyleDefault handler:nil]];
401+
[alertV addAction:[SDCAlertAction actionWithTitle:@"确定" style:SDCAlertActionStyleDefault handler:nil]];
402402
alertV.shouldDismissBlock = ^BOOL (SDCAlertAction *action){
403403
if (![action.title isEqualToString:@"取消"]) {
404404
[weakSelf phoneCodeBtnClicked:sender withCaptcha:textF.text];

Coding_iOS/Controllers/MeSetting/SettingPhoneViewController.m

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,65 @@ - (void)phoneCodeBtnClicked:(PhoneCodeButton *)sender withCaptcha:(NSString *)ca
134134
return;
135135
}
136136
sender.enabled = NO;
137-
[[Coding_NetAPIManager sharedManager] request_GeneratePhoneCodeToResetPhone:_phone phoneCountryCode:_phone_country_code block:^(id data, NSError *error) {
137+
__weak typeof(self) weakSelf = self;
138+
[[Coding_NetAPIManager sharedManager] request_GeneratePhoneCodeToResetPhone:_phone phoneCountryCode:_phone_country_code withCaptcha:captcha block:^(id data, NSError *error) {
138139
if (data) {
139140
[NSObject showHudTipStr:@"验证码发送成功"];
140141
[sender startUpTimer];
141142
}else{
142143
[sender invalidateTimer];
144+
if (error && error.userInfo[@"msg"] && [[error.userInfo[@"msg"] allKeys] containsObject:@"j_captcha_error"]) {
145+
[weakSelf p_showCaptchaAlert:sender];
146+
}
147+
}
148+
}];
149+
}
150+
151+
- (void)p_showCaptchaAlert:(PhoneCodeButton *)sender{
152+
SDCAlertController *alertV = [SDCAlertController alertControllerWithTitle:@"提示" message:@"请输入图片验证码" preferredStyle:SDCAlertControllerStyleAlert];
153+
UITextField *textF = [UITextField new];
154+
textF.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);
155+
textF.backgroundColor = [UIColor whiteColor];
156+
[textF doBorderWidth:0.5 color:nil cornerRadius:2.0];
157+
UIImageView *imageV = [UIImageView new];
158+
imageV.backgroundColor = [UIColor lightGrayColor];
159+
imageV.contentMode = UIViewContentModeScaleAspectFit;
160+
imageV.clipsToBounds = YES;
161+
imageV.userInteractionEnabled = YES;
162+
[textF doBorderWidth:0.5 color:nil cornerRadius:2.0];
163+
NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@api/getCaptcha", [NSObject baseURLStr]]];
164+
[imageV sd_setImageWithURL:imageURL placeholderImage:nil options:(SDWebImageRetryFailed | SDWebImageRefreshCached | SDWebImageHandleCookies)];
165+
166+
[alertV.contentView addSubview:textF];
167+
[alertV.contentView addSubview:imageV];
168+
[textF mas_makeConstraints:^(MASConstraintMaker *make) {
169+
make.left.equalTo(alertV.contentView).offset(15);
170+
make.height.mas_equalTo(25);
171+
make.bottom.equalTo(alertV.contentView).offset(-10);
172+
}];
173+
[imageV mas_makeConstraints:^(MASConstraintMaker *make) {
174+
make.right.equalTo(alertV.contentView).offset(-15);
175+
make.left.equalTo(textF.mas_right).offset(10);
176+
make.width.mas_equalTo(60);
177+
make.height.mas_equalTo(25);
178+
make.centerY.equalTo(textF);
179+
}];
180+
//Action
181+
__weak typeof(imageV) weakImageV = imageV;
182+
[imageV bk_whenTapped:^{
183+
[weakImageV sd_setImageWithURL:imageURL placeholderImage:nil options:(SDWebImageRetryFailed | SDWebImageRefreshCached | SDWebImageHandleCookies)];
184+
}];
185+
__weak typeof(self) weakSelf = self;
186+
[alertV addAction:[SDCAlertAction actionWithTitle:@"取消" style:SDCAlertActionStyleCancel handler:nil]];
187+
[alertV addAction:[SDCAlertAction actionWithTitle:@"确定" style:SDCAlertActionStyleDefault handler:nil]];
188+
alertV.shouldDismissBlock = ^BOOL (SDCAlertAction *action){
189+
if (![action.title isEqualToString:@"取消"]) {
190+
[weakSelf phoneCodeBtnClicked:sender withCaptcha:textF.text];
143191
}
192+
return YES;
193+
};
194+
[alertV presentWithCompletion:^{
195+
[textF becomeFirstResponder];
144196
}];
145197
}
146198

Coding_iOS/Util/Manager/Coding_NetAPIManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ typedef NS_ENUM(NSInteger, PurposeType) {
227227
- (void)request_UserJobArrayWithBlock:(void (^)(id data, NSError *error))block;
228228
- (void)request_UserTagArrayWithBlock:(void (^)(id data, NSError *error))block;
229229
- (void)request_UpdateUserInfo_WithObj:(User *)curUser andBlock:(void (^)(id data, NSError *error))block;
230-
- (void)request_GeneratePhoneCodeToResetPhone:(NSString *)phone phoneCountryCode:(NSString *)phoneCountryCode block:(void (^)(id data, NSError *error))block;
230+
- (void)request_GeneratePhoneCodeToResetPhone:(NSString *)phone phoneCountryCode:(NSString *)phoneCountryCode withCaptcha:(NSString *)captcha block:(void (^)(id data, NSError *error))block;
231231
- (void)request_PointRecords:(PointRecords *)records andBlock:(void (^)(id data, NSError *error))block;
232232
- (void)request_RewardToTweet:(NSString *)tweet_id encodedPassword:(NSString *)encodedPassword andBlock:(void (^)(id data, NSError *error))block;
233233
- (void)request_ServiceInfoBlock:(void (^)(id data, NSError *error))block;
@@ -273,7 +273,7 @@ typedef NS_ENUM(NSInteger, PurposeType) {
273273
- (void)request_Users_activenessWithGlobalKey:(NSString *)globalKey andBlock:(void (^)(ActivenessModel *data, NSError *error))block;
274274

275275
#pragma mark - 2FA
276-
- (void)post_Close2FAGeneratePhoneCode:(NSString *)phone block:(void (^)(id data, NSError *error))block;
276+
- (void)post_Close2FAGeneratePhoneCode:(NSString *)phone withCaptcha:(NSString *)captcha block:(void (^)(id data, NSError *error))block;
277277
- (void)post_Close2FAWithPhone:(NSString *)phone code:(NSString *)code block:(void (^)(id data, NSError *error))block;
278278
- (void)get_is2FAOpenBlock:(void (^)(BOOL data, NSError *error))block;
279279

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,10 +2393,13 @@ - (void)request_UpdateUserInfo_WithObj:(User *)curUser andBlock:(void (^)(id dat
23932393
}];
23942394
}
23952395

2396-
- (void)request_GeneratePhoneCodeToResetPhone:(NSString *)phone phoneCountryCode:(NSString *)phoneCountryCode block:(void (^)(id data, NSError *error))block{
2396+
- (void)request_GeneratePhoneCodeToResetPhone:(NSString *)phone phoneCountryCode:(NSString *)phoneCountryCode withCaptcha:(NSString *)captcha block:(void (^)(id data, NSError *error))block{
23972397
NSString *path = @"api/account/phone/change/code";
2398-
NSDictionary *params = @{@"phone": phone,
2399-
@"phoneCountryCode": phoneCountryCode};
2398+
NSMutableDictionary *params = @{@"phone": phone,
2399+
@"phoneCountryCode": phoneCountryCode}.mutableCopy;
2400+
if (captcha.length > 0) {
2401+
params[@"j_captcha"] = captcha;
2402+
}
24002403
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post andBlock:^(id data, NSError *error) {
24012404
if (data) {
24022405
[MobClick event:kUmeng_Event_Request_ActionOfServer label:@"生成手机验证码_绑定手机号"];
@@ -2954,8 +2957,12 @@ - (void)request_VerifyTypeWithBlock:(void (^)(VerifyType type, NSError *error))b
29542957
}
29552958

29562959
#pragma mark - 2FA
2957-
- (void)post_Close2FAGeneratePhoneCode:(NSString *)phone block:(void (^)(id data, NSError *error))block{
2958-
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/twofa/close/code" withParams:@{@"phone": phone, @"from": @"mart"} withMethodType:Post andBlock:^(id data, NSError *error) {
2960+
- (void)post_Close2FAGeneratePhoneCode:(NSString *)phone withCaptcha:(NSString *)captcha block:(void (^)(id data, NSError *error))block{
2961+
NSMutableDictionary *params = @{@"phone": phone, @"from": @"mart"}.mutableCopy;
2962+
if (captcha.length > 0) {
2963+
params[@"j_captcha"] = captcha;
2964+
}
2965+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/twofa/close/code" withParams:params withMethodType:Post andBlock:^(id data, NSError *error) {
29592966
block(data, error);
29602967
}];
29612968
}

Coding_iOS/Util/OC_Category/NSObject+Common.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ + (void)showCaptchaViewParams:(NSMutableDictionary *)params{
355355
NSString *path = @"api/request_valid";
356356
NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@api/getCaptcha?type=%@", [NSObject baseURLStr], params[@"type"]]];
357357
//UI
358-
SDCAlertController *alertV = [SDCAlertController alertControllerWithTitle:@"提示" message:@"亲,您操作这么快,不会是机器人吧?\n来,输个验证码先?" preferredStyle:SDCAlertControllerStyleAlert];
358+
SDCAlertController *alertV = [SDCAlertController alertControllerWithTitle:@"提示" message:@"请输入图片验证码" preferredStyle:SDCAlertControllerStyleAlert];
359359
UITextField *textF = [UITextField new];
360360
textF.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);
361361
textF.backgroundColor = [UIColor whiteColor];
@@ -389,7 +389,7 @@ + (void)showCaptchaViewParams:(NSMutableDictionary *)params{
389389
}];
390390
__weak typeof(alertV) weakAlertV = alertV;
391391
[alertV addAction:[SDCAlertAction actionWithTitle:@"取消" style:SDCAlertActionStyleCancel handler:nil]];
392-
[alertV addAction:[SDCAlertAction actionWithTitle:@"还真不是" style:SDCAlertActionStyleDefault handler:nil]];
392+
[alertV addAction:[SDCAlertAction actionWithTitle:@"确定" style:SDCAlertActionStyleDefault handler:nil]];
393393
alertV.shouldDismissBlock = ^BOOL (SDCAlertAction *action){
394394
BOOL shouldDismiss = [action.title isEqualToString:@"取消"];
395395
if (!shouldDismiss) {

0 commit comments

Comments
 (0)