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

系统教程 行业动态 更新时间:2024-06-14 16:58:30
针对MAC的应用内购买的在线收据验证(Online receipt validation for in app purchases for MAC)

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

是否有任何方法(API)用于OSX的应用内购买验证?

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

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

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.

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

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.

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

最满意答案

(2012年9月11日编辑)

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

我使用了一张Apple DTS票据来查询StoreKitGuide文档中的声明。 它说 ...

“OS X支持本章描述的服务器验证方法和本地验证方法......”

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

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

注意:在App Purchases中,收据包含在关联的Mac应用程序收据中。 您必须检查与您的应用关联的收据,以验证其包含的应用内购买收据的有效性。 这样做还允许您在应用程序中启用适当的功能。“

因此,经过一些尝试失败后,我确实设法让这一点得到了警告,即Apple的服务器返回的收据数据不包含“GUID的散列”,因此不会将收据数据绑定到任何特定硬件。

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

找到Mac应用程序收据文件(一旦您运行应用程序并输入您的(测试)Apple ID和密码,它就在您的应用程序包中。

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

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

这将返回格式的JSON数据

{"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工程师的说法)任何消费类型的应用内购买将在首次购买时添加到收据中,但在进一步购买或恢复操作后被删除。 我想知道在每次购买后让应用程序中运行的代码复制收据文件是否是个好主意,以防我们自己的服务器在应用程序尝试验证收据时关闭。 用户可能会尝试恢复购买,而不会意识到这将删除任何消耗品收据。

我希望有所帮助。

(原始评论如下)

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

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

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

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

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

(EDITED 11 September 2012)

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...

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

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

I got a reply from Apple saying ...

"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.

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."

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.

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

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.

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

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

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"} ]}}

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.

I hope that helps.

(ORIGINAL COMMENTS FOLLOW)

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.

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

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

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!

** 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

更多推荐

本文发布于:2023-04-15 03:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/4bb19ef29f3166eb9cccda8430455796.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在线   收据   Online   MAC   app

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!