ios - 使用 Parse iOS SDK 检查用户是否具有有效的自动续订订阅

标签 ios parse-platform in-app-purchase

我正在尝试实现一个具有自动续订订阅功能的应用程序。用户应该付费才能访问我的应用程序的所有功能。我已经使用 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/

相关文章:

ios - 更改两个 UITableViewCells 之间的间距以匹配行间距

parse-platform - Parse.com - 在对象数组中查询

iphone - 应用内购买的商品类型

ios - (iOS + StoreKit) 我可以检测到我何时在沙盒中吗?

ios - 如何以最短的迭代速度更快地与服务器联系人同步联系人?

iphone - UIView旋转然后移动

ios - 使用 iOS 从特定指针 ID 加载多个图像

ios - 从解析中拉出对象后如何从 parse.com 对象访问其他属性/列(swift)

android - 如何在不支付真钱的情况下测试应用内购买

ios - Swift3 中的 NSIndexPath 初始化有何变化?