VerificationManager.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // VerificationManager.h
  3. // Filmage Screen
  4. //
  5. // Version 1.0.1
  6. //
  7. // Created by 朱东勇 on 2018/2/8.
  8. // Copyright © 2018年 kdan mobile. All rights reserved.
  9. //
  10. #import <Foundation/Foundation.h>
  11. //#import "ASIFormDataRequest.h"
  12. //#import "JSONKit.h"
  13. #define kTestMode 0
  14. #if kTestMode
  15. #define kVerificationServer @"http://test-store.kdan.cn:3018/"
  16. #define kWebServerLink NSLocalizedString(@"http://test-pdf-pro.kdan.cn:3021", nil)
  17. #define kAIStoreServerLink @"http://test-pdf-pro.kdan.cn:3021/ai-pdf"
  18. #else
  19. #define kVerificationServer @"https://store.pdfreaderpro.com/"
  20. #define kWebServerLink NSLocalizedString(@"http://www.pdfreaderpro.com/store", nil)
  21. #define kAIStoreServerLink @"https://www.pdfreaderpro.com/ai-pdf"
  22. #endif
  23. #define kFetchLicenseCodeString [NSString stringWithFormat:@"%@/%@", kWebServerLink, @"store"]
  24. #define kLicenseRetrievalCodeString [NSString stringWithFormat:@"%@/%@", kWebServerLink, @"license_retrieval"]
  25. #define kFAQString [NSString stringWithFormat:@"%@/%@", kWebServerLink, @"faq"]
  26. #define kCheckUpdateURLString [NSString stringWithFormat:@"%@api/auth_devices/latest_version?lang=en&app_code=%@", kVerificationServer, [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"]?:@""]
  27. #define kFetchSysConfigInfoString [NSString stringWithFormat:@"%@/%@", kVerificationServer, @"api/sys_configs"]
  28. ///激活
  29. typedef enum {
  30. ActivityErrorTypeCDKeyEmpty,//CD Key为空
  31. ActivityErrorTypeCDKeyNotExist,//CD Key不存在
  32. ActivityErrorTypeNetworkDisable,//网络不可用
  33. ActivityErrorTypeOutNumber,//CD Key超出绑定数量,被其他设备使用
  34. ActivityErrorTypeCDKeyExpire,//序列码过期
  35. ActivityErrorTypeInvalidInfo,//激活错误,联系我们或查看FAQ
  36. ActivityErrorTypeNotMatchProduct,//CDkey是其他产品的
  37. ActivityErrorTypeFormatError,//格式错误
  38. ActivityErrorTypeUnknow,//未知错误
  39. }ActivityErrorType;
  40. typedef enum {
  41. ActivityStatusNone,
  42. ActivityStatusTrial, //试用
  43. ActivityStatusVerification, //激活
  44. ActivityStatusTrialExpire, //试用过期
  45. ActivityStatusVerifExpire, //过期
  46. ActivityStatusLicenseExpire,//序列号过期
  47. }ActivityStatus;
  48. typedef void(^ActivityComplention)(ActivityStatus status, NSDictionary *info, NSError *error);
  49. @interface VerificationManager : NSObject
  50. @property (nonatomic) BOOL autoVerification; //激活码定期自动校验,默认隔一小时校验一次
  51. @property (nonatomic, readonly) ActivityStatus status;
  52. @property (nonatomic, readonly) BOOL needUpgradeLicense;
  53. @property (nonatomic, readonly) NSString *licenseCode;
  54. @property (nonatomic, readonly) NSDictionary *detailInfo;
  55. @property (nonatomic, readonly) BOOL secondTrialEnabled;
  56. @property (nonatomic, readonly) NSInteger trialTimes;
  57. @property (nonatomic, readonly) NSString *email;
  58. @property (nonatomic, readonly) NSString *accountName;
  59. + (VerificationManager *)manager;
  60. + (VerificationManager *)defaultManager;
  61. + (NSMutableData*)mutableDataWithDic:(NSDictionary*)dic;
  62. ///** 跳转到 Built to Connect 官网商城购买界面,各App可自行跳转到对应激活购买界面
  63. // */
  64. //- (void)fetchVerificationCode;
  65. /** 激活设备
  66. @params info
  67. email 用户Email,可选
  68. cdkey 用户用于激活设备的激活码,必选
  69. */
  70. - (void)activateDeviceWithInfo:(NSDictionary*)info
  71. complention:(ActivityComplention)complention;
  72. /** 验证设备信息
  73. */
  74. - (void)verificationWithComplention:(ActivityComplention)complention;
  75. /** 提交试用
  76. @param days 申请试用天数,由App端指定,Server端会限定最大试用天数
  77. @param email option, 申请人Email信息
  78. */
  79. - (void)trialForDays:(float)days
  80. email:(NSString*)email
  81. name:(NSString*)name
  82. complention:(ActivityComplention)complention;
  83. - (void)trialForDays:(float)days
  84. complention:(ActivityComplention)complention;
  85. /** 邀请部分
  86. @param email 当前App使用的email 地址,用于接由试用体验邮件
  87. */
  88. - (void)getCodeWithEmail:(NSString*)email
  89. complention:(ActivityComplention)complention;
  90. /** 使用好友的邀请码
  91. */
  92. - (void)userCode:(NSString*)code
  93. complention:(ActivityComplention)complention;
  94. /** 修改用户email
  95. */
  96. - (void)modifyEmail:(NSString*)email
  97. complention:(ActivityComplention)complention;
  98. /** 给好友发送邀请email, 多个email 使用 , 号分隔
  99. */
  100. - (void)sendInvateEmails:(NSString*)emails
  101. code:(NSString*)code
  102. complention:(ActivityComplention)complention;
  103. @end
  104. #pragma mark - Data Parse
  105. @interface NSDictionary (ActivityInfo)
  106. @property (nonatomic, readonly) ActivityStatus status;
  107. @property (nonatomic, readonly) NSDate *createDate;
  108. @property (nonatomic, readonly) NSDate *expireDate;
  109. @property (nonatomic, readonly) NSString *licenseCode;
  110. @property (nonatomic, readonly) NSString *shareCode;
  111. @property (nonatomic, readonly) NSUInteger invateUsersCount;
  112. @property (nonatomic, readonly) NSDate *fetchInvateDate;
  113. @property (nonatomic, readonly) NSString *fromCode;
  114. @property (nonatomic, readonly) NSUInteger maxFreeDays;
  115. @property (nonatomic, readonly) BOOL repeatTrial;
  116. @property (nonatomic, readonly) NSString *email;
  117. @property (nonatomic, readonly) NSString *accountName;
  118. @property (nonatomic, readonly) NSUInteger trialTimes;
  119. @end
  120. #if DEBUG
  121. @interface VerificationManager (Test)
  122. - (void)updateVerificationStatus;
  123. - (void)updateStatus:(ActivityStatus)status postNo:(bool)postNo;
  124. @end
  125. #endif
  126. /// Notification
  127. extern NSString *kDeviceVerifyFinishNotification;//调用验证接口结束后发送通知
  128. extern NSString *kDeviceActivateStatusChangeNotification;