RQVIPModule.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. //
  2. // RQVIPModule.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/2/28.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQVIPModule.h"
  9. #include <CommonCrypto/CommonCrypto.h>
  10. @interface RQVIPModule ()
  11. @end
  12. @implementation RQVIPModule
  13. static id rq_VIPModule = nil;
  14. #pragma mark - init
  15. + (instancetype)sharedInstance {
  16. static dispatch_once_t onceToken;
  17. dispatch_once(&onceToken, ^{
  18. rq_VIPModule = [[self alloc] init];
  19. });
  20. return rq_VIPModule;
  21. }
  22. - (instancetype)init {
  23. if (self = [super init]) {
  24. }
  25. return self;
  26. }
  27. #pragma mark - PublicMethods
  28. - (void)gotoBuyVipWithVipPageType:(RQVIPPageType)vipPageType {
  29. [self gotoBuyVipWithVipPageType:vipPageType subject:RQ_YDTQuestion_Module.subject];
  30. }
  31. - (void)gotoBuyVipWithVipPageType:(RQVIPPageType)vipPageType subject:(RQHomePageSubjectType)subject {
  32. WeakSelf(weakSelf)
  33. [RQ_VIP_Module isActiveWithCcomplete:^(RQActivationModel * _Nullable activationModel, BOOL isSuccess) {
  34. if (isSuccess) {
  35. if (activationModel.isShare) {
  36. if (vipPageType == RQVIPPageType_Alert) {
  37. [weakSelf showVipAlertWithDictType:RQ_USER_MANAGER.currentUser.city subject:subject];
  38. } else {
  39. [weakSelf gotoVipViewWithDictType:RQ_USER_MANAGER.currentUser.city subject:subject];
  40. }
  41. } else {
  42. NSString *typeStr = subject > 4? @"vip_coach_package": @"vip_package";
  43. if (vipPageType == RQVIPPageType_Alert) {
  44. [weakSelf showVipAlertWithDictType:typeStr subject:subject];
  45. } else {
  46. [weakSelf gotoVipViewWithDictType:typeStr subject:subject];
  47. }
  48. }
  49. }
  50. }];
  51. }
  52. - (void)showVipAlertWithDictType:(NSString *)dictType subject:(RQHomePageSubjectType)subject {
  53. if (RQ_USER_MANAGER.isShouldLogin) {
  54. [MBProgressHUD rq_showProgressHUD:@"获取VIP套餐..."];
  55. [[RQ_HTTP_Service getTypeWithDictType:dictType] subscribeNext:^(NSArray *typeModels) {
  56. [MBProgressHUD rq_hideHUD];
  57. RQVipViewModel *vipViewModel = [[RQVipViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  58. RQViewModelIDKey : @(RQVIPPageType_Alert),
  59. RQViewModelUtilKey : typeModels,
  60. RQViewCommonValueKey : @(subject),
  61. }];
  62. RQVipViewController *vipViewController = [[RQVipViewController alloc] initWithViewModel:vipViewModel];
  63. [RQControllerHelper.topViewController presentPanModal:vipViewController];
  64. } error:^(NSError * _Nullable error) {
  65. [MBProgressHUD rq_hideHUD];
  66. [MBProgressHUD rq_showErrorTips:error];
  67. }];
  68. }
  69. }
  70. - (void)gotoVipViewWithDictType:(NSString *)dictType {
  71. [self gotoVipViewWithDictType:dictType subject:RQ_YDTQuestion_Module.subject];
  72. }
  73. - (void)gotoVipViewWithDictType:(NSString *)dictType subject:(RQHomePageSubjectType)subject {
  74. if (RQ_USER_MANAGER.isShouldLogin) {
  75. [MBProgressHUD rq_showProgressHUD:@"获取VIP套餐..."];
  76. [[RQ_HTTP_Service getTypeWithDictType:dictType] subscribeNext:^(NSArray *typeModels) {
  77. [MBProgressHUD rq_hideHUD];
  78. if(subject>4){
  79. NYLIVipCoachViewModel *livipCoachViewModel = [[NYLIVipCoachViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  80. RQViewModelIDKey : @(RQVIPPageType_Full),
  81. RQViewModelUtilKey : typeModels,
  82. RQViewCommonValueKey : @(subject),
  83. }];
  84. [RQ_APPDELEGATE.services pushViewModel:livipCoachViewModel animated:YES];
  85. }else{
  86. [RQ_APPDELEGATE.services pushViewModel:[[RQVipViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  87. RQViewModelIDKey : @(RQVIPPageType_Full),
  88. RQViewModelUtilKey : typeModels,
  89. RQViewCommonValueKey : @(subject),
  90. }] animated:YES];
  91. }
  92. } error:^(NSError * _Nullable error) {
  93. [MBProgressHUD rq_hideHUD];
  94. [MBProgressHUD rq_showErrorTips:error];
  95. }];
  96. }
  97. }
  98. - (void)gotoVipCenter {
  99. [self gotoVipCenterWithSubject:RQ_YDTQuestion_Module.subject];
  100. }
  101. - (void)gotoVipCenterWithSubject:(RQHomePageSubjectType)subject {
  102. @weakify(self)
  103. [RQ_VIP_Module isActiveWithCcomplete:^(RQActivationModel * _Nullable activationModel, BOOL isSuccess) {
  104. @strongify(self)
  105. if (isSuccess) {
  106. if (activationModel.isShare) {
  107. [self gotoVipCenterWithDictType:RQ_USER_MANAGER.currentUser.city subject:subject];
  108. } else {
  109. // NSString *typeStr = subject > 4? @"vip_coach_package": @"vip_package";
  110. NSString *typeStr = @"vip_package";
  111. [self gotoVipCenterWithDictType:typeStr subject:subject];
  112. }
  113. }
  114. }];
  115. }
  116. - (void)gotoVipCenterWithDictType:(NSString *)dictType subject:(RQHomePageSubjectType)subject {
  117. if (RQ_USER_MANAGER.isShouldLogin) {
  118. [MBProgressHUD rq_showProgressHUD:@"获取VIP套餐..."];
  119. [[RQ_HTTP_Service getTypeWithDictType:dictType] subscribeNext:^(NSArray *typeModels) {
  120. [MBProgressHUD rq_hideHUD];
  121. // if(subject>4){
  122. // NYLIVipCoachViewModel *livipCoachViewModel = [[NYLIVipCoachViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  123. // RQViewModelIDKey : @(RQVIPPageType_Full),
  124. // RQViewModelUtilKey : typeModels,
  125. // RQViewCommonValueKey : @(subject),
  126. // }];
  127. // [RQ_APPDELEGATE.services pushViewModel:livipCoachViewModel animated:YES];
  128. // }else{
  129. RQVipCenterViewModel *vipCenterViewModel = [[RQVipCenterViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  130. RQViewModelUtilKey : [typeModels isKindOfClass:[NSArray class]]? typeModels : @[],
  131. RQViewCommonValueKey : @(subject),
  132. }];
  133. [RQ_APPDELEGATE.services pushViewModel:vipCenterViewModel animated:YES];
  134. // }
  135. } error:^(NSError * _Nullable error) {
  136. [MBProgressHUD rq_hideHUD];
  137. [MBProgressHUD rq_showErrorTips:error];
  138. }];
  139. }
  140. }
  141. //vip处理
  142. - (void)isVipWithSubjectDto:(NSInteger)subject complete:(VoidBlock_Bool)complete {
  143. if (RQ_USER_MANAGER.isShouldLogin) {
  144. __block BOOL isVerify;
  145. [[RQ_HTTP_Service getVideoVipWithUserId:RQ_USER_MANAGER.currentUser._id] subscribeNext:^(RQVideoVipModel *videoVipModel) {
  146. //rsa 公钥
  147. NSString *publicKey = [NSString stringWithFormat:@"%@%@%@",@"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCzR04LMmDlwyVRfK+Kgsm/vFMOFyqvGk4QIVC",@"Gj2CKKfhycRExm15N3tKOOouIjl/EU79It45oS+ltJkscvYrJn1zz+1bSoBLelZzJrn7K0NpHF8k", @"bCprsFHd60x+YJ4l8C3SDxfFebo4kqveJzx6JNZKwzFm7LPEO5XB9pEBRwIDAQAB"];
  148. // 构造被签名串
  149. NSMutableString *mutableVerifyString = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:@"%ld",videoVipModel.userId]];
  150. if (RQStringIsNotEmpty(videoVipModel.subject1)) {
  151. [mutableVerifyString appendFormat:@"%ld",[RQ_SHARE_FUNCTION getTimeStampWithTimeStr:videoVipModel.subject1 formatter:@"yyyy-MM-dd HH:mm:ss"]];
  152. }
  153. if (RQStringIsNotEmpty(videoVipModel.subject2)) {
  154. [mutableVerifyString appendFormat:@"%ld",[RQ_SHARE_FUNCTION getTimeStampWithTimeStr:videoVipModel.subject2 formatter:@"yyyy-MM-dd HH:mm:ss"]];
  155. }
  156. if (RQStringIsNotEmpty(videoVipModel.subject3)) {
  157. [mutableVerifyString appendFormat:@"%ld",[RQ_SHARE_FUNCTION getTimeStampWithTimeStr:videoVipModel.subject3 formatter:@"yyyy-MM-dd HH:mm:ss"]];
  158. }
  159. if (RQStringIsNotEmpty(videoVipModel.subject4)) {
  160. [mutableVerifyString appendFormat:@"%ld",[RQ_SHARE_FUNCTION getTimeStampWithTimeStr:videoVipModel.subject4 formatter:@"yyyy-MM-dd HH:mm:ss"]];
  161. }
  162. [mutableVerifyString appendFormat:@"%ld",videoVipModel.subject1Int];
  163. [mutableVerifyString appendFormat:@"%ld",videoVipModel.subject2Int];
  164. [mutableVerifyString appendFormat:@"%ld",videoVipModel.subject3Int];
  165. [mutableVerifyString appendFormat:@"%ld",videoVipModel.subject4Int];
  166. if (RQStringIsNotEmpty(videoVipModel.spSubject1)) {
  167. [mutableVerifyString appendFormat:@"%ld",[RQ_SHARE_FUNCTION getTimeStampWithTimeStr:videoVipModel.spSubject1 formatter:@"yyyy-MM-dd HH:mm:ss"]];
  168. }
  169. if (RQStringIsNotEmpty(videoVipModel.spSubject4)) {
  170. [mutableVerifyString appendFormat:@"%ld",[RQ_SHARE_FUNCTION getTimeStampWithTimeStr:videoVipModel.spSubject4 formatter:@"yyyy-MM-dd HH:mm:ss"]];
  171. }
  172. [mutableVerifyString appendFormat:@"%ld",videoVipModel.spSubject1Int];
  173. [mutableVerifyString appendFormat:@"%ld",videoVipModel.spSubject4Int];
  174. //公钥验签
  175. isVerify = [self verify:mutableVerifyString.copy signature:RQStringIsNotEmpty(videoVipModel.sign)? videoVipModel.sign : @"" withPublivKey:publicKey];
  176. NSLog(@"验签通过了吧------%@", isVerify ? @"YES":@"NO");
  177. if (complete) {
  178. BOOL result;
  179. RQ_VIP_Module.isSubject1Vip = videoVipModel.subject1Int;
  180. RQ_VIP_Module.isSubject2Vip = videoVipModel.subject2Int;
  181. RQ_VIP_Module.isSubject3Vip = videoVipModel.subject3Int;
  182. RQ_VIP_Module.isSubject4Vip = videoVipModel.subject4Int;
  183. RQ_VIP_Module.isSubjectAllVip = RQ_VIP_Module.isSubject1Vip && RQ_VIP_Module.isSubject2Vip && RQ_VIP_Module.isSubject3Vip && RQ_VIP_Module.isSubject4Vip;
  184. self.videoVipModel = videoVipModel;
  185. RQ_VIP_Module.isSpSubject1Vip = videoVipModel.spSubject1Int;
  186. RQ_VIP_Module.isSpSubject4Vip = videoVipModel.spSubject4Int;
  187. RQ_VIP_Module.isSpSubjectAllVip = RQ_VIP_Module.isSpSubject1Vip && RQ_VIP_Module.isSpSubject4Vip;
  188. NSInteger isAds = 0;
  189. if (subject == 1) {
  190. isAds ++;
  191. result = isVerify? RQ_VIP_Module.isSubject1Vip : NO;
  192. } else if (subject == 2) {
  193. isAds ++;
  194. result = isVerify? RQ_VIP_Module.isSubject2Vip : NO;
  195. } else if (subject == 3) {
  196. isAds ++;
  197. result = isVerify? RQ_VIP_Module.isSubject3Vip : NO;
  198. } else if (subject == 4) {
  199. isAds ++;
  200. result = isVerify? RQ_VIP_Module.isSubject4Vip : NO;
  201. } else if (subject == 5) {//1-4全
  202. isAds ++;
  203. result = isVerify? RQ_VIP_Module.isSubjectAllVip : NO;
  204. } else if (subject == 6) { //科一特
  205. isAds ++;
  206. result = isVerify? RQ_VIP_Module.isSpSubject1Vip : NO;
  207. } else if (subject == 7) { //科四特
  208. isAds ++;
  209. result = isVerify? RQ_VIP_Module.isSpSubject4Vip : NO;
  210. } else {
  211. result = isVerify? (RQ_VIP_Module.isSubject1Vip || RQ_VIP_Module.isSubject2Vip || RQ_VIP_Module.isSubject3Vip || RQ_VIP_Module.isSubject4Vip
  212. ||RQ_VIP_Module.isSpSubject1Vip || RQ_VIP_Module.isSpSubject4Vip) : NO;
  213. }
  214. RQ_VIP_Module.isADVip = (isAds >=2);
  215. RQ_VIP_Module.isVip = result;
  216. // complete(result? result : (RQ_COMMON_MANAGER.APP_SWITCH? YES : NO));
  217. complete(result? result :NO);
  218. }
  219. } error:^(NSError * _Nullable error) {
  220. [MBProgressHUD rq_showErrorTips:error];
  221. if (complete) {
  222. RQ_VIP_Module.isSubject1Vip = NO;
  223. RQ_VIP_Module.isSubject2Vip = NO;
  224. RQ_VIP_Module.isSubject3Vip = NO;
  225. RQ_VIP_Module.isSubject4Vip = NO;
  226. RQ_VIP_Module.isSubject4Vip = NO;
  227. RQ_VIP_Module.isSpSubject1Vip = NO;
  228. RQ_VIP_Module.isSpSubject4Vip = NO;
  229. RQ_VIP_Module.isSubjectAllVip = NO;
  230. RQ_VIP_Module.isSpSubjectAllVip = NO;
  231. RQ_VIP_Module.isVip = NO;
  232. RQ_VIP_Module.isADVip = NO;
  233. self.videoVipModel = nil;
  234. complete(NO);
  235. }
  236. }];
  237. } else {
  238. if (complete) {
  239. RQ_VIP_Module.isSubject1Vip = NO;
  240. RQ_VIP_Module.isSubject2Vip = NO;
  241. RQ_VIP_Module.isSubject3Vip = NO;
  242. RQ_VIP_Module.isSubject4Vip = NO;
  243. RQ_VIP_Module.isSpSubject1Vip = NO;
  244. RQ_VIP_Module.isSpSubject4Vip = NO;
  245. RQ_VIP_Module.isSubjectAllVip = NO;
  246. RQ_VIP_Module.isSpSubjectAllVip = NO;
  247. RQ_VIP_Module.isVip = NO;
  248. RQ_VIP_Module.isADVip = NO;
  249. self.videoVipModel = nil;
  250. complete(NO);
  251. }
  252. }
  253. }
  254. /// 是否Vip
  255. - (void)isVipWithSubject:(NSInteger)subject complete:(VoidBlock_Bool)complete {
  256. if( RQ_COMMON_MANAGER.APP_SWITCH && !RQ_USER_MANAGER.isLogin ){//审核时提示 - v2.1.1
  257. [RQ_SHARE_FUNCTION showAlertWithTitle:@"提示" message:@"使用计时平台账号登录极速驾培,可享受跨平台使用权益,直接购买只会绑定当前设备" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"登录账号购买(推荐)",@"游客登录"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  258. if (selectedOtherButtonIndex == 0) { //登录账号
  259. if(RQ_USER_MANAGER.isShouldLogin){
  260. NSLog(@"跳转登录");
  261. }
  262. }else if (selectedOtherButtonIndex == 1) {//游客登录
  263. NSString *deviceidStr = [SAMKeychain deviceId];
  264. NSArray *components = [deviceidStr componentsSeparatedByString:@"-"];
  265. NSString *logincode = [components lastObject];
  266. [MBProgressHUD rq_showProgressHUD:@""];
  267. [[RQ_HTTP_Service getAppleUserInfo:logincode] subscribeNext:^(RQUserModel *userModel) {
  268. [MBProgressHUD rq_hideHUD];
  269. if(userModel){
  270. userModel.nickName = userModel.userName;
  271. /// 存储用户数据nickName
  272. [RQ_USER_MANAGER loginUser:userModel];
  273. if (userModel.channel == RQUserLoginChannelTypePhone) {
  274. /// 切换更控制器
  275. dispatch_async(dispatch_get_main_queue(), ^{
  276. /// 发通知
  277. [[NSNotificationCenter defaultCenter] postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeLogin)}];
  278. });
  279. }
  280. [MBProgressHUD rq_showTips:@"登录成功"];
  281. }
  282. } error:^(NSError * _Nullable error) {
  283. [MBProgressHUD rq_hideHUD];
  284. [MBProgressHUD rq_showTips:error.description];
  285. } completed:^{
  286. }];
  287. }
  288. NSLog(@"index=%zd",selectedOtherButtonIndex);
  289. }];
  290. } else {
  291. [self isVipWithSubjectDto:subject complete:complete];
  292. }
  293. }
  294. - (void)isActiveWithCcomplete:(RQGetActivationModelBlock)complete {
  295. if (RQ_USER_MANAGER.isShouldLogin) {
  296. if([RQ_USER_MANAGER.currentUser.userName containsString:@"游客"]){//游客特殊处理
  297. if (complete) {
  298. self.activationModel = [[RQActivationModel alloc] init];
  299. self.activationModel.isActive = 1;
  300. self.activationModel.isShare = 0;
  301. self.activationModel.userId = RQ_USER_MANAGER.currentUser._id.intValue;
  302. if (!RQObjectIsNil(self.activationModel)) {
  303. if ([self.activationModel isKindOfClass:[RQActivationModel class]]) {
  304. complete(self.activationModel, YES);
  305. } else {
  306. [MBProgressHUD rq_showTips:@"获取激活信息失败"];
  307. complete(self.activationModel, NO);
  308. }
  309. } else {
  310. [MBProgressHUD rq_showTips:@"获取激活信息失败"];
  311. complete(self.activationModel, NO);
  312. }
  313. }
  314. return;
  315. }
  316. [[RQ_HTTP_Service getActivationWithUserId:RQ_USER_MANAGER.currentUser._id] subscribeNext:^(RQActivationModel *activationModel) {
  317. if (complete) {
  318. self.activationModel = activationModel;
  319. if (!RQObjectIsNil(self.activationModel)) {
  320. if ([self.activationModel isKindOfClass:[RQActivationModel class]]) {
  321. complete(self.activationModel, YES);
  322. } else {
  323. [MBProgressHUD rq_showTips:@"获取激活信息失败"];
  324. complete(self.activationModel, NO);
  325. }
  326. } else {
  327. [MBProgressHUD rq_showTips:@"获取激活信息失败"];
  328. complete(self.activationModel, NO);
  329. }
  330. }
  331. } error:^(NSError * _Nullable error) {
  332. [MBProgressHUD rq_showErrorTips:error];
  333. if (complete) {
  334. self.activationModel = nil;
  335. complete(self.activationModel, NO);
  336. }
  337. }];
  338. } else {
  339. if (complete) {
  340. self.activationModel = nil;
  341. complete(self.activationModel, NO);
  342. }
  343. }
  344. }
  345. #pragma mark - PrivateMethods
  346. // verify Signature
  347. - (BOOL)verify:(NSString *)content signature:(NSString *)signature withPublivKey:(NSString *)publicKey {
  348. SecKeyRef publicKeyRef = [self addPublicKey:publicKey];
  349. if (!publicKeyRef) { NSLog(@"添加公钥失败"); return NO; }
  350. NSData *originData = [self sha256:content];
  351. NSData *signatureData = [[NSData alloc] initWithBase64EncodedString:signature options:NSDataBase64DecodingIgnoreUnknownCharacters];
  352. if (!originData || !signatureData) { return NO; }
  353. OSStatus status = SecKeyRawVerify(publicKeyRef, kSecPaddingPKCS1SHA256, [originData bytes], originData.length, [signatureData bytes], signatureData.length);
  354. if (status ==noErr) { return YES; }
  355. else{ NSLog(@"验签失败:%d",status); return NO; }
  356. }
  357. // digest message with sha1
  358. - (NSData *)sha256:(NSString *)str {
  359. const void *data = [str cStringUsingEncoding:NSUTF8StringEncoding];
  360. CC_LONG len = (CC_LONG)strlen(data);
  361. uint8_t * md = malloc( CC_SHA256_DIGEST_LENGTH * sizeof(uint8_t) );;
  362. CC_SHA256(data, len, md);
  363. return [NSData dataWithBytes:md length:CC_SHA256_DIGEST_LENGTH];
  364. }
  365. - (SecKeyRef)addPublicKey:(NSString *)pubKey {
  366. NSData *data = [[NSData alloc] initWithBase64EncodedString:pubKey options:NSDataBase64DecodingIgnoreUnknownCharacters];
  367. //a tag to read/write keychain storage
  368. NSString *tag = @"RSA_PUBLIC_KEY";
  369. NSData *d_tag = [NSData dataWithBytes:[tag UTF8String] length:[tag length]];
  370. // Delete any old lingering key with the same tag
  371. NSMutableDictionary *publicKey = [[NSMutableDictionary alloc] init];
  372. [publicKey setObject:(__bridge id) kSecClassKey forKey:(__bridge id)kSecClass];
  373. [publicKey setObject:(__bridge id) kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType];
  374. [publicKey setObject:d_tag forKey:(__bridge id)kSecAttrApplicationTag];
  375. SecItemDelete((__bridge CFDictionaryRef)publicKey);
  376. // Add persistent version of the key to system keychain
  377. [publicKey setObject:data forKey:(__bridge id)kSecValueData];
  378. [publicKey setObject:(__bridge id) kSecAttrKeyClassPublic forKey:(__bridge id)kSecAttrKeyClass];
  379. [publicKey setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id)kSecReturnPersistentRef];
  380. CFTypeRef persistKey = nil;
  381. OSStatus status = SecItemAdd((__bridge CFDictionaryRef)publicKey, &persistKey);
  382. if (persistKey != nil){
  383. CFRelease(persistKey);
  384. }
  385. if ((status != noErr) && (status != errSecDuplicateItem)) { return nil; }
  386. [publicKey removeObjectForKey:(__bridge id)kSecValueData];
  387. [publicKey removeObjectForKey:(__bridge id)kSecReturnPersistentRef];
  388. [publicKey setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id)kSecReturnRef];
  389. [publicKey setObject:(__bridge id) kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType];
  390. // Now fetch the SecKeyRef version of the key
  391. SecKeyRef keyRef = nil;
  392. status = SecItemCopyMatching((__bridge CFDictionaryRef)publicKey, (CFTypeRef *)&keyRef);
  393. if(status != noErr){
  394. return nil;
  395. }
  396. return keyRef;
  397. }
  398. - (BOOL)isVip {
  399. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"isVip"];
  400. if (RQObjectIsNil(object)) {
  401. return NO;
  402. } else {
  403. BOOL isVip = [object boolValue];
  404. return isVip;
  405. }
  406. }
  407. - (void)setIsVip:(BOOL)isVip {
  408. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithBool:isVip] ForKey:@"isVip"];
  409. }
  410. - (BOOL)isADVip {
  411. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"isADVip"];
  412. if (RQObjectIsNil(object)) {
  413. return NO;
  414. } else {
  415. BOOL isADVip = [object boolValue];
  416. return isADVip;
  417. }
  418. }
  419. - (void)setIsADVip:(BOOL)isADVip {
  420. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithBool:isADVip] ForKey:@"isADVip"];
  421. }
  422. - (BOOL)isSubject1Vip {
  423. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"isSubject1Vip"];
  424. if (RQObjectIsNil(object)) {
  425. return NO;
  426. } else {
  427. BOOL isSubject1Vip = [object boolValue];
  428. return isSubject1Vip;
  429. }
  430. }
  431. - (void)setIsSubject1Vip:(BOOL)isSubject1Vip {
  432. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithBool:isSubject1Vip] ForKey:@"isSubject1Vip"];
  433. }
  434. - (BOOL)isSubject2Vip {
  435. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"isSubject2Vip"];
  436. if (RQObjectIsNil(object)) {
  437. return NO;
  438. } else {
  439. BOOL isSubject2Vip = [object boolValue];
  440. return isSubject2Vip;
  441. }
  442. }
  443. - (void)setIsSubject2Vip:(BOOL)isSubject2Vip {
  444. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithBool:isSubject2Vip] ForKey:@"isSubject2Vip"];
  445. }
  446. - (BOOL)isSubject3Vip {
  447. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"isSubject3Vip"];
  448. if (RQObjectIsNil(object)) {
  449. return NO;
  450. } else {
  451. BOOL isSubject3Vip = [object boolValue];
  452. return isSubject3Vip;
  453. }
  454. }
  455. - (void)setIsSubject3Vip:(BOOL)isSubject3Vip {
  456. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithBool:isSubject3Vip] ForKey:@"isSubject3Vip"];
  457. }
  458. - (BOOL)isSubject4Vip {
  459. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"isSubject4Vip"];
  460. if (RQObjectIsNil(object)) {
  461. return NO;
  462. } else {
  463. BOOL isSubject4Vip = [object boolValue];
  464. return isSubject4Vip;
  465. }
  466. }
  467. - (void)setIsSubject4Vip:(BOOL)isSubject4Vip {
  468. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithBool:isSubject4Vip] ForKey:@"isSubject4Vip"];
  469. }
  470. - (BOOL)isSpSubject1Vip {
  471. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"isSpSubject1Vip"];
  472. if (RQObjectIsNil(object)) {
  473. return NO;
  474. } else {
  475. BOOL isSpSubject1Vip = [object boolValue];
  476. return isSpSubject1Vip;
  477. }
  478. }
  479. - (void)setIsSpSubject1Vip:(BOOL)isSpSubject1Vip {
  480. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithBool:isSpSubject1Vip] ForKey:@"isSpSubject1Vip"];
  481. }
  482. - (BOOL)isSpSubject4Vip {
  483. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"isSpSubject4Vip"];
  484. if (RQObjectIsNil(object)) {
  485. return NO;
  486. } else {
  487. BOOL isSpSubject4Vip = [object boolValue];
  488. return isSpSubject4Vip;
  489. }
  490. }
  491. - (void)setIsSpSubject4Vip:(BOOL)isSpSubject4Vip {
  492. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithBool:isSpSubject4Vip] ForKey:@"isSpSubject4Vip"];
  493. }
  494. - (BOOL)isSubjectAllVip {
  495. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"isSubjectAllVip"];
  496. if (RQObjectIsNil(object)) {
  497. return NO;
  498. } else {
  499. BOOL isSubjectAllVip = [object boolValue];
  500. return isSubjectAllVip;
  501. }
  502. }
  503. - (void)setIsSubjectAllVip:(BOOL)isSubjectAllVip {
  504. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithBool:isSubjectAllVip] ForKey:@"isSubjectAllVip"];
  505. }
  506. - (BOOL)isSpSubjectAllVip {
  507. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"isSpSubjectAllVip"];
  508. if (RQObjectIsNil(object)) {
  509. return NO;
  510. } else {
  511. BOOL isSubjectAllVip = [object boolValue];
  512. return isSubjectAllVip;
  513. }
  514. }
  515. - (void)setIsSpSubjectAllVip:(BOOL)isSubjectAllVip {
  516. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithBool:isSubjectAllVip] ForKey:@"isSpSubjectAllVip"];
  517. }
  518. - (NSUInteger)freeLookSimExamNum {
  519. id object = [RQ_COMMON_MANAGER getObjectWithKey:@"freeLookSimExamNum"];
  520. if (RQObjectIsNil(object)) {
  521. return NO;
  522. } else {
  523. NSInteger freeLookSimExamNum = [object integerValue];
  524. return freeLookSimExamNum;
  525. }
  526. }
  527. - (void)setFreeLookSimExamNum:(NSUInteger)freeLookSimExamNum {
  528. [RQ_COMMON_MANAGER saveObjectWithObject:[NSNumber numberWithInteger:freeLookSimExamNum] ForKey:@"freeLookSimExamNum"];
  529. }
  530. @end