From 77f09aaf079c8b7c822e43e449214f8b9716a416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E6=98=8E=E6=B5=A9?= Date: Sun, 11 Mar 2018 13:48:24 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90feature=E3=80=91=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E6=97=B6=E6=94=AF=E6=8C=81=E7=9F=AD=E4=BF=A1=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Utinitys/IfishHttpRequest/IFISHHttpTool.h | 11 +++++ .../Utinitys/IfishHttpRequest/IFISHHttpTool.m | 43 ++++++++++++++++--- .../RegistViewController.mm | 15 ++++++- .../RegistViewController.xib | 26 +++++++++-- 4 files changed, 84 insertions(+), 11 deletions(-) diff --git a/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.h b/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.h index f159279..9b7e3c9 100644 --- a/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.h +++ b/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.h @@ -90,6 +90,17 @@ typedef void(^kanHuShangJia)(CertificationShopModel*kanHuShangJia); -(void)getverifyWithTimerButton:(UIButton*)timeBtn addphoneNumber:(NSString*)phoneNumber zone: (NSString*)areaCode result:(void (^)(NSError *err))result; +/** + * 获取验证码 SMS + * + * @param timeBtn 验证码按钮 + * @param zone 区域号,不要加"+"号(Area code) + * @param isTextCode 是否为短信验证码 + */ + +-(void)getverifyWithTimerButton:(UIButton*)timeBtn addphoneNumber:(NSString*)phoneNumber zone: +(NSString*)areaCode isTextCode:(BOOL)isTextCode result:(void (^)(NSError *err))result; + /** * 注册 diff --git a/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.m b/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.m index a12c4d3..376c047 100644 --- a/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.m +++ b/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.m @@ -177,12 +177,12 @@ addPhoneNumber:(NSString*)phoneNumber addSendType:(NSString*)sendType backData:(backVerifyCode)backVerifyCodeblock{ - [self timerFireWithTimerButton:timeBtn addPhoneNumber:phoneNumber]; + [self timerFireWithTimerButton:timeBtn addPhoneNumber:phoneNumber timeBtnFinalTitle:@"语音验证码"]; [self getverifyWithTimerButton:timeBtn addphoneNumber:phoneNumber AddSendType:sendType backData:backVerifyCodeblock]; } #pragma mark 倒计时 --(void)timerFireWithTimerButton:(UIButton*)timeBtn addPhoneNumber:(NSString*)phoneNumber{ +-(void)timerFireWithTimerButton:(UIButton*)timeBtn addPhoneNumber:(NSString*)phoneNumber timeBtnFinalTitle:(NSString *)title{ __block int timeout=60; //倒计时时间 @@ -195,7 +195,7 @@ dispatch_async(dispatch_get_main_queue(), ^{ //设置界面的按钮显示 根据自己需求设置 - [timeBtn setTitle:@"语音验证码" forState:UIControlStateNormal]; + [timeBtn setTitle:title forState:UIControlStateNormal]; timeBtn.userInteractionEnabled = YES; //timeBtn.backgroundColor=COLOR_LABEL_TITLE; [timeBtn setBackgroundImage:[UIImage imageNamed:@"registered_icon_validation"] forState:UIControlStateNormal]; @@ -232,7 +232,7 @@ dispatch_source_cancel(_timer1); dispatch_async(dispatch_get_main_queue(), ^{ //设置界面的按钮显示 根据自己需求设置 - [timeBtn setTitle:@"语音验证码" forState:UIControlStateNormal]; + [timeBtn setTitle:title forState:UIControlStateNormal]; timeBtn.userInteractionEnabled = YES; //timeBtn.backgroundColor=COLOR_LABEL_TITLE; [timeBtn setBackgroundImage:[UIImage imageNamed:@"registered_icon_validation"] forState:UIControlStateNormal]; @@ -311,11 +311,42 @@ #pragma mark - SMS 新 -(void)getverifyWithTimerButton:(UIButton*)timeBtn addphoneNumber:(NSString*)phoneNumber zone: -(NSString*)areaCode result:(void (^)(NSError *err))result +(NSString*)areaCode isTextCode:(BOOL)isTextCode result:(void (^)(NSError *))result + +{ + NSString *title = isTextCode ? @"短信验证码" : @"语音验证码"; + + [self timerFireWithTimerButton:timeBtn addPhoneNumber:phoneNumber timeBtnFinalTitle:title]; + + [SMSSDK getVerificationCodeByMethod:isTextCode ? SMSGetCodeMethodSMS : SMSGetCodeMethodVoice phoneNumber:phoneNumber zone:areaCode customIdentifier:nil result:^(NSError *error) { + + if (!error) { + NSLog(@"获取验证码成功"); + + } else { + NSLog(@"错误信息:%@",error); + dispatch_source_cancel(_timer1); + dispatch_async(dispatch_get_main_queue(), ^{ + //设置界面的按钮显示 根据自己需求设置 + [timeBtn setTitle:title forState:UIControlStateNormal]; + timeBtn.userInteractionEnabled = YES; + //timeBtn.backgroundColor=COLOR_LABEL_TITLE; + [timeBtn setBackgroundImage:[UIImage imageNamed:@"registered_icon_validation"] forState:UIControlStateNormal]; + + }); + [self showTitle:@"" messsage:@"获取验证失败"]; + + } + + }]; +} + +-(void)getverifyWithTimerButton:(UIButton*)timeBtn addphoneNumber:(NSString*)phoneNumber zone: +(NSString*)areaCode result:(void (^)(NSError *))result { - [self timerFireWithTimerButton:timeBtn addPhoneNumber:phoneNumber]; + [self timerFireWithTimerButton:timeBtn addPhoneNumber:phoneNumber timeBtnFinalTitle:@"语音验证码"]; [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodVoice phoneNumber:phoneNumber zone:areaCode customIdentifier:nil result:^(NSError *error) { diff --git a/Ifish/controllers/logAddRegistController/RegistViewController.mm b/Ifish/controllers/logAddRegistController/RegistViewController.mm index ea851d2..bd9b198 100644 --- a/Ifish/controllers/logAddRegistController/RegistViewController.mm +++ b/Ifish/controllers/logAddRegistController/RegistViewController.mm @@ -60,6 +60,8 @@ @property(nonatomic) double latitude; @property(nonatomic,copy) NSString *adderss; +@property (weak, nonatomic) IBOutlet UILabel *qrcodeSwitchLbl; + @end extern BOOL formLogIn; @@ -133,12 +135,21 @@ extern BOOL formLogIn; //NSString *zone = [dataContorl areaCode:self.phoneNumberTextField.text]; //self.areaCode = zone; - - [IFISHHTTPTOOL getverifyWithTimerButton:_timeBtn addphoneNumber:self.phoneNumberTextField.text zone:self.areaCode result:^(NSError *err) { + BOOL isTextCode = [[self.timeBtn titleForState:UIControlStateNormal] isEqualToString:@"短信验证码"]; + [IFISHHTTPTOOL getverifyWithTimerButton:_timeBtn addphoneNumber:self.phoneNumberTextField.text zone:self.areaCode isTextCode:isTextCode result:^(NSError *err) { }]; } +- (IBAction)qrcodeSwithBtnClicked:(UIButton *)sender { + if ([[self.timeBtn titleForState:UIControlStateNormal] isEqualToString:@"语音验证码"]) { + [self.timeBtn setTitle:@"短信验证码" forState:UIControlStateNormal]; + self.qrcodeSwitchLbl.text = @"语音验证码"; + } else if ([[self.timeBtn titleForState:UIControlStateNormal] isEqualToString:@"短信验证码"]) { + [self.timeBtn setTitle:@"语音验证码" forState:UIControlStateNormal]; + self.qrcodeSwitchLbl.text = @"短信验证码"; + } +} #pragma mark-设置键盘样式 -(void)setTextkeyboadType{ diff --git a/Ifish/controllers/logAddRegistController/RegistViewController.xib b/Ifish/controllers/logAddRegistController/RegistViewController.xib index 570b807..102f191 100644 --- a/Ifish/controllers/logAddRegistController/RegistViewController.xib +++ b/Ifish/controllers/logAddRegistController/RegistViewController.xib @@ -1,11 +1,11 @@ - + - + @@ -16,6 +16,7 @@ + @@ -118,7 +119,7 @@ - @@ -173,20 +187,25 @@ + + + + + @@ -195,6 +214,7 @@ +