如何检查订阅项目的到期时间 [英] How to check the expiration for subscription items

查看:258
本文介绍了如何检查订阅项目的到期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IabHelper的QueryInventoryFinishedListener尚未返回过期的订阅项目.

QueryInventoryFinishedListener of IabHelper has not returned the expired subscription items.

另一方面,Google Play帐单库的PurchaseHistoryResponseListener似乎收到了所有购买的物品,其中包括过期的物品.

On the other hand, PurchaseHistoryResponseListener of Google Play Billing Library seems to receive all purchased items, which is including expired items.

在Google Play结算库中,我们必须检查PurchaseHistoryResponseListener的购买日期以及商品的每个到期日期?

On Google Play Billing Library, we have to check the purchased date of PurchaseHistoryResponseListener and each expiration date of items?

推荐答案

queryPurchases与queryPurchaseHistoryAsync

通常,我们应该使用queryPurchases(String skuType),它不会返回过期的项目. queryPurchaseHistoryAsync返回启用和禁用的项目,如您所见,如下所示.

queryPurchases vs queryPurchaseHistoryAsync

Generally, we should use queryPurchases(String skuType), which does not returns expired items. queryPurchaseHistoryAsync returns enabled and disabled items, as you see the documentation like following.

queryPurchases

获取您在应用内购买的所有商品的购买详细信息.此方法使用Google Play商店应用的缓存,而无需启动网络请求.

Get purchases details for all the items bought within your app. This method uses a cache of Google Play Store app without initiating a network request.

queryPurchaseHistoryAsync

返回用户为每个SKU进行的最新购买,即使该购买已过期,取消或消耗.

Returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.

关于queryPurchaseHistoryAsync

我无法显示出queryPurchaseHistoryAsync的用例.如果需要使用queryPurchaseHistoryAsync,则需要实现检查其是否过期.

About queryPurchaseHistoryAsync

I could not image the use case for queryPurchaseHistoryAsync. If we need to use queryPurchaseHistoryAsync, we need the implementation to check if it is expired or not.

  private PurchaseHistoryResponseListener listener = new PurchaseHistoryResponseListener() {
    @Override
    public void onPurchaseHistoryResponse(int responseCode, List<Purchase> purchasesList) {
      for (Purchase purchase : purchasesList) {
        if (purchase.getSku().equals("sku_id")) {
          long purchaseTime = purchase.getPurchaseTime();
          // boolean expired = purchaseTime + period < now
        }
      }
    }
  };

购买对象没有期间的信息,因此上述期间必须从BillingClient.querySkuDetailsAsync获取或进行硬编码.以下是使用querySkuDetailsAsync的示例实现.

Purchase object does not have the information of period, so the above period must be acquired from BillingClient.querySkuDetailsAsync or be hard-coded. The following is sample implementation to use querySkuDetailsAsync.

    List<String> skuList = new ArrayList<>();
    skuList.add("sku_id");
    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(skuList).setType(BillingClient.SkuType.SUBS);
    billingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
      @Override
      public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
        if (skuDetailsList == null) {
          return;
        }
        for (SkuDetails skuDetail : skuDetailsList) {
          if (skuDetail.getSku().equals("sku_id")) {
            String period = skuDetail.getSubscriptionPeriod();

          }
        }
      }
    });

这篇关于如何检查订阅项目的到期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆