96 lines
2.8 KiB
Objective-C
96 lines
2.8 KiB
Objective-C
//
|
|
// MainPresenter.m
|
|
// mew-ios
|
|
//
|
|
// Created by 触海 on 2023/11/6.
|
|
//
|
|
|
|
#import "MainPresenter.h"
|
|
#import "AccountInfoStorage.h"
|
|
#import "AccountModel.h"
|
|
#import "Api+Main.h"
|
|
#import "MainProtocol.h"
|
|
#import <NIMSDK/NIMSDK.h>
|
|
#import "MEWRechargeStorage.h"
|
|
|
|
@implementation MainPresenter
|
|
|
|
#pragma mark - Public Method
|
|
/// 获取Ticket
|
|
- (void)autoLogin {
|
|
AccountModel *accountModel = [[AccountInfoStorage instance] getCurrentAccountInfo];
|
|
if (accountModel == nil || accountModel.uid == nil || accountModel.access_token == nil) {
|
|
[[self getView] tokenInvalid];
|
|
return;
|
|
}
|
|
|
|
if ([[AccountInfoStorage instance] getTicket].length > 0) {
|
|
return;
|
|
}
|
|
|
|
// 获取ticket
|
|
[Api requestTicket:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
NSArray *tickets = [data.data valueForKey:@"tickets"];
|
|
NSString *ticket = [tickets[0] valueForKey:@"ticket"];
|
|
[[AccountInfoStorage instance] saveTicket:ticket];
|
|
[[self getView] autoLoginSuccess];
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
[self logout];
|
|
}] access_token:accountModel.access_token issue_type:@"multi"];
|
|
}
|
|
|
|
/// IM登录
|
|
- (void)loginNIM {
|
|
AccountModel *accountModel = [[AccountInfoStorage instance] getCurrentAccountInfo];
|
|
if (accountModel == nil) {
|
|
[[self getView] tokenInvalid];
|
|
return;
|
|
}
|
|
|
|
if (![NIMSDK sharedSDK].loginManager.isLogined) { //没有登录,去登录
|
|
NIMAutoLoginData *data = [[NIMAutoLoginData alloc] init];
|
|
data.account = accountModel.uid;
|
|
data.token = accountModel.netEaseToken;
|
|
data.forcedMode = NO;
|
|
[[NIMSDK sharedSDK].loginManager login:data.account token:data.token completion:^(NSError * _Nullable error) {
|
|
NSLog(@"error :: %@",error);
|
|
}];
|
|
// [[NIMSDK sharedSDK].loginManager autoLogin:data];
|
|
// [[NIMSDK sharedSDK].loginManager addDelegate:self];
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// 获取用户信息
|
|
- (void)getUserInfo {
|
|
[Api getUserInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
[[self getView] getUserInfoSuccess:[UserInfoModel mewModelWithDictionary:data.data]];
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
|
|
}] uid:[[AccountInfoStorage instance] getUid]];
|
|
}
|
|
|
|
/// 检查是否有未消费的内购订单
|
|
- (void)checkTranscation {
|
|
NSString *uid = [AccountInfoStorage instance].getUid;
|
|
NSArray *array = [MEWRechargeStorage mewGetAllReciptsWithUid:uid];
|
|
if (array == nil && array.count == 0) {
|
|
return;
|
|
}
|
|
|
|
NSString *transcationIdStr = [array mewToJSONString];
|
|
[Api requestCheckTranscationIds:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
|
|
|
|
}] transcationIdStr:transcationIdStr];
|
|
}
|
|
|
|
/// 获取版本信息
|
|
- (void)getVersionUpdate {
|
|
|
|
}
|
|
|
|
|
|
@end
|