恢复订阅的丢失购买令牌

the*_*ius 7 java android google-play google-play-developer-api android-inapp-purchase

我现在遇到一个重大问题,我们的服务器是取消订阅用户的应用程序(不是Google Play),并删除我们在成功购买后从Google Play收到的购买代币.我们已经注意到它们不再被删除,但我需要处理我们已经丢失的那些.

所以我的问题是,有没有办法恢复购买令牌?(主要在V2 API中)

dma*_*tra 5

您可以获取令牌和订单ID来解析来自“ getPurchases”的响应

https://developer.android.com/google/play/billing/billing_reference.html#getPurchases

但是,如果您使用TrialDrive Sample中的IabHelper,则更加轻松。 https://github.com/googlesamples/android-play-billing/tree/master/TrivialDrive

在该应用程序中,您可以从购买对象中检索令牌,您可以从其中开始查询库存:

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
           Log.d(TAG, "Query inventory finished.");

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null) return;

            // Is it a failure?
            if (result.isFailure()) {
                Log.d(TAG, "Failed to query inventory: " + result);
                return;
            }

            Purchase premiumMonthly = inventory.getPurchase(SKU_SUSCRIPTION);
            if (premiumMonthly != null && premiumMonthly.isAutoRenewing()) {
                    String token = premiumMonthly.getToken();
                    String orderid = premiumMonthly.getOrderId();

                    Log.d(TAG, token);
                    Log.d(TAG, orderid);
                } 
            }
   ....

    mHelper.queryInventoryAsync(mGotInventoryListener);
Run Code Online (Sandbox Code Playgroud)