VerificationManager.h 5.9 KB

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