Mac App Store应用内购买的在线收据验证 [英] Online receipt validation for Mac App Store In-App Purchases

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

问题描述

对于iOS的应用内购买,我们可以

For in-app purchases for iOS we can use an online API for validation, meaning that we can validate the purchase on our own server.

是否可以通过任何(API)验证OS X的应用内购买?

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

我仅找到

I've found only this snippet about in-app validation for Mac and it seems that Apple doesn't provide any API for online validation.

也许苹果有一些计划支持OS X的在线验证?

Or maybe there is some plan from Apple to support online validation for OS X?

推荐答案

我的应用程序 EasyBooks 提供了供用户使用的在线组件每年支付.将其作为非消耗性类型提供是没有意义的,因为它只能真正用作消耗性(但是在iOS中实际上是非重复订阅).我想提供此应用程序内,我想我终于有解决方案了……

My app EasyBooks 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..."

我收到苹果的回复说...

I got a reply from Apple saying ...

"用于验证Mac应用内购买产品的步骤 应用程序与iOS应用程序相同.所不同的是,您将把以64为基数的应用程序收据(而不是transactionReceipt属性的内容)分配给收据数据字段.检索应用程序的完整Mac App Store收据,然后使用base64编码对其进行编码.用一个名为回执数据的键创建一个JSON对象,然后将编码后的回执分配给它.按照应用内购买编程指南"中的通过应用商店验证收据"中所述进行操作.

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

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

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

因此,在经过几次失败的尝试之后,我确实设法解决了这一问题,即苹果服务器返回的收据数据不包含"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 receipt将对收据进行base64编码,而没有换行符(这很重要)

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

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

这将以以下格式返回JSON数据

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应用程序,其中包含可在应用程序内购买的易耗品和非易耗品的组合.易耗品是一项服务,由我的Web服务器完成.在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!

任何拥有Apple开发人员帐户的人都可以在Apple开发人员论坛上阅读有关此内容的信息: https://devforums.apple.com/message/548411#548411

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

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

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