针对MAC的应用内购买的在线收据验证 [英] Online receipt validation for in app purchases for MAC

查看:264
本文介绍了针对MAC的应用内购买的在线收据验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于iOS的应用内购买,我们可以使用在线API进行验证 - http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/VerifyingStoreReceipts/VerifyingStoreReceipts.html
这意味着,我们可以在自己的服务器上验证购买。

For in-app purchases for iOS we can use online API for validation - http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/VerifyingStoreReceipts/VerifyingStoreReceipts.html It means, that we can validate the purchase on own server.

对于OSX的应用内购买验证有没有办法(API)?

Is there any way (API) for such validation of in app purchases for OSX?

我发现只有关于Mac的应用内验证的这个片段 - http://developer.apple.com/library/mac/releasenotes/General/ValidateAppStoreReceipt/_index .html#// apple_ref / doc / uid / TP40010573-CH1-SW23 似乎Apple没有为在线验证提供任何API。

I've found only this snippet about in-app validation for Mac - http://developer.apple.com/library/mac/releasenotes/General/ValidateAppStoreReceipt/_index.html#//apple_ref/doc/uid/TP40010573-CH1-SW23 and it seems that Apple doesn't provide any API for online validation.

或者可能是Apple有一些计划支持OSX的在线验证...

Or may be there is some plan from Apple to support online validation for OSX...

推荐答案

(2012年9月11日编辑)

(EDITED 11 September 2012)

我的应用提供了用户每年支付的在线组件。将它作为非消耗类型提供是没有意义的,因为它只能作为消耗品使用(但它实际上是iOS中的非重复订阅)。我想在应用程序中提供这个,我想最终我有一个解决方案...

My app provides an online component that users pay yearly for. It wouldn't make sense to provide this as a non-consumable type as it only really works as a consumable (however it's really a non-repeating subscription in iOS). I would like to offer this in-app and I think I have a solution finally...

我使用了我的一张Apple DTS门票来查询在StoreKitGuide文档。它说...

I used one of my Apple DTS tickets to query a statement made in the StoreKitGuide document. It says ...


OS X支持此
章节中描述的服务器验证方法和本地验证方法。 ..

"OS X supports both the server validation method described in this chapter and the local validation method..."

我得到了Apple的回复说...

I got a reply from Apple saying ...


验证Mac
应用程序的应用程序内购买产品的步骤与iOS应用程序使用的步骤相同。不同之处在于您将分配基本64位编码的应用程序收据(而不是检索应用程序的完整Mac App Store收据,然后使用base64编码对其进行编码。使用名为receipt-data的单个密钥创建一个JSON对象,并分配编码的收据,而不是transactionReceipt属性的内容。按照应用程序内购买编程指南中的通过应用程序商店验证收据部分所述进行操作。

"The steps for verifying your In-App Purchase products for Mac applications are the same used for iOS applications. The difference is that you will be assigning your base 64 encoded app receipt (rather than the content of the transactionReceipt property) to the receipt-data field. Retrieve the full Mac App Store receipt for your application, then encode it using base64 encoding. Create a JSON object with a single key named receipt-data and assign your encoded receipt to it. Proceed as outlined in the Verifying a Receipt with the App Store section of the In-App Purchase Programming Guide.

注意:在App Purchase中收据包含在相关的Mac应用程序的收据。你必须chec k与您的应用关联的收据,以验证其包含的应用内购买收据的有效性。这样做还允许您在应用程序中启用相应的功能。

Note: In App Purchases receipt are included in the associated Mac app's receipt. You must check the receipt associated with your app to verify the validity of the In-App Purchase receipts that it contains. Doing so also allows you to enable the appropriate functionality in your app."

因此,在尝试失败之后,我确实设法得到了这个请注意,Apple服务器返回的收据数据不包含GUID的散列,因此不会将收据数据与任何特定硬件联系起来。

So after some failed attempts, I did manage to get this working with the caveat that the receipt data returned by Apple's servers does not contain the 'hash of the GUID' and therefore does not tie the receipt data to any particular hardware.

这可以使用以下步骤在Mac上轻松测试:

This can be tested on your Mac quite easily using these steps:


  1. 查找Mac应用程序收据文件(它位于应用程序包中一旦你运行了应用程序并输入了(测试)Apple ID和密码。

  1. Find the Mac app receipt file (it's in your app's bundle once you've run the app and entered your (test) Apple ID and password.

在命令行中, base64 -i收据将base64编码收据没有换行符(这很重要)

At the command line, base64 -i receipt will base64 encode the receipt with no line breaks (that's important)

再次发出命令line, curl -d'{receipt-data:< your b64 string here>}'https://sandbox.itunes.apple.com/verifyReceipt

Again at the command line, curl -d '{ "receipt-data": "<your b64 string here>" }' https://sandbox.itunes.apple.com/verifyReceipt

这会返回JSON da ta格式为

This returns JSON data in the format

{"status":0, 
 "environment":"Sandbox", 
 "receipt":{"adam_id":"0", 
            "bundle_id":"uk.co.geode.easybooks", 
            "application_version":"2.2.7", 
            "download_id":"0", 
            "in_app":[ {"quantity":"1", 
                        "product_id":"uk.co.geode.easybooks.syncing",
                        "transaction_id":"1000000034508678",
                        "purchase_date":"2012-09-05 12:00:17 Etc/GMT",
                        "original_transaction_id":"1000000034508678",
                        "original_purchase_date":"2012-01-24 10:16:17 Etc/GMT"} ]}}

我还没有确认,但显然(根据Apple工程师的说法)任何消费类型的应用内购买将在首次购买时添加到收据中,但在进一步购买或恢复操作后被删除。我想知道在每次购买后让应用程序中运行的代码复制收据文件是否是个好主意,以防我们自己的服务器在应用程序尝试验证收据时关闭。用户可能会尝试恢复购买,但没有意识到这将删除任何消耗品收据。

I have not confirmed it yet, but apparently (according to the Apple engineer) any consumable types of in-app purchase will be added to the receipt when first purchased, but removed after any further purchases or restore operations. I wonder whether it might be a good idea to make the code running in the app make a copy of the receipt file after each purchase just in case our own servers are down at the time the app tries to validate the receipt. Users may otherwise try to restore purchases, not realising this will remove any consumable product receipts.

我希望有所帮助。

(原始评论如下)

我遇到同样的问题。我在商店里有一个iOS应用程序,它包含可以在应用程序内购买的消费品和非消费品。消费品是一项服务,由我的网络服务器完成。在StoreKit委托方法 paymentQueue:updatedTransactions:中,我使用 transactionReceipt 属性,这是一个NSData对象。我将其编码为base64并将其发送到服务器。在服务器上我将收据传递给Apple的服务器进行验证。

I have the same issue. I have an iOS app in the store that has a mix of consumable and non-consumable products that can be purchased in-app. The consumable product is a service, which is fulfilled by my webserver. In the StoreKit delegate method paymentQueue:updatedTransactions:, I use the transactionReceipt property, which is an NSData object. I encode this to base64 and send it to the server. Out on the server I pass the receipt to Apple's servers for validation.

但对于Mac OS,SKPaymentTransaction上没有transactionReceipt属性,因此我们无法验证收据同样的方式。

But for Mac OS, there is no transactionReceipt property on the SKPaymentTransaction, so we cannot validate receipts in the same way.

我们可以做非易耗品,这可能会对您有所帮助。在Mac OS上进行应用内购买时,收据会在应用包中更新。然后可以解析收据文件,查找每个应用程序内收据,这些收据全部存储在主包中的收据文件中。有关详细信息,请参阅 http://developer.apple.com /library/mac/#releasenotes/General/ValidateAppStoreReceipt/_index.html

We can do the non-consumable products, which may help you. When an in-app purchase is made on Mac OS, the receipt is updated in the app bundle. It is then possible to parse the receipt file looking for each in-app receipt, which are all stored in the receipt file in the main bundle. For more about that see http://developer.apple.com/library/mac/#releasenotes/General/ValidateAppStoreReceipt/_index.html

当我使用非消费品时,这对我来说很好,但我有一个耗材,这是更新到应用程序的收据文件。如果没有transactionReceipt属性,我认为我的服务器无法验证收据是否为正版。如果其他人有任何其他经验,请告诉我们!

This works fine for me when I use the non-consumable product, but I have one consumable and this is not updated into the app's receipt file. Without the transactionReceipt property, I don't see any way for my server to validate that the receipt is genuine. If anyone else has any other experience please let us know!

**已添加2011年10月5日**
任何拥有Apple开发者帐户的人也可以阅读此内容在Apple开发者论坛上:
https://devforums.apple.com/message/548411 #548411

** Added 5 Oct 2011 ** Anyone with an Apple developer account can also read about this on the Apple developer forum: https://devforums.apple.com/message/548411#548411

这篇关于针对MAC的应用内购买的在线收据验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆