Android - 如何检查订阅是否续订?

标签 android in-app-purchase in-app-billing

我有一个 Android 应用程序,可以按月续订。在此应用中,我想在下个月继续订阅时通知用户一些信息。

我可以在商家中心看到续订(orderId 以 eg..0, ..1 结尾),但是在查询库存时,我的采购订单 Id 与 befor eq 相同。

{
    "orderId": "GPA.XXXX-YYYY-XXXX-ZZZZZ",
    "packageName": "my.packageName",
    "productId": "my.sku",
    "purchaseTime": 1456398623654,
    "purchaseState": 0,
    "developerPayload": "mypayload",
    "purchaseToken": "token",
    "autoRenewing": true
}

更让我困扰的是 purchaseTime 也没有改变。

所以我的问题是:是否有任何方法可以在应用程序中检测到发生了续订?

编辑:

我正在使用 Google Play Developer API 获取订阅信息,然后自己计算续订次数。

最佳答案

所有重复的订单 ID 在 INAPP_PURCHASE_DATA JSON 字段(在 V3 中)的 orderId 字段中返回,每个重复交易都附加一个整数。

Subscription order numbers

To help you track transactions relating to a given subscription, Google payments provides a base Merchant Order Number for all recurrences of the subscription and denotes each recurring transaction by appending an integer as follows:

GPA.1234-5678-9012-34567 (base order number)
GPA.1234-5678-9012-34567..0 (first recurrence orderID)
GPA.1234-5678-9012-34567..1 (second recurrence orderID)
GPA.1234-5678-9012-34567..2 (third recurrence orderID) ...

但由于 local caching,您可能无法获得最新信息。因此,请尝试从应用程序管理器中清除缓存以首先查看您是否获得了正确的购买信息。

由于这种方式的购买查询不可靠,从后端调用 Google Play 开发者 Purchases.subscriptions: get API 以获取 Purchases.subscriptions resource 更有意义,它将返回当前订阅的 expiryTimeMillis

{
  "kind": "androidpublisher#subscriptionPurchase",
  "startTimeMillis": long,
  "expiryTimeMillis": long,
  "autoRenewing": boolean,
  "priceCurrencyCode": string,
  "priceAmountMicros": long,
  "countryCode": string,
  "developerPayload": string,
  "paymentState": integer,
  "cancelReason": integer
}

关于Android - 如何检查订阅是否续订?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36591498/

相关文章:

android - 无法使用测试帐户 "The publisher cannot purchase this item"进行 Android 应用内购买

ios - Apple Pay iOS Swift 申请优惠券

android - 如何在服务器端使用开发者的公钥验证购买是否正确签名将使应用程序更安全?

android - IAB 助手未设置。无法执行操作 : queryInventory

android - MPAndroidChart 起始条在 0 以外的其他地方

java - 使用 Apache Commons FTP 库在 Android 上通过 FTP 下载目录

android - 应用内计费 (v3) - 了解空指针异常

java - 如何获取设备原始宽度和高度或实际屏幕宽度和高度?

android - 如何缩放相机以覆盖android googlemap中的路径?

java - Android 计费 - 在 production/alpha/beta 中使用 android.test.purchased 测试购买