我正在尝试实现一个具有自动续订订阅功能的应用程序。用户应该付费才能访问我的应用程序的所有功能。我已经使用 Parse 作为我的应用程序的后端。它为 inAppPurchases 提供了一些 API 方法,但没有提及自动更新类型。我唯一发现的是博客中一些两年前的帖子,据说收据验证仅针对可下载的购买实现。
我曾尝试使用它在文档中称为“简单购买”的方式,它运行良好,但我不知道如何检查我的用户是否已经购买了订阅。
有没有人知道有没有办法通过 Parse API 来做到这一点,或者这应该以其他方式实现?
最佳答案
如前所述,收据验证仅内置于可下载内容的 Parse SDK 中,但创建一个 Cloud Code 函数将应用收据发布到 iTunes Store 以进行验证相当简单。以下是用于服务器端验证的 Apple 文档:Validating Receipts with the App Store
这是一个基本函数的样子:
Parse.Cloud.define('validateReceipt', function (request, response) {
var receiptAsBase64EncodedString = request.params.receiptData;
var postData = {
method: 'POST',
url: 'http://buy.itunes.apple.com/verifyReceipt',
body: { 'receipt-data': receiptAsBase64EncodedString,
'password': SHARED_SECRET }
}
Parse.Cloud.httpRequest(postData).then(function (httpResponse) {
// httpResponse is a Parse.Cloud.HTTPResponse
var json = httpResponse.data; // Response body as a JavaScript object.
var validationStatus = json.status; // App Store validation status code
var receiptJSON = json.receipt; // Receipt data as a JSON object
// TODO: You'll need to check the IAP receipts to retrieve the
// expiration date of the auto-renewing subscription, and
// determine if it is expired yet.
var subscriptionIsActive = true;
if (subscriptionIsActive) {
return response.success('Subscription Active');
}
else {
return response.error('Subscription Expired');
}
});
});
参见 Receipt Fields有关解释收据 JSON 的详细信息。对于 iOS 7+ 而言,这相当简单,但对于 iOS 6 及更早版本,自动续订订阅收据却很乏味。
关于ios - 使用 Parse iOS SDK 检查用户是否具有有效的自动续订订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27041132/