使用 Parse iOS SDK 检查用户是否具有有效的自动续订订阅 [英] Check if user has valid auto-renewable subscription with Parse iOS SDK

查看:13
本文介绍了使用 Parse iOS SDK 检查用户是否具有有效的自动续订订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一个具有自动续订订阅的应用程序.用户应该付费访问我的应用程序的所有功能.我已经使用 Parse 作为我的应用程序的后端.它为 inAppPurchases 提供了一些 API 方法,但没有提及自动更新类型.我唯一发现的是博客中有一些两年前的帖子,据说收据验证仅适用于可下载的购买.

I'm trying to implement an application with auto-renewable subscription. Users should pay to access all functions of my application. I already use Parse as backend for my application. It provides some API methods for inAppPurchases but there is nothing said about auto-renewable type. The only thing I have found is some two years old threads in the blog it is said that receipt verification was implemented only for downloadable purchases.

我尝试使用文档Simple purchase"中所称的方法,效果很好,但我不知道如何检查我的用户是否已经购买了订阅.

I have tried to use as it called in docs "Simple purchase" and it works fine but I can't figure out how can I check if my user already bought subscription or not.

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

Does anybody know is there way to do it via Parse API or This should implemented in another way?

推荐答案

如前所述,收据验证仅内置于 Parse SDK 中,用于可下载的内容,但创建一个 Cloud Code 函数来发布应用收据是相当简单的到 iTunes Store 进行验证.以下是用于服务器端验证的 Apple 文档:Validating Receipts with应用商店

As mentioned, receipt validation is only built into the Parse SDK for downloadable content, but it is fairly simple to to create a Cloud Code function that POSTs the app receipt to the iTunes Store for validation. Here are the Apple docs for server side validation: Validating Receipts with the App Store

这是一个基本函数的样子:

Here is a what a basic function would look like:

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');
       }
    });
});

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

See Receipt Fields for details on interpreting the receipt JSON. It's fairly straight forward for iOS 7+, but auto-renewing subscription receipts for iOS 6 and earlier are tedious.

这篇关于使用 Parse iOS SDK 检查用户是否具有有效的自动续订订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆