验证Mac App Store收据服务器端

时间:2014-04-09 08:42:56

标签: macos mac-app-store receipt-validation

我已将IAP添加到我的Mac Appstore应用程序中。我无法正确验证收据服务器端。我正在使用此代码阅读收据:

NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];

// This is my own method to convert to base64
NSString *receiptString = [NSData base64forData:receipt];

然后我将数据发送到我的服务器,然后查询https://buy.itunes.apple.com/verifyReceipt以查看收据是否有效。无论我尝试什么,我总是收到无效的收据。当我将收据文件作为纯文本提供或使用base64命令行工具编码时,我也尝试使用gem Venice具有相同问题。但与此同时,我在/Applications的所有应用中尝试使用收据文件时失败。

是否有人在Mac Appstore上成功实施了收据验证?

1 个答案:

答案 0 :(得分:3)

在对此进行调查之后,我终于找到了一个适用于Mac Appstore收据的宝石:itunes-receipt

require 'itunes/receipt'

# pass Base64 encoded raw receipt data which you received from your app
receipt = Itunes::Receipt.verify! 'ewoJInNpZ25hdHVyZSIgPSAi...'
receipt.product_id     # => 'com.example.products.100gems'
receipt.transaction_id # => '1234567890'