NYTools.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. //删除-题目
  54. +(void)delateUserKey:(NSString*)userKey{
  55. NSString *NYCocheName = [NSString stringWithFormat:@"NYExercise_%@",userKey];
  56. YYCache *yyCache = [YYCache cacheWithName:NYCocheName];
  57. [yyCache removeAllObjects];
  58. }
  59. // AES加密方法
  60. + (NSString *)encryptAES:(NSString *)plainText{
  61. NSString *cipherText = aesEncryptString(plainText, nykey);
  62. return cipherText;
  63. }
  64. // AES解密方法
  65. + (NSString *)decryptAES:(id)cipherText{
  66. NSString *decryptedText = aesDecryptString(cipherText, nykey);
  67. return decryptedText;
  68. }
  69. @end