如何检测和验证更新为自动再生订阅? [英] How to detect and verify a renewal for an auto-renewable subscription?
问题描述
所以,我已经安装了我的为期1个月,这相当于在沙箱中5分钟左右的应用程序自动再生订阅。在客户端应用程序我同意,发送回执到我的服务器,它得到验证,我把记录在我的数据库,这个用户有一个订阅。
我的问题是我该如何检查,如果该订阅已续订?我已阅读文档和想不出该怎么办。
这里是我迄今为止:
- 是被发送到我的服务器初始收据验证了状态0,太棒了。我也得到latest_receipt,我在用最古老的收据替换数据库中。
- 6分钟后,当我尝试验证latest_receipt,我得到状态21006(过期收据)和这样的:
{收据:
{original_purchase_date_pst:2013年8月6日11时58分04秒美洲/洛杉矶,
唯一标识符: ' - - - - - - ',
original_transaction_id:----------,
expires_date:1376129825000,
TRANSACTION_ID:------------,
量:'1',
PRODUCT_ID:'认购',
ITEM_ID:--------,
出价:COM --------,
unique_vendor_identifier:---------,
web_order_line_item_id:---------,
bvrs:'2.0',
expires_date_formatted:2013年8月10日10时17分05秒ETC / GMT,
购买日期:2013年8月10日10时12分05秒ETC / GMT,
purchase_date_ms:1376129525000,
expires_date_formatted_pst:2013年8月10日3时17分05秒美洲/洛杉矶,
purchase_date_pst:2013年8月10日3时12分05秒美洲/洛杉矶,
original_purchase_date:2013年8月6日18时58分04秒ETC / GMT,
original_purchase_date_ms:1375815484000},
latest_expired_receipt_info:
{original_purchase_date_pst:2013年8月6日11时58分04秒美洲/洛杉矶,
唯一标识符: ' - - - -',
original_transaction_id:' - ',
expires_date:1376129825000,
TRANSACTION_ID:' - ',
量:'1',
PRODUCT_ID:'认购',
ITEM_ID:' - ',
出价:com.-',
unique_vendor_identifier:' - ',
web_order_line_item_id:' - ',
bvrs:'2.0',
expires_date_formatted:2013年8月10日10时17分05秒ETC / GMT,
购买日期:2013年8月10日10时12分05秒ETC / GMT,
purchase_date_ms:1376129525000,
expires_date_formatted_pst:2013年8月10日3时17分05秒美洲/洛杉矶,
purchase_date_pst:2013年8月10日3时12分05秒美洲/洛杉矶,
original_purchase_date:2013年8月6日18时58分04秒ETC / GMT,
original_purchase_date_ms:1375815484000},
状态:21006}
使用数组中的第二个元素是latest_receipt_info,但现在它的latest_EXPIRED_receipt_info。这里是文档说什么:
在除了receipt_data字段,响应还可以包括
两个新的领域。 如果用户的订阅是活动的,是
更新由在收货后发生了交易的
服务器发送到App Store,的latest_receipt领域包括
基带64 codeD收到此预订的最后一次续期。
这个新收据上的德$ C $光盘数据也是在提供
latest_expired_receipt_info场。您的服务器可以使用这个新
收到保持最新更新的记录。
块引用>所以,如果因为我的服务器上次检查子不断被刷新,去codeD收到更新应该在 latest_expired_receipt_info 。在该对象的expires_date是一样的原始收据的expires_date
什么是地狱?我只是想检查,如果子处于活动状态。用简单的话我怎么做,任何人都可以解释一下吗?
感谢您!
解决方案我的经验。让我们假设,我们总是发送初次领取苹果的服务器。
在任何情况下,你至少有两个领域获得JSON:
状态
(无评论)和收据
(约收货信息,您已经发送)。此外到:
1)如果订阅的仍然活跃的,你会得到额外
latest_receipt
(基于64位带codeD字符串)和latest_receipt_info
(关于收货信息)。2)如果订阅的已经过期的,你会得到额外
latest_expired_receipt_info
(约合最后更新收货信息)。是的,你会得到关于它的唯一信息,没有采用base64恩codeD字符串。是的,据我所知,这不是任何地方记录。希望有所帮助。
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:
- 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.
- 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 }
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:
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.
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.
What the hell? I just want to check if the sub is active. Can anyone explain in simple words how do I do that?
Thank you!
解决方案My experience. Let's assume, we always send initial receipt to Apple's server.
In any case, you'll get JSON with at least two fields:
status
(no comments) andreceipt
(information about receipt that you've send).Additionally to that:
1) If the subscription is still active, you'll additionally get
latest_receipt
(base64-encoded string) andlatest_receipt_info
(information about that receipt).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.And yes, AFAIK, that's not documented anywhere. Hope that helps.
这篇关于如何检测和验证更新为自动再生订阅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!