一起养成写作习惯!这是我参与「日新计划 4 月更文挑战」的第16天,点击查看活动详情。
I 前置知识
1.1 分布式系统下的session

session: 一种保存key-value的机制 key:
- sessionID
- token (配合签名一起使用)

1.2 服务端侧的登录处理
- openid去和数据库里的数据匹配(采用微信授权登接口英文录)
- 设置token至redis
- 设置token至cookie
1.3 app侧需求
-
冷启动ap接口是什么p数据库查询语句时,若token不过期,就使用最近一次登录的t数据库查询语句oken进行工龄差一年工资差多少数据请求
-
优化toke数据库系统概论第五版课后答案n的存储方式:
之前只是存储在内存,只要杀死app,重新打开就要求重新登录。现在改为将token信息存储到本地数据库,每次打开ap数据库系统的核心是p使用最近一次登录获得的to数据库查询语句ken。
II app侧登录流程
2.1 开发步骤
- I、保存token到UserInfoModel 对象中
- II、再次打开app的时候获取token
- III、退出登录或者(token)失效进行信息信息清除
- IV、在登录界面的viewDidLoad 进行判断是否直接进入首页
- V : token存测试你的自卑程度储区分正式环境和测试环境(U接口类型serInfoModel 对象新增一个当前token的域名属性c逆向思维十大口诀urre测试抑郁程度的问卷ntHost,用于查询判断) 5.1) 更换表名 5.2)UserInfoModel新增字段currentHost, 5.3)查询token新增条件currentHost 5.4) 存储token新增字段currentHost
2.2 token信息存储注意事项
登录账号得到的token信息。最好不要作为一个独立的单利接口crc错误计数对象存储;而是将它作为单公积金例对象的属性userInfo,这样便于切接口卡换账号存储token和其他账号信息
- 如果之前是使用独立的单利对象UserInfoModel ,为了兼容代码可以这么做
/** 登录账号得到的token信息。最好不要作为一个独立的单利对象存储;而是将它作为单例对象的属性userInfo,便于切换账号存储token和其他账号信息。 */ + (instancetype)shareUserInfoModel{ return [QCTSession.shareQCTSession userInfo]; }
使用线程安全模式来创建共享实例,并使用条件编译#if进行A测试英文RC、MRC的适配
kunna逆向n.blog.csdn.net/artic测试抑郁症的20道题le/det…
2.3 整体思路
保存和清除token
- 使用BGF数据库设计MDB 进保存最近逆向选择一次登录的token
pod 'BGFMDB', '~> 2.0.13' #2.0.9
- 切换账号的时候更换token
- 请求接口发现token 失效的时候,回到登录界面
III 核心实现
3.1 Sessio测试工程师n 对象的创建
使用HSSingleton工具类实现单例,并将包含登陆token及其他有状态相关字段的userInfo对象作为单例对象的属性
HSSingletonH(Session); HSSingletonM(Session); + (void)SaveUserInfo:(UserInfoModel *)userInfo{ QCTSession.shareQCTSession.userInfo = userInfo; }
存储token信息
#pragma mark - ******** iOS 优化登录流程:【打开app,如果 token不过期,就使用最近一次登录的tokenn进行接口请求。】(现状是每次打开app都会重新登录) + (void)saveModelWithModel:(UserInfoModel*)userModel{ [self emptySeeionLocal]; userModel.bg_tableName = QCTUserInfoModelTableName; BOOL isSave = [userModel bg_save];// 保存方法 if (isSave) { NSLog(@"token保存成功:%@",userModel.mj_keyValues); }else{ NSLog(@"token保存失败:%@",userModel.mj_keyValues); } } +(void)emptySeeionLocal{ NSMutableArray *tmparr = [NSMutableArray arrayWithArray:[[self class] bg_find:QCTUserInfoModelTableName where:nil] ]; // 先删除 for (UserInfoModel *loginModel in tmparr) { NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"bg_id"),bg_sqlValue(loginModel.bg_id)]; BOOL isDelete = [UserInfoModel bg_delete:[NSString stringWithFormat:@"%@",QCTUserInfoModelTableName] where:where]; NSLog(@"删除重复数据%@:%@",isDelete?@"成功":@"失败",loginModel.mj_keyValues); // break; // } }
获取token信息
+ (instancetype)getmodel4LoginSeesion{ NSMutableArray *tmparr = [NSMutableArray arrayWithArray:[[self class] bg_find:QCTUserInfoModelTableName where:nil] ]; if(tmparr.count>0 ){ UserInfoModel *userModel = tmparr.firstObject; // QCTSession.shareQCTSession.userInfo = userModel; [ QCTSession SaveUserInfo:userModel]; NSLog(@"获取的token 信息%@",userModel); return tmparr.firstObject; } NSLog(@"获取的token userModel.shareUserInfoModel %@",UserInfoModel.shareUserInfoModel); // return UserInfoModel.shareUserInfoModel; }
3.2 保存token到UserInfoModel 对象中的时机
- 登录的时候
[ Session SaveUserInfo:userModel]; [UserInfoModel saveModelWithModel:userModel];
- app 退出的时候:applicationWillTerminate 、applicationWillResignActive
- (void)applicationWillTerminate:(UIApplication *)application { // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. [UserInfoModel saveModelWithModel:UserInfoModel.shareUserInfoModel]; }
3.3 再次打开app的时候获取token
#pragma mark - ******** 获取token信息 - (void)initInfo{ QCTSession.shareQCTSession.tmpUserInfoModel = nil; [UserInfoModel getmodel4LoginSeesion];// 获取会话 } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self initInfo]; }
3.4 退测试仪出登录或者(token)失效进行信息信息清除
- 在 application :didFinishLaunc测试抑郁症hingWithOptions: 方法进行监听
__weak __typeof__(self) weakSelf = self; [[[NSNotificationCenter defaultCenter] rac_addObserverForName:kExitlogshowLoginViewNotification object:nil] subscribeNext:^(NSNotification *notification) { NSString *tmp = @""; if(notification.object){ tmp = notification.object; [weakSelf.window showHUDMessage:tmp afterBlock:^(id _Nonnull sender) { [weakSelf setupExitlogout]; }]; }else{ // tmp = @""; [weakSelf setupExitlogout]; } }];
- 退出登录(token过期)的处理
/** 1、移除极光的别名 2、初始化一些信息 3、清除账户信息缓存(本地数据库和内存中的token信息) */ - (void)setupExitlogout { [JPUSHService setTags:nil alias:@"" callbackSelector:@selector(tagsAliasCallback:tags:alias:) object:self]; [UserInfoModel cleanInfoWithblock:^(id sender) { //3、登录 UserInfoModel.shareUserInfoModel.token = nil; AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; [appDelegate setupLoginV]; }]; }
- 清除本地数据库的token
+ (void)cleanInfoWithblock:(void (^)(id sender))block{ [[UserInfoModel shareUserInfoModel] cleanInfo]; if(block){ block(nil); } } - (void)cleanInfo{ #pragma mark - ******** 包括清除本地数据库的token [[self class] emptySeeionLocal];// [self setToken:nil]; _CurrentSysUser = nil; // _ [QCTSession shareQCTSession].tmpUserInfoModel = nil; }
3.5 在登录界面的viewDidLoad 进行判断是否直接接口英文进入测试工程师首页
- viewDidLoad 早createSubView的时候进行判断,是否直接进入首页
if(UserInfoModel.shareUserInfoModel.isLoginByToken){ [[self class] jumpHome]; return; }
- 判接口英文断是否有token
/** 判断是否有token */ - (BOOL)isLoginByToken{ if(![NSStringQCTtoll isBlankString:UserInfoModel.shareUserInfoModel.token]){ return YES; } return NO; }
3.6 token存储区分正式环境和测试环境
-
UserInfoModel 对象新增一个当前token的域名属性currentHost,用于查询判断环境
-
BGoGFMDB如果新增字段,就需要接口是什么更换一下表名
#warning BGFMDB如果新增字段,就需要更换一下表名,否则在旧表会找不到字段,无法更新数据 2021-01-29 17:16:10.418453+0800 Housekeeper[15013:1071895] [logging] table QCTUserInfoModelTableName0401 has no column named BG_IsreqGetCurrentSysUsering in "insert into QCTUserInfoModelTableName0401(BG_currentHost,BG_BearerToken,BG_token,BG_DictionariesEnum,BG_DictionariesEnumDictionary,BG_loginCode,BG_isGotoChangePassword,BG_HaveDefaultLevel,BG_bg_updateTime,BG_loginMessage,BG_IsreqGetCurrentSysUsering,BG_IsTobacco,BG_bg_createTime,BG_MsgsourceStr,BG_isShowBindingMobileNote) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"
- 根据域名进行存取t接口类型oken的

NSString* where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"currentHost"),bg_sqlValue(currentHost)]; NSMutableArray *tmparr = [NSMutableArray arrayWithArray:[[self class] bg_find:QCTUserInfoModelTableName where:where] ];
存储接口测试token信接口息
+ (void)saveModelWithModel:(UserInfoModel*)userModel{ [self emptySeeionLocal]; userModel.bg_tableName = QCTUserInfoModelTableName; userModel.currentHost = currentHost; BOOL isSave = [userModel bg_save];// 保存方法 if (isSave) { NSLog(@"token保存成功:%@",userModel.mj_keyValues); }else{ NSLog(@"token保存失败:%@",userModel.mj_keyValues); } }
3.7 注意事项
- `2020-03-30 19:23:12.877204+0800 Housekeeper[5577:1118700] DB Error: 1 “duplicate公积金 column name: BG_CompanyId”
` BGFMDB 不支持大小写,因此保存的对象不能有大小写的两个字段
@property (copy, nonatomic) NSString *companyId; //@property (strong, nonatomic) NSString *CompanyId;
- `2020-04-01 16:18:32.127564+0800 retail[8875:1402725] [logging] table QCTUserInfoModelTableName has no column named BG_currentHost
`
调试技巧
如果BGFMDB的表新增字段,可更换一下表名,避免找不到字段,数逆向据更新失败
如果新增字段,就需要更换一下数据库系统概论第五版课后答案表名
IV测试抑郁程度的问卷 see also
公众号:iOS逆向
评论(0)