NYTools.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // NYTools.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2024/3/22.
  6. // Copyright © 2024 JCZ. All rights reserved.
  7. //
  8. #import "NYTools.h"
  9. #import "AESCipher.h"
  10. #define nykey @"YojZ7wyaYkgSqf1O"
  11. #define nyIv @"KXh9DfxR0UKCEkH2"
  12. @implementation NYTools
  13. /**
  14. *记录-题目-对错
  15. *userKey 用户id
  16. *carType 车辆类型
  17. *subject 科目几
  18. *exerciseType 题目类型
  19. */
  20. +(void)saveExerciseModel:(RQExerciseModel*)exercise userKey:(NSString*)userKey carType:(RQHomePageCarType)carType subject:(RQHomePageSubjectType)subject exerciseType:(NSUInteger)exerciseType{
  21. NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey];
  22. YYCache *yyCache = [YYCache cacheWithName:NYCocheName];
  23. NSString *NYCocheNameKey = [NSString stringWithFormat:@"NYExerciseKey_%zd_%zd_%zd",carType,subject,exerciseType];
  24. //记录——用户做的题目-答题
  25. NSArray *userAnswer = exercise.userAnswer.copy;
  26. NSDictionary *exer_dic = @{
  27. @"ID":@(exercise.ydtQuestionModel.ID),//题目id
  28. @"type":@(exercise.ydtQuestionModel.Type),//题目类型
  29. @"answerResultsType":@(exercise.answerResultsType),//是否做对
  30. @"userAnswer":userAnswer,//用户选项
  31. };
  32. NSArray *array = [self readExerciseListUserKey:userKey carType:carType subject:subject exerciseType:exerciseType];
  33. NSMutableArray *value = [NSMutableArray arrayWithArray:array];
  34. [value addObject:exer_dic];
  35. //根据key写入缓存value
  36. [yyCache setObject:value forKey:NYCocheNameKey withBlock:^{
  37. NSLog(@"setObject sucess");
  38. }];
  39. }
  40. //读取-题目对错
  41. +(NSArray*)readExerciseListUserKey:(NSString*)userKey carType:(RQHomePageCarType)carType subject:(RQHomePageSubjectType)subject exerciseType:(NSUInteger)exerciseType{
  42. NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey];
  43. YYCache *yyCache = [YYCache cacheWithName:NYCocheName];
  44. NSString *NYCocheNameKey = [NSString stringWithFormat:@"NYExerciseKey_%zd_%zd_%zd",carType,subject,exerciseType];
  45. id object = [yyCache objectForKey:NYCocheNameKey];
  46. if ([object isKindOfClass:[NSMutableArray class]]) {
  47. return (NSArray *)object;
  48. } else {
  49. // 返回一个空数组或者其他默认值,视情况而定
  50. return @[];
  51. }
  52. }
  53. +(void)delExerciseListUserKey:(NSString*)userKey carType:(RQHomePageCarType)carType subject:(RQHomePageSubjectType)subject exerciseType:(NSUInteger)exerciseType{
  54. NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey];
  55. YYCache *yyCache = [YYCache cacheWithName:NYCocheName];
  56. NSString *NYCocheNameKey = [NSString stringWithFormat:@"NYExerciseKey_%zd_%zd_%zd",carType,subject,exerciseType];
  57. [yyCache removeObjectForKey:NYCocheNameKey];
  58. // NSMutableArray *value = [NSMutableArray arrayWithArray:@[]];
  59. // //根据key写入缓存value
  60. // [yyCache setObject:value forKey:NYCocheNameKey withBlock:^{
  61. // NSLog(@"setObject sucess");
  62. // }];
  63. }
  64. //删除-题目
  65. +(void)delateUserKey:(NSString*)userKey {
  66. NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey];
  67. YYCache *yyCache = [YYCache cacheWithName:NYCocheName];
  68. [yyCache removeAllObjects];
  69. }
  70. //保存课堂ID
  71. +(void)saveClassIdStr:(NSString *)classIdStr userKey:(NSString*)userKey{
  72. NSString *NYClassRoomID = [NSString stringWithFormat:@"NYClassRoomID_%@",userKey];
  73. YYCache *yyCache = [YYCache cacheWithName:@"NYClassRoomID"];
  74. //根据key写入缓存value
  75. [yyCache setObject:classIdStr forKey:NYClassRoomID withBlock:^{
  76. NSLog(@"setObject sucess");
  77. }];
  78. }
  79. //读取课堂ID
  80. +(NSString*)readClassIdStr:(NSString*)userKey{
  81. NSString *NYClassRoomID = [NSString stringWithFormat:@"NYClassRoomID_%@",userKey];
  82. YYCache *yyCache = [YYCache cacheWithName:@"NYClassRoomID"];
  83. id object = [yyCache objectForKey:NYClassRoomID];
  84. if ([object isKindOfClass:[NSString class]]) {
  85. return (NSString *)object;
  86. } else {
  87. // 返回一个空数组或者其他默认值,视情况而定
  88. return nil;
  89. }
  90. }
  91. //删除-课堂ID
  92. +(void)delateClassIdStr:(NSString*)userKey {
  93. NSString *NYClassRoomID = [NSString stringWithFormat:@"NYClassRoomID_%@",userKey];
  94. YYCache *yyCache = [YYCache cacheWithName:@"NYClassRoomID"];
  95. [yyCache removeObjectForKey:NYClassRoomID withBlock:^(NSString * _Nonnull key) {
  96. NSLog(@"removeObjectForKey ❤️ sucess");
  97. }];
  98. }
  99. // AES加密方法
  100. + (NSString *)encryptAES:(NSString *)plainText{
  101. NSString *cipherText = aesEncryptString(plainText, nykey);
  102. return cipherText;
  103. }
  104. // AES解密方法
  105. + (NSString *)decryptAES:(id)cipherText{
  106. NSString *decryptedText = aesDecryptString(cipherText, nykey);
  107. return decryptedText;
  108. }
  109. + (BOOL)hasUserWatchedAdToday:(NSString*)keynum {
  110. NSString *kUserLastWatchAdDateKey = [NSString stringWithFormat:@"UserLastWatchAdDateKey%@",keynum];
  111. NSDate *lastDate = [[NSUserDefaults standardUserDefaults] objectForKey:kUserLastWatchAdDateKey];
  112. if (!lastDate) return NO;
  113. NSCalendar *calendar = [NSCalendar currentCalendar];
  114. return [calendar isDateInToday:lastDate];
  115. }
  116. + (void)saveUWatchedAdToday:(NSString*)keynum {
  117. NSString *kUserLastWatchAdDateKey = [NSString stringWithFormat:@"UserLastWatchAdDateKey%@",keynum];
  118. // 记录广告观看时间(建议在广告播放成功的回调中执行)
  119. [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:kUserLastWatchAdDateKey];
  120. }
  121. @end