iOS In App购买状态21002,java.lang.NumberFormatException



在Apple服务器验证Apple IOS应用内购买收据时,我们的一些交易返回为:

{"status":21002,"exception":"java.lang.NumberFormatException"}
我可以知道问题的原因是什么吗?我们遵循Apple应用内购买指南,即我们将在发送收据之前以Base 64编码来自iOS客户端的应用商店退货收据以进行验证

注意:我们的大部分交易都通过了,大约有10%的交易有上述错误

几个可能的原因:

  • 有人试图破解你的IAP收据验证。有一些技术可以插入假收据,希望开发人员无法正确验证它们。

  • 测试过程中的错误导致测试收据转到生产验证者。

我经常看到这些错误,但是我不记得这两个错误中哪一个导致了这个确切的消息。我想他们都是。看过之后,我还没有收到过客户投诉。

如果你的销量足够低(不幸的是,我的是),进入iTunes Connect,看看是否有任何销售匹配的错误。您还可以查看收据数据,看看它是否看起来可疑。

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

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

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

    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 ... */
    }
}];

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

相关内容

最新更新