为订阅找回丢失的购买令牌
Recover lost purchase token for a subscription
我现在遇到了一个大问题,我们有这样的情况,我们的服务器正在取消用户订阅我们的应用程序(不在 Google Play 中)并删除我们从 Google 收到的购买令牌购买成功后播放。我们已经照顾好它们不再被删除,但我需要处理我们已经丢失的那些。
所以我的问题是,有什么办法可以恢复购买令牌吗? (主要在 V2 API 中)
您可以通过解析来自 'getPurchases'
的响应来获取令牌和订单 ID
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);
我现在遇到了一个大问题,我们有这样的情况,我们的服务器正在取消用户订阅我们的应用程序(不在 Google Play 中)并删除我们从 Google 收到的购买令牌购买成功后播放。我们已经照顾好它们不再被删除,但我需要处理我们已经丢失的那些。
所以我的问题是,有什么办法可以恢复购买令牌吗? (主要在 V2 API 中)
您可以通过解析来自 'getPurchases'
的响应来获取令牌和订单 IDhttps://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);