[英]Validating App store receipt gives DrmInvalidArgumentException
我在這里關注文檔。
我有我的團隊的收據數據,我正在嘗試驗證,他們收到錯誤代碼21002,這是錯誤的JSON。 看起來他們有額外的參數附加到base64數據,所以我嘗試刪除它們並發送:
- (void)viewDidLoad {
[super viewDidLoad];
NSData *receipt; // Sent to the server by the device
// Create the JSON object that describes the request
NSError *error;
NSDictionary *requestContents = @{
@"receipt-data": @"<<$mybase64data>>", @"password" : @"<<$thepassword>>"};
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents options:0 error:&error];
if (!requestData) { /* ... Handle error ... */ }
// Create a POST request with the receipt data.
NSURL *storeURL = [NSURL URLWithString:@"https://buy.itunes.apple.com/verifyReceipt"];
NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
[storeRequest setHTTPMethod:@"POST"];
[storeRequest setHTTPBody:requestData];
// Make a connection to the iTunes Store on a background queue.
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:storeRequest queue:queue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (connectionError) {
/* ... Handle error ... */
NSLog(@"conerror %@", connectionError);
} else {
NSError *error;
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
NSLog(@"hello %@", jsonResponse);
NSLog(@"error %@", error);
if (!jsonResponse) {
}
}
}];
}
結果:
2017-03-03 22:45:47.454 receipttest[89851:352604] hello {
exception = "com.apple.jingle.mzfairplay.validators.DrmInvalidArgumentException";
status = 21002;
}
2017-03-03 22:45:47.455 receipttest[89851:352604] error (null)
需要記住的一點是:在此示例中,數據直接從App發送給Apple,但您也可以從服務器執行此操作。 在測試服務器App時,不要使用NSLog()來打印base64數據,NSLog會截斷數據。
使用來自測試用戶的收據時,我遇到了這個問題,該收據是幾天之后,每年都有可自動續訂的訂閱。
我查看了上面有關額外字符等的有用回復(我還檢查過我提供了自動更新的應用秘密),沒有任何樂趣。
In the end I tried creating A NEW SANDBOX user and it worked first time
with no other changes other than the new Receipt!
希望這有助於某人。
我也收到了相同的錯誤回復。 我的解決方案是刪除所有出現的\\r\\n
。
也許你有同樣的問題。 我還沒有想出插入這些字符的時間和原因。
注意URLENCODE:
- (NSString *)URLEncodedString
{
// CharactersToBeEscaped = @":/?&=;+!@#$()~',*";
// CharactersToLeaveUnescaped = @"[].";
NSString *unencodedString = self;
NSString *encodedString = (NSString *)
CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)unencodedString,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8));
return encodedString;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.