如何检测和验证自动续订订阅的续订? [英] How to detect and verify a renewal for an auto-renewable subscription?

查看:23
本文介绍了如何检测和验证自动续订订阅的续订?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我为我的应用设置了一个自动续订订阅,期限为 1 个月,在沙箱中相当于 5 分钟左右.在我订阅的客户端应用程序中,将收据发送到我的服务器,它会得到验证,然后我在我的数据库中记录了该用户已订阅.

So I have setup an auto-renewable subscription for my app with a period of 1 month, which equals 5 minutes or so in the sandbox. In the client app I subscribe, send the receipt to my server, it gets verified and I put a record in my database that this user has a subscription.

我的问题是如何检查此订阅是否已续订?我已经阅读了文档,但不知道该怎么做.

My question is how do I check if this subscription has been renewed? I have read the docs and can't figure out what should I do.

这是我目前所处的位置:

Here is where I am so far:

  1. 发送到我的服务器的初始收据被验证为状态 0,很好.我还得到了 latest_receipt,我在我的数据库中用最旧的收据替换了它.
  2. 6 分钟后,当我尝试验证 latest_receipt 时,我得到状态 21006(已过期的收据)和:
  1. The initial receipt that gets sent to my server is verified with a status 0, great. I also get latest_receipt, which I replace in my database with the oldest receipt.
  2. After 6 minutes when I try to verify the latest_receipt, I get status 21006 (expired receipt) and this:

   { receipt: 
       { original_purchase_date_pst: '2013-08-06 11:58:04 America/Los_Angeles',
         unique_identifier: '------------',
         original_transaction_id: '----------',
         expires_date: '1376129825000',
         transaction_id: '------------',
         quantity: '1',
         product_id: 'subscription',
         item_id: '--------',
         bid: 'com.--------',
         unique_vendor_identifier: '---------',
         web_order_line_item_id: '---------',
         bvrs: '2.0',
         expires_date_formatted: '2013-08-10 10:17:05 Etc/GMT',
         purchase_date: '2013-08-10 10:12:05 Etc/GMT',
         purchase_date_ms: '1376129525000',
         expires_date_formatted_pst: '2013-08-10 03:17:05 America/Los_Angeles',
         purchase_date_pst: '2013-08-10 03:12:05 America/Los_Angeles',
         original_purchase_date: '2013-08-06 18:58:04 Etc/GMT',
         original_purchase_date_ms: '1375815484000' },
      latest_expired_receipt_info: 
       { original_purchase_date_pst: '2013-08-06 11:58:04 America/Los_Angeles',
         unique_identifier: '-------',
         original_transaction_id: '-',
         expires_date: '1376129825000',
         transaction_id: '-',
         quantity: '1',
         product_id: 'subscription',
         item_id: '-',
         bid: 'com.-',
         unique_vendor_identifier: '--',
         web_order_line_item_id: '-',
         bvrs: '2.0',
         expires_date_formatted: '2013-08-10 10:17:05 Etc/GMT',
         purchase_date: '2013-08-10 10:12:05 Etc/GMT',
         purchase_date_ms: '1376129525000',
         expires_date_formatted_pst: '2013-08-10 03:17:05 America/Los_Angeles',
         purchase_date_pst: '2013-08-10 03:12:05 America/Los_Angeles',
         original_purchase_date: '2013-08-06 18:58:04 Etc/GMT',
         original_purchase_date_ms: '1375815484000' },
      status: 21006 }

数组中的第二个元素以前是 latest_receipt_info,但现在是 latest_EXPIRED_receipt_info.这是文档所说的:

The second element in the array used to be latest_receipt_info, but now it's latest_EXPIRED_receipt_info. Here is what the docs say:

除了receipt_data字段,响应中还可能包括两个新领域.如果用户的订阅是有效的并且是 在收到您的订单后发生的交易续订服务器发送到 App Store,latest_receipt 字段包含一个此订阅最后一次续订的 base-64 编码收据.此新收据的解码数据也在latest_expired_receipt_info 字段.您的服务器可以使用这个新的收据以保留最近续订的记录.

In addition to the receipt_data field, the response may also include two new fields. If the user’s subscription is active and was renewed by a transaction that took place after the receipt your server sent to the App Store, the latest_receipt field includes a base-64 encoded receipt for the last renewal for this subscription. The decoded data for this new receipt is also provided in the latest_expired_receipt_info field. Your server can use this new receipt to maintain a record of the most recent renewal.

因此,如果自我的服务器上次检查以来订阅已续订,则续订的解码收据应在 latest_expired_receipt_info 中.在该对象中,expires_date 与原始收据的 expires_date 相同.

So if the sub has been renewed since my server last checked, the decoded receipt for the renewal should be in latest_expired_receipt_info. In that object the expires_date is the same as the original receipt's expires_date.

什么鬼?我只想检查 sub 是否处于活动状态.谁能用简单的话解释一下我该怎么做?

What the hell? I just want to check if the sub is active. Can anyone explain in simple words how do I do that?

谢谢!

推荐答案

我的经验.假设我们总是将初始收据发送到 Apple 的服务器.

My experience. Let's assume, we always send initial receipt to Apple's server.

无论如何,您将获得包含至少两个字段的 JSON:status(无注释)和 receipt(有关您已发送的收据的信息).

In any case, you'll get JSON with at least two fields: status (no comments) and receipt (information about receipt that you've send).

除此之外:

1) 如果订阅仍然有效,您将另外获得 latest_receipt(base64 编码字符串)和 latest_receipt_info(关于那个收据).

1) If the subscription is still active, you'll additionally get latest_receipt (base64-encoded string) and latest_receipt_info (information about that receipt).

2) 如果订阅已经过期,您还将获得latest_expired_receipt_info(关于上次续订收据的信息).是的,你只得到关于它的信息,没有 base64 编码的字符串.

2) If the subscription is already expired, you'll additionally get latest_expired_receipt_info (information about last renewing receipt). Yes, you get only information about it, no base64-encoded string.

是的,AFAIK,这在任何地方都没有记录.希望有所帮助.

And yes, AFAIK, that's not documented anywhere. Hope that helps.

这篇关于如何检测和验证自动续订订阅的续订?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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