Commit 13d972ff authored by “Icebear”'s avatar “Icebear”

调试通过登录验证码

parent 6742b09f
......@@ -10,9 +10,13 @@
NS_ASSUME_NONNULL_BEGIN
@interface BaseHttpModel : NSObject
@property(nonatomic, assign) NSInteger errcode;
@property(nonatomic, strong) NSString *errmsg;
@property(nonatomic, strong) NSDictionary *data;
@property(nonatomic, assign) NSInteger code;
@property(nonatomic, strong) NSString *msg;
@property(nonatomic, strong) id data;
- (BOOL)isSucc;
- (NSString *)errorMsg;
@end
NS_ASSUME_NONNULL_END
......@@ -8,6 +8,15 @@
#import "BaseHttpModel.h"
#define kBaseApiOtherError @"服务器错误,请稍后再试"
#define kSuccHttpCode 0
@implementation BaseHttpModel
- (BOOL)isSucc {
return self.code == kSuccHttpCode;
}
- (NSString *)errorMsg {
return self.msg.length > 0 ? self.msg : kBaseApiOtherError;
}
@end
......@@ -8,7 +8,7 @@
#import <Foundation/Foundation.h>
typedef enum : NSUInteger {
AppServer_Developer,
AppServer_Developer = 0,
AppServer_Product,
} AppServer;
......
......@@ -15,7 +15,7 @@
dispatch_once(&onceToken, ^{
if (!sharedInstance) {
sharedInstance = [[self alloc] init];
sharedInstance.appServer = 1;
sharedInstance.appServer = AppServer_Product;
sharedInstance.useSSL = NO;
[sharedInstance cofigureAppServer];
}
......@@ -32,7 +32,7 @@
NSData *jsonData = [str dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
NSDictionary *urlDict = [NSDictionary dictionary];
if(self.appServer == ProductSever){
if(self.appServer == AppServer_Product){
urlDict = _useSSL ? (dict[@"product"][@"https"]) : (dict[@"product"][@"http"]);
self.kHost = [dict objectForKey:@"kHost"];
}else{
......
......@@ -9,7 +9,7 @@
///环境Url
#import "NRGlobalUrlModel.h"
#import "NRBaseModelAgent.h"
#import "BaseHttpModel.h"
/*
接口请求基类,所有请求必须继承此类
这里采用的是YTKNetwork网络库,中大型APP专用,可满足所有网络需求
......@@ -18,9 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface NRBaseRequest : YTKBaseRequest
//自定义属性值
@property(nonatomic,assign)BOOL isSuccess;//是否成功
@property (nonatomic,copy) NSString * message;//服务器返回的信息
@property (nonatomic,copy) NSDictionary * result;//服务器返回的数据 已解密
@property(nonatomic, readonly) BaseHttpModel *httpModel;
- (void)startWithCompletionBlock:(void (^)(NRBaseRequest *request, NSString *error))block;
......
......@@ -7,10 +7,8 @@
#import "NRBaseRequest.h"
#import "NRGlobalUrlModel.h"
#import "BaseHttpModel.h"
#define kBaseApiOtherError @"服务器错误,请稍后再试"
#define kSuccHttpCode 0
@interface NRBaseRequest()
......@@ -45,14 +43,7 @@
return _httpModel;
}
- (BOOL)isSucc {
BaseHttpModel *httpModel = self.httpModel;
return httpModel && httpModel.errcode == kSuccHttpCode;
}
- (NSString *)errorMsg {
BaseHttpModel *httpModel = self.httpModel;
return httpModel.errmsg.length > 0 ? httpModel.errmsg : kBaseApiOtherError;
}
-(NSDictionary *)requestHeaderFieldValueDictionary{
NSDictionary *headers = [NSDictionary dictionaryWithObjectsAndKeys:@"application/x-www-form-urlencoded;charset=utf-8", @"Content-Type",@"iPhone 8",@"_m",@"1",@"_p",@"1",@"_o",@"1",@"_n",@"1.0.0",@"_v",@"1.0",@"_nv",@"14.55.27.328",@"startTime",nil];
......@@ -67,11 +58,11 @@
return;
}
__strong typeof(weakSelf) strongSelf = weakSelf;
if ([strongSelf isSucc]) {
if ([strongSelf.httpModel isSucc]) {
block(strongSelf, nil);
}
else {
block(strongSelf, [strongSelf errorMsg]);
block(strongSelf, [strongSelf.httpModel errorMsg]);
}
} failure:^(__kindof YTKBaseRequest *_Nonnull request) {
......
......@@ -13,7 +13,7 @@ typedef NS_ENUM(NSUInteger, UserSelectLoginMode) {
verificationLogin, //验证码登录
};
@interface NRLoginViewController ()<QMUITextFieldDelegate>
@interface NRLoginViewController ()<QMUITextFieldDelegate,NRLoginLogicDelegate>
@property (weak, nonatomic) IBOutlet QMUITextField *phoneNumberField;
@property (weak, nonatomic) IBOutlet QMUITextField *passwdField;
......@@ -106,6 +106,16 @@ typedef NS_ENUM(NSUInteger, UserSelectLoginMode) {
}
}
#pragma mark -- NRLoginLogicDelegate
-(void)requestDataCompleted:(BaseHttpModel *)httpModel{
[QMUITips hideAllTips];
if(httpModel.isSucc){
[QMUITips showSucceed:httpModel.errorMsg];
}else{
[QMUITips showError:httpModel.errorMsg];
}
}
#pragma mark -- IBAction
///显示密码
- (IBAction)showPassword:(id)sender {
......@@ -124,6 +134,11 @@ typedef NS_ENUM(NSUInteger, UserSelectLoginMode) {
}
///获取验证码
- (IBAction)getVerification:(id)sender {
if([self.phoneNumberField.text qmui_trimAllWhiteSpace].length != 11){
[QMUITips showError:@"请输入正确的手机号"];
return;
}
[QMUITips showLoading:@"获取中" inView:self.view];
[self.loginLogic getVerifyCodeAction:self.phoneNumberField.text];
}
......@@ -189,6 +204,7 @@ typedef NS_ENUM(NSUInteger, UserSelectLoginMode) {
-(NRLoginLogic *)loginLogic{
if(!_loginLogic){
_loginLogic = [[NRLoginLogic alloc] init];
_loginLogic.logicDelegate = self;
}
return _loginLogic;
}
......
......@@ -6,6 +6,10 @@
//
#import "NRBaseRequest.h"
#import "NRPasswordLoginRequest.h"
#import "NRServerTimeRequest.h"
#import "NRVerifyCodeRequest.h"
@protocol NRLoginLogicDelegate <NSObject>
@optional
......@@ -16,15 +20,15 @@
/**
数据加载完成
*/
-(void)requestDataCompleted;
-(void)requestDataCompleted:(BaseHttpModel *_Nullable)httpModel;
@end
NS_ASSUME_NONNULL_BEGIN
@interface NRLoginLogic : NRBaseRequest
@interface NRLoginLogic : NSObject
@property(nonatomic,weak)id<NRLoginLogicDelegate> delegagte;
@property(nonatomic,weak) id<NRLoginLogicDelegate> logicDelegate;
- (void)getVerifyCodeAction:(NSString *)phoneNumber;
......
......@@ -6,9 +6,6 @@
//
#import "NRLoginLogic.h"
#import "NRPasswordLoginRequest.h"
#import "NRServerTimeRequest.h"
#import "NRVerifyCodeRequest.h"
@implementation NRLoginLogic
......@@ -16,11 +13,26 @@
NRServerTimeRequest *servertimeRequest = [[NRServerTimeRequest alloc] init];
[servertimeRequest startWithCompletionBlock:^(NRBaseRequest * _Nonnull request, NSString * _Nonnull error) {
if (!error) {
if (self.delegagte && [self.delegagte respondsToSelector:@selector(requestDataCompleted)]) {
[self.delegagte requestDataCompleted];
NSString *tvalue = [servertimeRequest.httpModel.data objectAtIndex:0];
NRVerifyCodeRequest *verifyCodeRequest = [[NRVerifyCodeRequest alloc] init];
verifyCodeRequest.phoneNumber = phoneNumber;
verifyCodeRequest.actionType = @"6";
verifyCodeRequest.tvalue = tvalue ? tvalue : @"";
[verifyCodeRequest startWithCompletionBlock:^(NRBaseRequest * _Nonnull request, NSString * _Nonnull error) {
if (!error) {
}
if (self.logicDelegate && [self.logicDelegate respondsToSelector:@selector(requestDataCompleted:)]) {
[self.logicDelegate requestDataCompleted:request.httpModel];
}
}];
}else{
if (self.logicDelegate && [self.logicDelegate respondsToSelector:@selector(requestDataCompleted:)]) {
[self.logicDelegate requestDataCompleted:request.httpModel];
}
}
}];
}
- (void)verifyCodeLoginAction{
......
......@@ -11,8 +11,12 @@ NS_ASSUME_NONNULL_BEGIN
@interface NRVerifyCodeRequest : NRBaseRequest
@property(nonatomic, copy) NSString *actionType;
@property(nonatomic, copy) NSString *phoneNumber;
@property(nonatomic, copy) NSString *tvalue;
@end
NS_ASSUME_NONNULL_END
......@@ -6,10 +6,20 @@
//
#import "NRVerifyCodeRequest.h"
#define SECRET_KEY @"wu268m4iu8phczre4b"
@implementation NRVerifyCodeRequest
-(NSString *)requestUrl{
return @"/sendSms";
return @"sendSms";
}
-(id)requestArgument{
return @{
@"sign": [[[NSString stringWithFormat:@"actionType=%@&phoneNum=%@&t=%@%@",self.actionType,self.phoneNumber,self.tvalue,SECRET_KEY] qmui_md5] lowercaseString],
@"t": self.tvalue,
@"phoneNum" : self.phoneNumber,
@"actionType" : self.actionType,
};
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment