macos - Mac App Store 应用内购买的在线收据验证

标签 macos validation in-app-purchase

对于 iOS 的应用内购买,我们可以 use an online API for validation ,这意味着我们可以在我们自己的服务器上验证购买。

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

我只找到this snippet about in-app validation for Mac而且Apple似乎没有提供任何在线验证的API。

或者 Apple 可能有一些支持 OS X 在线验证的计划?

最佳答案

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

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

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

我收到 Apple 的回复说...

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

因此,经过几次失败的尝试后,我确实成功地实现了这一点,但需要注意的是,Apple 服务器返回的收据数据不包含“GUID 的哈希值”,因此不会将收据数据与任何特定硬件绑定(bind)。

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

  1. 找到 Mac 应用收据文件(运行应用并输入(测试)Apple ID 和密码后,该文件位于应用的 bundle 中。

  2. 在命令行中,base64 -i receipt将对收据进行 base64 编码不换行(这一点很重要)

  3. 再次在命令行,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"} ]}}

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

希望对您有所帮助。

(以下为原始评论)

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

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

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

当我使用非消耗品时,这对我来说效果很好,但我有一种消耗品,并且它更新到应用程序的收据文件中。如果没有 transactionReceipt 属性,我看不到服务器有任何方法来验证收据是否真实。如果其他人有任何其他经验,请告诉我们!

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

关于macos - Mac App Store 应用内购买的在线收据验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7598047/

相关文章:

macos - 如何在 Mac 系统日志中找到蓝牙连接

C#:以安全的方式正确发送电子邮件

php - 我们如何在 zend 框架上创建翻译验证错误消息?

php - 一些关于 RSS 提要的帮助

ios - 使用真实Apple ID的应用内购买行为

mysql - Mac OSX 上的 Xampp 管理器,最近 mysql 服务器停止启动

python - wx无法在mac上运行

c++ - 在带有 XCode 的 OpenCV 中使用 Featured2D 构建错误

xamarin.ios - Xamarin SKPaymentQueue AddPayment 抛出异常

javascript - 谷歌浏览器 : payments API returns purchase failed while transaction is successful