// // NYTools.m // jiaPei // // Created by Ning.ge on 2024/3/22. // Copyright © 2024 JCZ. All rights reserved. // #import "NYTools.h" #import "AESCipher.h" #define nykey @"YojZ7wyaYkgSqf1O" #define nyIv @"KXh9DfxR0UKCEkH2" @implementation NYTools /** *记录-题目-对错 *userKey 用户id *carType 车辆类型 *subject 科目几 *exerciseType 题目类型 */ +(void)saveExerciseModel:(RQExerciseModel*)exercise userKey:(NSString*)userKey carType:(RQHomePageCarType)carType subject:(RQHomePageSubjectType)subject exerciseType:(NSUInteger)exerciseType{ NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey]; YYCache *yyCache = [YYCache cacheWithName:NYCocheName]; NSString *NYCocheNameKey = [NSString stringWithFormat:@"NYExerciseKey_%zd_%zd_%zd",carType,subject,exerciseType]; //记录——用户做的题目-答题 NSArray *userAnswer = exercise.userAnswer.copy; NSDictionary *exer_dic = @{ @"ID":@(exercise.ydtQuestionModel.ID),//题目id @"type":@(exercise.ydtQuestionModel.Type),//题目类型 @"answerResultsType":@(exercise.answerResultsType),//是否做对 @"userAnswer":userAnswer,//用户选项 }; NSArray *array = [self readExerciseListUserKey:userKey carType:carType subject:subject exerciseType:exerciseType]; NSMutableArray *value = [NSMutableArray arrayWithArray:array]; [value addObject:exer_dic]; //根据key写入缓存value [yyCache setObject:value forKey:NYCocheNameKey withBlock:^{ NSLog(@"setObject sucess"); }]; } //读取-题目对错 +(NSArray*)readExerciseListUserKey:(NSString*)userKey carType:(RQHomePageCarType)carType subject:(RQHomePageSubjectType)subject exerciseType:(NSUInteger)exerciseType{ NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey]; YYCache *yyCache = [YYCache cacheWithName:NYCocheName]; NSString *NYCocheNameKey = [NSString stringWithFormat:@"NYExerciseKey_%zd_%zd_%zd",carType,subject,exerciseType]; id object = [yyCache objectForKey:NYCocheNameKey]; if ([object isKindOfClass:[NSMutableArray class]]) { return (NSArray *)object; } else { // 返回一个空数组或者其他默认值,视情况而定 return @[]; } } +(void)delExerciseListUserKey:(NSString*)userKey carType:(RQHomePageCarType)carType subject:(RQHomePageSubjectType)subject exerciseType:(NSUInteger)exerciseType{ NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey]; YYCache *yyCache = [YYCache cacheWithName:NYCocheName]; NSString *NYCocheNameKey = [NSString stringWithFormat:@"NYExerciseKey_%zd_%zd_%zd",carType,subject,exerciseType]; [yyCache removeObjectForKey:NYCocheNameKey]; // NSMutableArray *value = [NSMutableArray arrayWithArray:@[]]; // //根据key写入缓存value // [yyCache setObject:value forKey:NYCocheNameKey withBlock:^{ // NSLog(@"setObject sucess"); // }]; } //删除-题目 +(void)delateUserKey:(NSString*)userKey { NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey]; YYCache *yyCache = [YYCache cacheWithName:NYCocheName]; [yyCache removeAllObjects]; } //保存课堂ID +(void)saveClassIdStr:(NSString *)classIdStr userKey:(NSString*)userKey{ NSString *NYClassRoomID = [NSString stringWithFormat:@"NYClassRoomID_%@",userKey]; YYCache *yyCache = [YYCache cacheWithName:@"NYClassRoomID"]; //根据key写入缓存value [yyCache setObject:classIdStr forKey:NYClassRoomID withBlock:^{ NSLog(@"setObject sucess"); }]; } //读取课堂ID +(NSString*)readClassIdStr:(NSString*)userKey{ NSString *NYClassRoomID = [NSString stringWithFormat:@"NYClassRoomID_%@",userKey]; YYCache *yyCache = [YYCache cacheWithName:@"NYClassRoomID"]; id object = [yyCache objectForKey:NYClassRoomID]; if ([object isKindOfClass:[NSString class]]) { return (NSString *)object; } else { // 返回一个空数组或者其他默认值,视情况而定 return nil; } } //删除-课堂ID +(void)delateClassIdStr:(NSString*)userKey { NSString *NYClassRoomID = [NSString stringWithFormat:@"NYClassRoomID_%@",userKey]; YYCache *yyCache = [YYCache cacheWithName:@"NYClassRoomID"]; [yyCache removeObjectForKey:NYClassRoomID withBlock:^(NSString * _Nonnull key) { NSLog(@"removeObjectForKey ❤️ sucess"); }]; } // AES加密方法 + (NSString *)encryptAES:(NSString *)plainText{ NSString *cipherText = aesEncryptString(plainText, nykey); return cipherText; } // AES解密方法 + (NSString *)decryptAES:(id)cipherText{ NSString *decryptedText = aesDecryptString(cipherText, nykey); return decryptedText; } + (BOOL)hasUserWatchedAdToday:(NSString*)keynum { NSString *kUserLastWatchAdDateKey = [NSString stringWithFormat:@"UserLastWatchAdDateKey%@",keynum]; NSDate *lastDate = [[NSUserDefaults standardUserDefaults] objectForKey:kUserLastWatchAdDateKey]; if (!lastDate) return NO; NSCalendar *calendar = [NSCalendar currentCalendar]; return [calendar isDateInToday:lastDate]; } + (void)saveUWatchedAdToday:(NSString*)keynum { NSString *kUserLastWatchAdDateKey = [NSString stringWithFormat:@"UserLastWatchAdDateKey%@",keynum]; // 记录广告观看时间(建议在广告播放成功的回调中执行) [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:kUserLastWatchAdDateKey]; } @end