应用内自动续订订阅

发布于 2024-10-24 04:00:36 字数 1194 浏览 1 评论 0原文

很抱歉问到有关 iTunes 订阅的第一百万个问题,但我仍然有一些疑问。

基本上我正在我的应用程序中实现自动续订订阅,我想确保我做对了。以下是我提出的要采取的步骤列表:

  • 每当用户购买订阅时,将收据发送到服务器以验证它
    • 如果收据有效,请将其保存到数据库
  • 则在应用程序加载时将其保存在数据库中,询问服务器是否存在此 UDID 的收据(这是为了确定用户是否有有效的订阅)
    • 如果是,请检查从订阅开始日期到到期日期的日期范围内商店中是否添加了新商品
      • 如果有,请以某种方式通知用户这些项目并将其标记为可免费下载

这些步骤是否正确?如果是这样,为什么苹果文档说:

<块引用> <块引用>

在大多数情况下,您的 iOS 客户端应用程序不需要更改。事实上,您的客户端应用程序现在变得更加简单,因为您可以使用与恢复非消耗产品相同的代码来恢复自动更新订阅。这在“恢复交易”中进行了描述。您的应用程序在订阅续订的每个时间段都会收到单独的交易;您的应用程序应单独验证每张收据。

对我来说,这似乎需要一些代码来处理我提到的所有各种情况。或者我完全错了。我是吗?

另外,我如何知道订阅到期日期?我无法找到在任何地方获取此信息的方法。我应该将其保存在我自己的数据库中吗?

更新:

自从我发布这个问题以来,我已经弄清楚了一些事情。如果我错了,请随时纠正我。

首先,我想我应该将订阅的长度存储在我自己的数据库中的某个位置,因为正如苹果文档中所述,您无法通过苹果的网络服务以任何方式检索它。事实上,每个订阅长度都有不同的产品标识符,因此您应该有一种方法将产品标识符转换为订阅长度。

此外,Sylvian 发布了有关他实施自动续订订阅的详细信息,所以至少我知道我的想法没有太大缺陷。

现在唯一的问题是:我如何知道用户有有效的订阅?我可以将此信息存储在我的服务器上,是的,但是如何将用户与已完成的交易关联起来?我应该保存设备的 UDID 吗?

Sorry for the millionth question about iTunes subscriptions, but I still have a few doubts.

Basically I'm implementing auto-renewable subscriptions in my app and I want to make sure I got it right. Here's a list of steps to take that I came up with:

  • whenever an user buys a subscription, send the receipt to the server to validate it
    • if the receipt is valid, save it on the database
  • on application load, ask the server if a receipt for this UDID exists (this is to figure out if the user has a valid subscription)
    • if so, check if a new item has been added on the store in a date range from the subscription start date to the expire date
      • if any, notify the user about those items in some way and mark them as freely downloadable

Are these steps correct? And if so, why does the Apple doc say:

In most cases, your iOS client application should not need to change. In fact, your client application is now made simpler, as you can use the same code to recover auto-renewable subscriptions as you do to recover nonconsumable products. This is described in “Restoring Transactions.”Your application receives a separate transaction for each period of time where the subscription was renewed; your application should verify each receipt separately.

To me it looks like this needs some code to handle all the various cases I mentioned, instead. Or I'm totally wrong about it. Am I?

Plus, how do I know about the subscription expiration date? I can't find a way to get this information anywhere. Am I supposed to save this on my own database?

Update:

I've figured out a few things since I posted this question. Feel free to correct me if I'm wrong.

First of all I guess I'm supposed to store the length of the subscription somewhere on my own database, because as stated on Apple's docs, you cannot retrieve it in any way through Apple's web services. In fact, each subscription length has a different product identifier, so you should have a way to convert a product identifier to a subscription length.

Also, Sylvian has posted details about his implementation of auto-renewable subscriptions, so at least I know my thinking wasn't too much flawed.

Now the only problem is this: how do I know that an user has a valid subscription? I could store this information on my server, yeah, but how do I associate an user with a completed transaction? Should I save the device's UDID?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

转身泪倾城 2024-10-31 04:00:36

以下是我们如何实施应用内购买,特别是我公司的新自动更新产品。

应用程序将交易收据传输到我们的网络服务,如果处理正确,我们会向应用程序返回 OK,并且 Apple 可以验证它。在这种情况下,我们更新了用户帐户(即数据库)以表示“是的,他已付款,并且他的订阅在收据到期日期之前有效”。

在此 Web 服务确定后,应用程序通过另一个 Web 服务重新加载帐户信息,并查看是否有有效的订阅。就是这样......直到自动再生产品出现。

我们现在必须实现一些每天运行的 CRON 作业:每天我们都会列出应该过期的通行证列表,然后我们询问 Apple 原始收据是否仍然有效:神奇的是,在他们的回答中,有嵌入最新收据的字段latest-receipt。如果它与我们拥有的不同,我们就会知道订阅已自动续订,我们会存储最新的收据以供下一次 cron 检查,并更新用户帐户以延长到期日期。

希望有帮助。

Here is how we implemented In App Purchases and specifically the new auto-renewable products at my company.

The application transmits the transaction receipt to our webservice, we return OK to the application if we handled it correctly and Apple could verify it. In that case we updated the user account (i.e. the database) to say "yes he has paid and his subscription is valid till the receipt expiration date".

After the OK for this webservice, the application reloads the account info through another webservice, and see there is a valid subscription. That was it... Until auto-renewable products appeared.

We now had to implement some CRON jobs which runs every day: every day we make a list of passes which are supposed to expire, and we ask Apple if the original receipt is still valid: the magic thing is that in their answer, there is a field latest-receipt which embeds the latest receipt. If it is not the same as the one we have, we understand that the subscription has been renewed automatically, we store the latest receipt for the next cron check, and we update the user account to extend the expiration date.

Hope it helps.

浮萍、无处依 2024-10-31 04:00:36

我想我找到了解决方案。它不需要额外的用户名/密码,而且似乎可以正常工作。

注意:如果您认为此内容不合适,请在评论中解释原因。谢谢。

基本上,每当用户购买订阅时,我都会根据服务器验证收据并将收据数据存储在用户默认值中。然后,当应用程序打开时,或者每当我需要检查订阅是否仍然有效时,我都会从用户默认值中检索之前保存的收据数据,并针对服务器进行验证。

我的网络服务仅返回订阅是否仍然有效或已过期,以及一些其他相关信息,例如订阅长度。为此,它只需像往常一样查询 iTunes 服务器,并检查状态响应是否非零。 21006 表示订阅已过期。

I think I found a solution. It doesn't require an additional username/password and it seems to be working.

Note: If you think this is inappropriate, please explain why in the comments. Thanks.

Basically, whenever an user buys a subscription, I validate the receipt against my server and store the receipt data in the user defaults. Then, when the app is opened, or whenever I need to check if the subscription is still valid, I retrieve the previously saved receipt data from the user defaults and validate it against the server.

My webservice just returns whether the subscription is still valid or has expired, plus some other related information such as the subscription length. To do this, it just queries the iTunes server as usual, and checks if the status response is nonzero. 21006 means that the subscription has expired.

油饼 2024-10-31 04:00:36

如果您的应用程序有一些用户管理,即您使用用户名/密码来使用该应用程序,那么您必须维护一个服务器来记录当前登录用户的购买/有效性。这适用于正常订阅和非消耗品购买。但是...如果您使用新的自动续订订阅,则无法在该应用程序中维护多个用户,因为:这种购买不能在订阅期内使用同一 Apple ID 多次完成我发现它真的很烦人,并为这种情况找到了更好的解决方案,即我在应用程序中有多个子帐户,但我想使用相同的 Apple-Id 为每个帐户购买自动续订订阅。我想我必须使用旧的订阅模式。有什么新想法吗?

If your app has some user management i.e. you use username/password to use the app, then you have to maintain a server to record the purchase/validity of the currently logged in user. This is applicable for normal subscription and non-consumable purchase. But... if you use the new auto-renewable subscription, then it's NOT possible to maintain multiple user in that app, because : this kind of purchase can not be done multiple times within the subscription period using the same Apple ID from the same application and I found it really annoying and finding a better solution for this case i.e where I have multiple child account in the app but I want to use the same Apple-Id to purchase a auto-renewable subscription for each account. And I think I have to use the old subscription model. Any new thoughts ?

空城旧梦 2024-10-31 04:00:36

据我了解,苹果服务器将联系您(或使用 iPhone 的客户)并告诉您“看这里,我为您提供了有效的购买”​​。在您的应用程序中,您阅读此消息并解锁相关内容以供使用。下一步是告诉苹果服务器你已经回复了回执,苹果服务器不会再显示该消息。

因此,通过可更新的订阅,您每个周期都会收到一条新消息。如果我错了,请纠正我。

as far as I have understand it the apple server will contact you (or the customer with his iPhone) and tell "look here I have a valid purchase for you". Inside your App you read this message and unlock the regarding content for use. The next step is to tell the apple server that you have responded to the receipt and the apple server will not show the message again.

So with a renewable subscription you get for each period a new message. Correct me if I'm wrong, please.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文