3

我在这里关注文档。

https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html

我有一个我正在尝试验证的团队的收据数据,他们收到错误代码 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)
4

4 回答 4

2

Something to keep in mind: In this example the data is sent to Apple straight from the App, but you might do this from a server too. When you testing your server App don't use NSLog() to print your base64 data, NSLog truncates data.

于 2017-03-14T18:08:33.757 回答
2

当使用来自几天前的测试用户的收据时,我遇到了这个问题,并且每年自动更新订阅。

我检查了上面关于额外字符等的有用回复(我还检查了我是否提供了我的应用程序密码以进行自动更新),但并不高兴。

In the end I tried creating A NEW SANDBOX user and it worked first time 
with no other changes other than the new Receipt!

希望这可以帮助某人。

于 2017-07-19T16:17:32.673 回答
1

对于多份收据,我也收到了相同的错误响应。我的解决方案是删除所有出现的\r\n.

也许你有同样的问题。我仍然没有弄清楚这些字符何时以及为什么插入。

于 2017-03-08T16:07:37.150 回答
0

注意URLENCODE:

- (NSString *)URLEncodedString
{
    // CharactersToBeEscaped = @":/?&=;+!@#$()~',*";
    // CharactersToLeaveUnescaped = @"[].";

    NSString *unencodedString = self;
    NSString *encodedString = (NSString *)
    CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                              (CFStringRef)unencodedString,
                                                              NULL,
                                                              (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                              kCFStringEncodingUTF8));

    return encodedString;
}
于 2018-06-12T04:10:39.337 回答