如何确定用户是否取消 Google Play 订阅?

How to determine if user cancels Google Play subscription?

即将在我们的 Android 应用程序中构建订阅产品,但不太清楚了解已取消订阅的最佳方式。我们计划让用户取消的唯一方法是让他们去 Google Play 商店并明确取消,但在这种情况下,我们的后端不会收到通知。

Google Play Developer API 文档明确表示您不能查询 API 所有订阅的状态,所以我们怎么知道哪些用户取消了他们的订阅?

非常感谢任何帮助!

根据应用内订阅文档,没有机制可以检测用户何时取消订阅。因为它不会立即取消。相反,它等待订阅到期的周期结束。

文档摘录 (source)

When the user cancels a subscription, Google Play does not offer a refund for the current billing cycle. Instead, it allows the user to have access to the canceled subscription until the end of the current billing cycle, at which time it terminates the subscription. For example, if a user purchases a monthly subscription and cancels it on the 15th day of the cycle, Google Play will consider the subscription valid until the end of the 30th day (or other day, depending on the month)

当用户取消订阅时,该应用不会收到任何通知。

订阅的行为是每当您在应用程序中查询库存时,如果订阅有效,将返回SKU。订阅到期后查询库存时将不会返回SKU。

根据此 link

中的文档

可以在订阅接近尾声时运行批量查询

摘自文档 (source):

Query for subscription status only at expiration — Once your server has retrieved the expiration date of subscription tokens, it should not query the Google Play servers for the subscription status again until the subscription is reaching or has passed the expiration date. Typically, your servers would run a batch query each day to check the status of expiring subscriptions, then update the database

以下服务器api让您查询订阅状态:

https://developers.google.com/android-publisher/api-ref/purchases/subscriptions#resource-representations

如果订阅已取消,变量 autoRenewingcancelReason 会通知您。

通过使用上述 API,您将能够实现一个系统,其中可以查询即将到期的订阅的状态,然后确定它们是否被取消。

有关取消订阅的完整详细信息,请参阅此 link

注:
文档指出,只要用户订阅有效,您就应该继续提供内容。如果您计划在有人取消订阅时拒绝访问内容,将违反 Google 政策

文档摘录 (source)

Important: In all cases, you must continue to offer the content that your subscribers have purchased through their subscriptions, as long any user is able to access it. That is, you must not remove any content while any user still has an active subscription to it, even if that subscription will terminate at the end of the current billing cycle.

现在似乎可以接收有关订阅更改(续订、取消...)的服务器端通知:

The In-app Billing API provides server push notifications that give developers the capability to monitor state changes for Play-managed subscriptions.

有关详细信息,请参阅此页面:https://developer.android.com/google/play/billing/billing_subscriptions.html#realtime-notifications