iOS应用内购买状态21002,java.lang.NumberFormatException

9
验证苹果IOS应用内购买收据时,我们的一些交易返回以下信息:
{"status":21002,"exception":"java.lang.NumberFormatException"}

请问问题的原因是什么?我们已经按照苹果应用内购买指南进行操作,即在iOS客户端中使用Base 64编码对应用商店返回的收据进行编码,然后再将其发送进行验证。

注意:我们的大部分交易都成功了,只有约10%的交易出现了上述错误。

3个回答

8

可能有以下几个原因:

  • 有人试图攻击您的IAP收据验证。有些技术会插入虚假收据,希望开发者没有正确验证它们。urus hack有这种行为。

  • 在测试过程中出现错误,导致测试收据发送到生产验证器。

我经常见到这些错误,但我不记得这两个原因是哪一个导致了这个确切的消息。我认为它们都有可能。我看到这些错误后还没有收到过客户的抱怨。

如果您的销售量足够低(不幸的是,我的销售量就是这样),请进入iTunes Connect查看是否有与这些错误匹配的销售。您也可以查看收据数据,看看它是否可疑。


0

还有另一种可能性,您只发送pucharse_info而不是整个解密的JSON(包括签名等)

var receipt = Ti.Utils.base64encode(evt.receipt).text;

-1

当您验证收据时,可以尝试以下代码:

    NSData *receipt; // Sent to the server by the device

// Create the JSON object that describes the request
NSError *error;
NSDictionary *requestContents = @{
    @"receipt-data": [receipt base64EncodedStringWithOptions:0]
};
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 ... */
    } else {
        NSError *error;
        NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
        if (!jsonResponse) { /* ... Handle error ...*/ }
        /* ... Send a response back to the device ... */
    }
}];

Reference:https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW1


除非您不关心中间人攻击,否则永远不应该直接从您的设备验证收据到苹果的终端。您应该将其发送到您的服务器,并从您的服务器使用苹果的后端进行验证。 - mmsarquis

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接