验证App store收据会提供DrmInvalidArgumentException

时间:2017-03-04 03:48:06

标签: ios in-app-purchase receipt-validation

我在这里遵循文档。

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 个答案:

答案 0 :(得分:2)

需要注意的事项:在此示例中,数据直接从应用程序发送到Apple,但您也可以从服务器执行此操作。在测试服务器App时,不要使用NSLog()来打印base64数据,NSLog会截断数据。

答案 1 :(得分: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!

希望这有助于某人。

答案 2 :(得分:1)

我也收到了相同的错误回复。我的解决方案是删除所有出现的 <?php // Connect to MySQL include("dbconnect.php"); date_default_timezone_set('Europe/Skopje'); $Data=date("Y-m-d H:i:s"); // Prepare the SQL statement $SQL = "INSERT INTO tanjaarduino.sensors (Data, sensor1 ,sensor2, sensor3, sensor4, sensor5, sensor6 ,sensor7, sensor8, sensor9, sensor10, sensor11, sensor12) VALUES (Data=".$Data.", '".$_GET["s1"]."', '".$_GET["s2"]."','".$_GET["s3"]."','".$_GET["s4"]."','".$_GET["s5"]."','".$_GET["s6"]."','".$_GET["s7"]."','".$_GET["s8"]."','".$_GET["s9"]."','".$_GET["s10"]."','".$_GET["s11"]."','".$_GET["s12"]."')"; echo "The time is " . $Data; // Execute SQL statement mysql_query($SQL); ?>

也许你有同样的问题。我还没有想出插入这些字符的时间和原因。

答案 3 :(得分:0)

注意URLENCODE:

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

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

    return encodedString;
}