Google Play Developer API - 为什么在用户执行重新订阅时找不到 linkedPurchaseToken?

Google Play Developer API - Why linkedPurchaseToken is not found when user perform resubscribe?

在我们的后端服务器中,当用户

  1. 取消订阅。
  2. 几天后再重新订阅。

我们必须知道,旧购买令牌和新购买令牌都指的是同一个用户。

原因是,之前,用户已经使用旧的已取消订阅购买令牌在服务器中创建了一些数据。

当用户取消订阅并再次重新订阅时,我们希望确保用户仍然有权使用新的购买令牌访问旧数据。

我们预计我们可以从 linkedPurchaseToken 获取信息,其中新的购买令牌将指向旧的购买令牌。

这在https://medium.com/androiddevelopers/implementing-linkedpurchasetoken-correctly-to-prevent-duplicate-subscriptions-82dfbf7167da

中有描述

然而,根据我们的测试结果,情况并非如此。

Google 玩开发者 API

credentials = service_account.Credentials.from_service_account_file(
    constant.PATH_TO_SERVICE_ACCOUNT_JSON, 
    scopes = constant.SCOPES
)
    
androidpublisher = googleapiclient.discovery.build(
    'androidpublisher', 
    'v3', 
    credentials = credentials
)

product = androidpublisher.purchases().subscriptions().get(
    packageName = "com.xxx.yyy",
    subscriptionId = product_id,
    token = token
).execute()

return product

当前有效订阅

{
   'startTimeMillis':'1619245597271',
   'expiryTimeMillis':'1619246015249',
   'autoRenewing':True,
   'priceCurrencyCode':'SGD',
   'priceAmountMicros':'6980000',
   'countryCode':'SG',
   'developerPayload':'',
   'paymentState':1,
   'orderId':'GPA.3314-4833-2752-47988',
   'purchaseType':0,
   'acknowledgementState':1,
   'kind':'androidpublisher#subscriptionPurchase'
}

之前取消的订阅

{
   'startTimeMillis':'1619244776697',
   'expiryTimeMillis':'1619245074590',
   'autoRenewing':False,
   'priceCurrencyCode':'SGD',
   'priceAmountMicros':'6980000',
   'countryCode':'SG',
   'developerPayload':'',
   'cancelReason':3,
   'orderId':'GPA.3358-9904-1003-13416',
   'purchaseType':0,
   'acknowledgementState':1,
   'kind':'androidpublisher#subscriptionPurchase'
}

我们没有 linkedPurchaseToken 信息。因此,我们无法知道,这两个订阅指的是同一个用户。

在Google Play Console中,即使订单ID不同,也能分辨出订阅来自同一个用户。 然而,没有办法知道,通过 Google Play Developer API 回复。


我们的初步猜测是,这可能是由于 重新订阅 功能未在我们的 Google Play 控制台中启用。

但是,目前,我们所有的生产/测试版/测试版 APK 早已升级到 3.0.1。因此,我们不确定是否存在这样的消息:“您的用户目前无法重新订阅,因为您的应用未在所有活动的 APK 中使用 Billing Library 2.0。”消息。

知道吗,我们如何才能查明最新的活跃订阅和取消的非活跃订阅是否实际上指的是同一个用户?

在原始取消订阅到期之前重新订阅将重新使用相同的购买令牌。原订阅过期后重新订阅视为新购买,因此您将获得全新的购买令牌,并且不会设置 linkedPurchaseToken 字段。链接的购买令牌字段实际上仅为升级和降级流程设置。参见 Purchase Tokens and Order IDs docs

过去,linkedPurchaseToken 是为重新订阅流程设置的,如果您在原始订阅到期之前取消并重新订阅,就会发生这种情况。有了 Resubscribe this is no longer the case. (Note that Medium article has an updated note 这个信息 - 免责声明我是那篇文章的作者)。具体来自重新订阅文档:

A restored subscription uses the same the purchaseToken from when the subscription was cancelled. All cancellation fields are cleared from the resource.

因此不会设置 linkedPurchaseToken。注意:这仅在重新订阅发生在原始订阅到期之前时才会发生。

在您上面提供的购买示例中,在我看来,第二次购买似乎发生在 最初的第一次订阅过期之后。 (新订阅的 'startTimeMillis':'1619245597271' 大于旧订阅的 'expiryTimeMillis':'1619245074590',因此旧订阅已经过期。在这种情况下,新订阅被视为具有全新购买令牌的全新订阅。

针对您关于如何将两次购买联系在一起的问题,答案是您不能按照设计仅使用 Google Play 提供的信息。每个购买令牌及其相关信息均不包含用户身份信息。

但是,当您说“服务器中的数据”是从第一次购买时保存下来的,这让我认为您有一个带有某种用户帐户的后端服务器。在这种情况下,您应该在您的后端服务器上和您自己的代码中将两次购买与特定用户相关联。这是执行此操作的正确方法(请参阅 Classy Taxi sample)。

注意:我注意到 upgrade/downgrade docs 仍然提到过时的重新注册。

对我来说这似乎是一个错误,它不仅不发送 linkedPurchaseToken,而且 obfuscatedExternalAccountIdobfuscatedExternalProfileId 存在于原始购买中。

所以似乎没有办法link重新订阅订阅的用户并授予他们购买的物品。

您可以尝试从 Play 控制台的“订单管理”页面手动link 订单,但这不太实用。

据我所知,唯一的选择似乎是在 Play 控制台的订阅设置页面中禁用“重新订阅”功能。