应用内购买收据验证

发布于 2024-11-05 22:02:21 字数 755 浏览 1 评论 0原文

我想在我的应用程序中验证交易收据,

这是我的代码,

- (void)recordTransaction:(SKPaymentTransaction *)transaction {

    NSData *receiptData = [NSData dataWithData:transaction.transactionReceipt];

    NSString *encodedString = [Base64 encode:receiptData];

     NSURL *url = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];

    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];

    [request setPostValue:encodedString forKey:@"receipt-data"];

    [request setRequestMethod:@"POST"];

    [request setDelegate:self];

    [request startAsynchronous];

}

我得到输出:

{“status”:21002,“异常”:“java.lang.NullPointerException”}

有人可以帮助我获得正确的收据验证吗?

I want to verify the transaction receipt within my app,

Here is my code,

- (void)recordTransaction:(SKPaymentTransaction *)transaction {

    NSData *receiptData = [NSData dataWithData:transaction.transactionReceipt];

    NSString *encodedString = [Base64 encode:receiptData];

     NSURL *url = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];

    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];

    [request setPostValue:encodedString forKey:@"receipt-data"];

    [request setRequestMethod:@"POST"];

    [request setDelegate:self];

    [request startAsynchronous];

}

I am getting output:

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

Can someone help me to get proper receipt verification?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

猛虎独行 2024-11-12 22:02:21

仅供那些可能觉得有帮助的人使用。我注意到苹果已经更新了应用程序内购买指南,其中包含一些用于自动更新订阅购买的状态代码,但似乎也适用于此处。

  • 21000 App Store 无法读取您提供的 JSON 对象。
  • 21002 收据数据属性中的数据格式错误。
  • 21003 收据无法验证。
  • 21004 您提供的共享密钥与您帐户存档的共享密钥不匹配。
  • 21005 收据服务器当前不可用。
  • 21006 此收据有效,但订阅已过期。当此状态代码返回到您的服务器时,收据数据也会被解码并作为响应的一部分返回。
  • 21007 该收据是沙盒收据,但已发送到生产服务进行验证。
  • 21008 此收据是生产收据,但已发送至
    用于验证的沙箱服务。

重要提示:此处的非零状态代码仅在恢复有关自动续订订阅的信息时适用。在测试其他类型产品的响应时,请勿使用这些状态代码。 (真的吗?)

我希望这可以作为参考。我得到了 21007。Apple

网站上的状态代码列表: https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html

Just for those who may find it helpful. I noticed that apple has updated the In App Purchasing Guide with some status code that are for the auto renewable subscription purchases but seem to apply here as well.

  • 21000 The App Store could not read the JSON object you provided.
  • 21002 The data in the receipt-data property was malformed.
  • 21003 The receipt could not be authenticated.
  • 21004 The shared secret you provided does not match the shared secret on file for your account.
  • 21005 The receipt server is not currently available.
  • 21006 This receipt is valid but the subscription has expired. When this status code is returned to your server, the receipt data is also decoded and returned as part of the response.
  • 21007 This receipt is a sandbox receipt, but it was sent to the production service for verification.
  • 21008 This receipt is a production receipt, but it was sent to the
    sandbox service for verification.

Important: The non-zero status codes here apply only when recovering information about a auto-renewable subscription. Do not use these status codes when testing responses for other kinds of products. (Really?)

I hope this helps as a reference. I got nailed with 21007.

List of status codes on Apple's website: https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html

倾城花音 2024-11-12 22:02:21

经过多次尝试,我决定从服务器端进行收据验证。实际上这是推荐的方式。

这是我的代码,

-(void)recordTransaction:(SKPaymentTransaction *)transaction {   

NSString* receiptString = [[[NSString alloc] initWithData:transaction.transactionReceipt encoding:NSUTF8StringEncoding] autorelease];

// POST this string to your server

// I used ASIFormDataRequest 

}

// server side 

$url = 'https://sandbox.itunes.apple.com/verifyReceipt';

// encode the receipt data received from application

$purchase_encoded = base64_encode( $purchase_receipt );

//Create JSON

    $encodedData = json_encode( Array( 
        'receipt-data' => $purchase_encoded 
    ) );


// POST data

    //Open a Connection using POST method, as it is required to use POST method.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $encodedData);
    $encodedResponse = curl_exec($ch);
    curl_close($ch);


  //Decode response data using json_decode method to get an object.

      $response = json_decode( $encodedResponse );


// check response

if ($response->{'status'} != 0)

    // Invalid receipt

else

   // valid reciept

我找到了帮助表单,

http://gamesfromwithin.com/in-app -购买-第3部分

After number of tries, I decided to do the receipt verification from server side. Actually this is the recommended way.

Here is my code,

-(void)recordTransaction:(SKPaymentTransaction *)transaction {   

NSString* receiptString = [[[NSString alloc] initWithData:transaction.transactionReceipt encoding:NSUTF8StringEncoding] autorelease];

// POST this string to your server

// I used ASIFormDataRequest 

}

// server side 

$url = 'https://sandbox.itunes.apple.com/verifyReceipt';

// encode the receipt data received from application

$purchase_encoded = base64_encode( $purchase_receipt );

//Create JSON

    $encodedData = json_encode( Array( 
        'receipt-data' => $purchase_encoded 
    ) );


// POST data

    //Open a Connection using POST method, as it is required to use POST method.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $encodedData);
    $encodedResponse = curl_exec($ch);
    curl_close($ch);


  //Decode response data using json_decode method to get an object.

      $response = json_decode( $encodedResponse );


// check response

if ($response->{'status'} != 0)

    // Invalid receipt

else

   // valid reciept

I found help form,

http://gamesfromwithin.com/in-app-purchases-part-3

娜些时光,永不杰束 2024-11-12 22:02:21

...您没有触发您的请求。所以您的回复为空,因为您尚未提出请求!

添加 [request startSynchronous] 调用(这通常是一个坏主意,您应该始终异步运行网络调用),或者更好地重写代码以支持异步网络调用,并使用 [请求 startAsynchronous] 相反。

如果您需要更多信息,我建议您查看 ASI 文档:
http://allseeing-i.com/ASIHTTPRequest/How-to-use

...you're not firing your request. So your response is null, because you haven't made the request yet!

Either add a [request startSynchronous] call (which is generally a bad idea, you should always run your network calls asynchronously), or better yet rewrite your code to support an asynchronous network call, and use [request startAsynchronous] instead.

I would suggest reviewing the ASI documentation if you need more information:
http://allseeing-i.com/ASIHTTPRequest/How-to-use

从此见与不见 2024-11-12 22:02:21

从以下参考文献中,我了解到您的应用程序需要使用单独的服务器来“验证商店收据”。我认为对于收据验证,我们需要使用来自静态 IP 的请求。

谢谢,

参考

From the following reference I understand that your application need to use separate server for "Verifying Store Receipts". I think for receipts verification we need to use a request from static ip.

thanks,

Reference

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文