|
@@ -205,26 +205,26 @@ static VerificationManager *__verificationManager = nil;
|
|
|
#pragma mark - Interface
|
|
|
- (void)activateDeviceWithInfo:(NSDictionary*)info
|
|
|
complention:(ActivityComplention)complention {
|
|
|
- if (![info[@"cdkey"] length]) {
|
|
|
- //激活码为空
|
|
|
- NSError *error = [NSError errorWithDomain:@""
|
|
|
- code:ActivityErrorTypeCDKeyEmpty
|
|
|
- userInfo:nil];
|
|
|
- if (complention)
|
|
|
- complention(NO, nil, error);
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
- if (![self isValidLicenseCode:info[@"cdkey"]]) {
|
|
|
- //激活码格式不正确
|
|
|
- NSError *error = [NSError errorWithDomain:@"激活失败"
|
|
|
- code:ActivityErrorTypeFormatError
|
|
|
- userInfo:nil];
|
|
|
- if (complention)
|
|
|
- complention(NO, @{@"errors":@"FormatError"}, error);
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
+// if (![info[@"cdkey"] length]) {
|
|
|
+// //激活码为空
|
|
|
+// NSError *error = [NSError errorWithDomain:@""
|
|
|
+// code:ActivityErrorTypeCDKeyEmpty
|
|
|
+// userInfo:nil];
|
|
|
+// if (complention)
|
|
|
+// complention(NO, nil, error);
|
|
|
+//
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// if (![self isValidLicenseCode:info[@"cdkey"]]) {
|
|
|
+// //激活码格式不正确
|
|
|
+// NSError *error = [NSError errorWithDomain:@"激活失败"
|
|
|
+// code:ActivityErrorTypeFormatError
|
|
|
+// userInfo:nil];
|
|
|
+// if (complention)
|
|
|
+// complention(NO, @{@"errors":@"FormatError"}, error);
|
|
|
+//
|
|
|
+// return;
|
|
|
+// }
|
|
|
|
|
|
__block ActivityComplention tComplention = complention;
|
|
|
__block VerificationManager *weak_self = self;
|
|
@@ -240,7 +240,7 @@ static VerificationManager *__verificationManager = nil;
|
|
|
@"subscription":@{
|
|
|
@"app_code":[self bundleIdentify]?:@"",
|
|
|
@"email":info[@"email"]?:@"",
|
|
|
- @"cdkey":info[@"cdkey"]?:@"",
|
|
|
+// @"cdkey":info[@"cdkey"]?:@"",
|
|
|
},
|
|
|
//设备信息
|
|
|
@"device":@{
|
|
@@ -265,7 +265,7 @@ static VerificationManager *__verificationManager = nil;
|
|
|
// }
|
|
|
|
|
|
NSString *verifyString = [self.rsa activeWithUniquesn:uuid
|
|
|
- cdkey:info[@"cdkey"]?:@""
|
|
|
+ cdkey:info[@"email"]?:@""
|
|
|
model:GetProductName()?:@""
|
|
|
os:GetSystemVersion()?:@""
|
|
|
language:[[NSLocale currentLocale] localeIdentifier]?:@""
|
|
@@ -622,6 +622,155 @@ static VerificationManager *__verificationManager = nil;
|
|
|
[request startAsynchronous];
|
|
|
}
|
|
|
|
|
|
+- (void)unactivateDeviceWithcomplention:(ActivityComplention)complention {
|
|
|
+ __block ActivityComplention tComplention = complention;
|
|
|
+ __block VerificationManager *weak_self = self;
|
|
|
+
|
|
|
+ //Process Params
|
|
|
+ NSString *app_version = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] description];
|
|
|
+ if (!app_version.length)
|
|
|
+ app_version = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] description];
|
|
|
+ NSDictionary *params =
|
|
|
+ @{
|
|
|
+ @"data":@{
|
|
|
+ //激活信息
|
|
|
+ @"subscription":@{
|
|
|
+ @"app_code":[self bundleIdentify]?:@"",
|
|
|
+ },
|
|
|
+ //设备信息
|
|
|
+ @"device":@{
|
|
|
+ @"unique_sn":[self udid]?:@"",
|
|
|
+ @"model":GetProductName()?:@"",
|
|
|
+ @"os":GetSystemVersion()?:@"",
|
|
|
+ @"time_zone":[[NSTimeZone localTimeZone] localizedName:NSTimeZoneNameStyleShortDaylightSaving locale:[NSLocale currentLocale]]?:@"",
|
|
|
+ @"language":[[NSLocale currentLocale] localeIdentifier]?:@"",
|
|
|
+ @"app_version":app_version?:@"",
|
|
|
+ @"platform":@"DMG"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ if (!self.rsa) {
|
|
|
+ self.rsa = [[KMVerificationRSA alloc] init];
|
|
|
+ }
|
|
|
+ NSString *uuid = [self udid]?:@"";
|
|
|
+// if (uuid.length > @"8D397BE0-F478-5269-A8F1".length) {
|
|
|
+// uuid = [uuid substringToIndex:@"8D397BE0-F478-5269-A8F1".length];
|
|
|
+// }
|
|
|
+
|
|
|
+ NSString *verifyString = [self.rsa activeWithUniquesn:uuid
|
|
|
+ cdkey:@""
|
|
|
+ model:GetProductName()?:@""
|
|
|
+ os:GetSystemVersion()?:@""
|
|
|
+ language:[[NSLocale currentLocale] localeIdentifier]?:@""
|
|
|
+ appversion:app_version?:@""];
|
|
|
+
|
|
|
+ if (verifyString.length == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ params = @{@"verifyParam":verifyString};
|
|
|
+
|
|
|
+ NSMutableData *postData = [VerificationManager mutableDataWithDic:params];
|
|
|
+
|
|
|
+ //Send Request
|
|
|
+ NSString *urlString = [kVerificationPDFullServer stringByAppendingString:@"/oem/cancel"];
|
|
|
+
|
|
|
+
|
|
|
+ NSURL *url = [NSURL URLWithString:urlString];
|
|
|
+ ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
+
|
|
|
+ request.requestMethod = @"POST";
|
|
|
+ [request setPostBody:postData];
|
|
|
+ NSString *postLength = [NSString stringWithFormat:@"%ld", (unsigned long)[postData length]];
|
|
|
+ NSMutableDictionary *requestHeaders = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
+ postLength, @"Content-Length", nil];
|
|
|
+ request.defaultResponseEncoding = NSUTF8StringEncoding;
|
|
|
+ // [request setAuthenticationScheme:@"https"];//设置验证方式
|
|
|
+// [request setValidatesSecureCertificate:NO];//设置验证证书
|
|
|
+
|
|
|
+ [request setRequestHeaders:requestHeaders];
|
|
|
+ [request addRequestHeader:@"Content-Type" value:@"application/json"];
|
|
|
+ [request addRequestHeader:@"Accept" value:@"application/vnd.api+json;version=1"];
|
|
|
+
|
|
|
+ __block void(^processRequest)(void) = ^{
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ NSDictionary *info = [[request.responseString objectFromJSONString] filterNullObject];
|
|
|
+
|
|
|
+ NSError *error = request.error;
|
|
|
+ if ([info valueForKey:@"msg"]) {
|
|
|
+ NSString *detailKey = [info valueForKey:@"msg"];
|
|
|
+ if ([detailKey isEqualToString:@"exceed_max_device_num"]) {
|
|
|
+ error = [NSError errorWithDomain:@"激活失败"
|
|
|
+ code:ActivityErrorTypeOutNumber
|
|
|
+ userInfo:info];
|
|
|
+ }else if ([detailKey isEqualToString:@"invalid_activate_info"]) {
|
|
|
+ error = [NSError errorWithDomain:@"激活失败"
|
|
|
+ code:ActivityErrorTypeInvalidInfo
|
|
|
+ userInfo:info];
|
|
|
+ }else if ([detailKey isEqualToString:@"invalid_license_key"]) {
|
|
|
+ error = [NSError errorWithDomain:@"激活失败"
|
|
|
+ code:ActivityErrorTypeCDKeyNotExist
|
|
|
+ userInfo:info];
|
|
|
+ }else if ([detailKey isEqualToString:@"license_not_match_product"]) {
|
|
|
+ error = [NSError errorWithDomain:@"激活失败"
|
|
|
+ code:ActivityErrorTypeNotMatchProduct
|
|
|
+ userInfo:info];
|
|
|
+ }else if ([detailKey isEqualToString:@"license_expired"]) {
|
|
|
+ error = [NSError errorWithDomain:@"激活失败"
|
|
|
+ code:ActivityErrorTypeCDKeyExpire
|
|
|
+ userInfo:info];
|
|
|
+ }else if ([detailKey isEqualToString:@" Activated success!"]) {
|
|
|
+ error = nil;
|
|
|
+ }else {
|
|
|
+ error = [NSError errorWithDomain:@"激活失败"
|
|
|
+ code:ActivityErrorTypeUnknow
|
|
|
+ userInfo:info];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if(error) {
|
|
|
+ error = [NSError errorWithDomain:error.domain code:ActivityErrorTypeNetworkDisable userInfo:error.userInfo];
|
|
|
+ } else {
|
|
|
+ error = [NSError errorWithDomain:@"激活失败"
|
|
|
+ code:ActivityErrorTypeUnknow
|
|
|
+ userInfo:@{}];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!error) {
|
|
|
+ NSMutableDictionary *dic = [weak_self.detailInfo?:@{} mutableCopy];
|
|
|
+
|
|
|
+ for (NSString *key in info[@"data"]) {
|
|
|
+ [dic setValue:info[@"data"][key] forKey:key];
|
|
|
+ }
|
|
|
+
|
|
|
+ weak_self.detailInfo = dic;
|
|
|
+
|
|
|
+ NSString *notificationName = (NSString *)kDeviceActivateStatusChangeNotification;
|
|
|
+ [[NSNotificationCenter defaultCenter] postNotificationName:notificationName
|
|
|
+ object:self
|
|
|
+ userInfo:info];
|
|
|
+
|
|
|
+// [self verificationWithComplention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
|
|
|
+ [weak_self verificationWithComplention:^(ActivityStatus status, NSDictionary *info, NSError *error) {
|
|
|
+
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ [weak_self restartTimer];
|
|
|
+
|
|
|
+
|
|
|
+ if (tComplention)
|
|
|
+ tComplention(weak_self.status, info, error);
|
|
|
+ });
|
|
|
+ };
|
|
|
+ [request setFailedBlock:^{
|
|
|
+ processRequest();
|
|
|
+ }];
|
|
|
+ [request setCompletionBlock:^{
|
|
|
+ processRequest();
|
|
|
+ }];
|
|
|
+ [request startAsynchronous];
|
|
|
+}
|
|
|
|
|
|
- (void)getCodeWithEmail:(NSString*)email
|
|
|
complention:(ActivityComplention)complention {
|