gpt4 book ai didi

java - 为订阅找回丢失的购买 token

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:59:22 25 4
gpt4 key购买 nike

我现在遇到了一个主要问题,我们有这样的例子,我们的服务器正在取消用户订阅我们的应用程序(不在 Google Play 中)并删除我们在成功购买后从 Google Play 收到的购买 token 。我们已经照顾好它们不再被删除,但我需要处理我们已经丢失的那些。

所以我的问题是,有什么办法可以恢复购买 token 吗? (主要在 V2 API 中)

最佳答案

您可以从“getPurchases”解析响应获取 token 和订单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

在您的应用程序中,您可以从开始查询 list 时获得的购买对象中检索 token :

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);

关于java - 为订阅找回丢失的购买 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36161390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com