【问题标题】:iOS In App purchase status 21002, java.lang.NumberFormatExceptioniOS In App 购买状态 21002,java.lang.NumberFormatException
【发布时间】:2013-03-03 16:20:14
【问题描述】:

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

{"status":21002,"exception":"java.lang.NumberFormatException"}

我可以知道问题的原因是什么吗? 我们已遵循 Apple 应用内购买指南,即我们将使用来自 iOS 客户端的 Base 64 对应用商店退货收据进行编码,然后再发送收据以进行验证

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

【问题讨论】:

    标签: ios in-app-purchase


    【解决方案1】:

    几个可能的原因:

    • 有人试图破解您的 IAP 收据验证。有一些技术会插入伪造的收据,希望开发人员无法正确验证它们。 urus hack 有这种行为。

    • 测试期间的错误导致测试收据发送给生产验证者。

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

        当你验证收据时,也许你可以试试下面的代码:

            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

        【讨论】:

        • 您永远不应该(除非您不关心 MITM 攻击)直接从您的设备验证收据到 Apple 的端点。您应该将其发送到您的服务器,然后从您的服务器使用 Apple 的后端对其进行验证。
        猜你喜欢
        • 2015-09-16
        • 2011-12-10
        • 2012-12-27
        • 2023-02-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多