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

Vit*_*kyi 6 in-app-purchase ios parse-platform

我正在尝试使用自动续订订阅来实现应用程序.用户应该付费访问我的应用程序的所有功能.我已经将Parse用作我的应用程序的后端.它为inAppPurchases提供了一些API方法,但没有任何关于自动更新类型的说法.我发现的唯一一件事就是在博客中有两年的线程,据说收据验证仅针对可下载的购买实施.

我试图在文档"简单购买"中使用,它工作正常但我无法弄清楚如何检查我的用户是否已经购买了订阅.

有没有人知道有没有办法通过Parse API来实现,或者这应该以另一种方式实现?

gyr*_*cus 4

如前所述,收据验证仅内置于可下载内容的 Parse SDK 中,但创建将应用程序收据 POST 到 iTunes Store 进行验证的 Cloud Code 函数相当简单。以下是用于服务器端验证的 Apple 文档:使用 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');
       }
    });
});
Run Code Online (Sandbox Code Playgroud)

有关解释收据 JSON 的详细信息,请参阅收据字段。对于 iOS 7+ 来说,这相当简单,但对于 iOS 6 及更早版本来说,自动续订订阅收据却很乏味。