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

标签 android google-play in-app-billing google-play-console google-play-developer-api

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

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

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

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

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

我们希望我们可以从 linkedPurchaseToken 获取信息,其中新的购买 token 将指向旧的购买 token 。

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

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

Google Play 开发者 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 响应知道这一点。

enter image description here


我们的初步猜测是,这可能是因为我们的 Google Play 管理中心未启用重新订阅功能。

enter image description here

但是,目前,我们所有的生产/测试版/测试版 APK 早已升级到 3.0.1。因此,我们不确定是否存在这样的消息:“Resubscribe is not currently available for your users because your app does not use Billing Library 2.0 in all active APKs.”消息。

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

最佳答案

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

过去,linkedPurchaseToken 是为重新订阅流程设置的,如果您在原始订阅到期之前取消并重新订阅,就会发生这种情况。用Resubscribe这已不再是这种情况。 (请注意,Medium 文章有 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',因此旧订阅已经过期。在这种情况下,新订阅被视为具有全新购买 token 的全新订阅。

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

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

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

关于android - Google Play Developer API - 为什么在用户执行重新订阅时找不到 linkedPurchaseToken?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67240094/

相关文章:

安卓工作室Javadoc : Cannot find symbol

android - Google 的应用内计费示例(普通驱动器)的 onActivityResult 方法中存在错误?

Android 应用内计费 queryInventoryAsync 返回 sku 和购买项目大小 0

安卓约束布局 : How to add a dynamic view one below another

java - Android/Java 及多个 "view states"

android - 如何从 Android Play 导出用户评论

Android 应用程序在 Play 商店中显示新版本,但下载旧 APK

android - 跟踪来自Google Play之外的用户的安装?

Android 应用内购买付款后崩溃

java - 使用 Processing 在 Android 中保存现有的 CSV 文件