// // LoginVerifCodePresent.m // YUMI // // Created by YUMI on 2021/9/9. // #import "LoginVerifCodePresent.h" ///第三方 #import ///Tool #import "AccountInfoStorage.h" #import "DESEncrypt.h" #import "YUMIConstant.h" ///Api #import "Api+Login.h" ///Presenter #import "LoginVerifCodePresent.h" ///Protocol #import "LoginVerifCodeProtocol.h" ///Model #import "AccountModel.h" @implementation LoginVerifCodePresent - (id)getView { return ((id) [super getView]); } /// 获取手机的验证码 /// @param phone 手机号 /// @param type 类型 - (void)phoneSmsCode:(NSString *)phone type:(GetSmsType)type phoneAreaCode:(NSString *)phoneAreaCode { NSString * desPhone = [DESEncrypt encryptUseDES:phone key:KeyWithType(KeyType_PasswordEncode)]; [Api phoneSmsCode:[self createHttpCompletion:^(id _Nonnull data) { [[self getView] phoneSmsCodeSuccess]; }] mobile:desPhone type:[NSString stringWithFormat:@"%lu", (unsigned long)type] phoneAreaCode:phoneAreaCode]; } /// 使用手机号和验证码登录 /// @param phone 手机号 /// @param code 验证码 - (void)loginWithPhone:(NSString *)phone code:(NSString *)code phoneAreaCode:(NSString *)phoneAreaCode{ NSString * desPhone = [DESEncrypt encryptUseDES:phone key:KeyWithType(KeyType_PasswordEncode)]; [Api loginWithCode:[self createHttpCompletion:^(BaseModel * _Nonnull data) { AccountModel * accountModel = [AccountModel modelWithDictionary:data.data]; if (accountModel && accountModel.access_token.length > 0) { [[AccountInfoStorage instance] saveAccountInfo:accountModel]; } [[self getView] loginWithPhoenSuccess]; } fail:^(NSInteger code, NSString * _Nullable msg) { [[self getView] loginFailWithMsg:msg]; } errorToast:YES] phone:desPhone code:code client_secret:@"uyzjdhds" version:@"1" client_id:@"erban-client" grant_type:@"password" phoneAreaCode:phoneAreaCode]; } /// 使用手机号和密码登录 /// @param phone 手机号 /// @param password 验证码 - (void)loginWithPhone:(NSString *)phone password:(NSString *)password { NSString * desPassword = [DESEncrypt encryptUseDES:password key:KeyWithType(KeyType_PasswordEncode)]; NSString * desPhone = [DESEncrypt encryptUseDES:phone key:KeyWithType(KeyType_PasswordEncode)]; [Api loginWithPassword:[self createHttpCompletion:^(BaseModel * _Nonnull data) { AccountModel * accountModel = [AccountModel modelWithDictionary:data.data]; if (accountModel && accountModel.access_token.length > 0) { [[AccountInfoStorage instance] saveAccountInfo:accountModel]; } [[self getView] loginSuccess]; } fail:^(NSInteger code, NSString * _Nullable msg) { [[self getView] loginFailWithMsg:msg]; } errorToast:YES] phone:desPhone password:desPassword client_secret:@"uyzjdhds" version:@"1" client_id:@"erban-client" grant_type:@"password"]; } /// 绑定手机号 /// @param phone 手机号 /// @param code 验证码 - (void)bindWithPhone:(NSString *)phone code:(NSString *)code phoneAreaCode:(NSString *)phoneAreaCode{ NSString * ticket = [[AccountInfoStorage instance] getTicket]; NSString * desPhone = [DESEncrypt encryptUseDES:phone key:KeyWithType(KeyType_PasswordEncode)]; [Api bindMoblieCode:[self createHttpCompletion:^(BaseModel * _Nonnull data) { [[self getView] bindPhoneSuccess]; } showLoading:YES] phone:desPhone code:code ticket:ticket phoneAreaCode:phoneAreaCode]; } -(void)bindAuthorizationCodeWithAuthCode:(NSString *)authCode{ [Api bindAuthorizationCode:[self createHttpCompletion:^(BaseModel * _Nonnull data) { [[self getView] bindAuthorizationCodeSuccess]; }fail:^(NSInteger code, NSString * _Nullable msg) { [[self getView]bindAuthorizationCodeFail]; } showLoading:YES errorToast:YES] authCode:authCode]; } @end