gpt4 book ai didi

Android 应用内购买同一类型产品的多种类型订阅

转载 作者:行者123 更新时间:2023-11-29 01:23:12 25 4
gpt4 key购买 nike

在这里,我正在为多种类型的订阅实现 Google 的应用内购买,即 monthlyquarterlyhalf-yearly每年一次。我为每个非托管或非托管订阅类型创建了 SkewId。这些订阅包适用于相同类型的工作。但是现在我想知道我怎么知道付款后订阅的订阅天数?

我将托管类型的代码实现为:

 mHelper = new IabHelper(this, base64EncodedPublicKey);
// enable debug logging (for a production application, you should set
// this to false).
mHelper.enableDebugLogging(true);
mHelper.startSetup(new
IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d("TAG", "In-app Billing setup failed: " +
result);
} else {
Log.d("TAG", "In-app Billing is set up OK");
}
}
});
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
Purchase purchase) {
if (result.isFailure()) {
// Handle error
Log.d("TAG", "We have gas. Consuming it.");
remove_ads_btn_monthly.setEnabled(true);
remove_ads_btn_quarterly.setEnabled(true);
remove_ads_btn_halfyearly.setEnabled(true);
remove_ads_btn_yearly.setEnabled(true);
if (plan_duration != 1)
toast = new CustomToast(RemoveAdsActivity.this, "You've already subscribed package of " + plan_duration + " months.");
else
toast = new CustomToast(RemoveAdsActivity.this, "You've already subscribed package of " + plan_duration + " month.");

return;
} else if (purchase.getSku().equals(SKU_MONTHLY)) {
consumeItem();
remove_ads_btn_monthly.setEnabled(false);
remove_ads_btn_quarterly.setEnabled(false);
remove_ads_btn_halfyearly.setEnabled(false);
remove_ads_btn_yearly.setEnabled(false);
} else if (purchase.getSku().equals(SKU_HALF_YEARLY)) {
consumeItem();
remove_ads_btn_monthly.setEnabled(false);
remove_ads_btn_quarterly.setEnabled(false);
remove_ads_btn_halfyearly.setEnabled(false);
remove_ads_btn_yearly.setEnabled(false);
} else if (purchase.getSku().equals(SKU_QUARTERLY)) {
consumeItem();
remove_ads_btn_monthly.setEnabled(false);
remove_ads_btn_quarterly.setEnabled(false);
remove_ads_btn_halfyearly.setEnabled(false);
remove_ads_btn_yearly.setEnabled(false);
} else if (purchase.getSku().equals(SKU_ANNUALY)) {
consumeItem();
remove_ads_btn_monthly.setEnabled(false);
remove_ads_btn_quarterly.setEnabled(false);
remove_ads_btn_halfyearly.setEnabled(false);
remove_ads_btn_yearly.setEnabled(false);
}

}
};

public void consumeItem() {
mHelper.queryInventoryAsync(mReceivedInventoryListener);
}

IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {

Purchase gasMonthly = inventory.getPurchase(SKU_MONTHLY);
Purchase gasYearly = inventory.getPurchase(SKU_ANNUALY);
Purchase gasQuarterly = inventory.getPurchase(SKU_QUARTERLY);
Purchase gasHalfYearly = inventory.getPurchase(SKU_HALF_YEARLY);
if (gasMonthly != null) {
mHelper.consumeAsync(inventory.getPurchase(SKU_MONTHLY), mConsumeFinishedListener);
mSubscribedTo = true;
} else if (gasYearly != null) {
mHelper.consumeAsync(inventory.getPurchase(SKU_ANNUALY), mConsumeFinishedListener);
mSubscribedTo = true;
} else if (gasQuarterly != null) {
mHelper.consumeAsync(inventory.getPurchase(SKU_QUARTERLY), mConsumeFinishedListener);
mSubscribedTo = true;
} else if (gasHalfYearly != null) {
mHelper.consumeAsync(inventory.getPurchase(SKU_HALF_YEARLY), mConsumeFinishedListener);
mSubscribedTo = true;
} else {
mSubscribedTo = false;
}
}
};
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase,
IabResult result) {

if (result.isSuccess()) {
//API
remove_ads_btn_monthly.setEnabled(true);
remove_ads_btn_quarterly.setEnabled(true);
remove_ads_btn_halfyearly.setEnabled(true);
remove_ads_btn_yearly.setEnabled(true);
} else {
// handle error
}
}
};

现在,我想知道如何自定义我的代码以支付每种类型的订阅,如图所示。当时间段结束时,每个订阅都应该自行激活。

谢谢。

最佳答案

您有两种选择可以将购买时间存储在服务器上(然后在您的应用中使用当前时间对其进行验证)或使用 googleplay androidpublisher api .

在响应中您将获得 PurchasedTime。

{
"kind": "androidpublisher#productPurchase",
"purchaseTimeMillis": long,
"purchaseState": integer,
"consumptionState": integer,
"developerPayload": string
}

Android : inApp purchase receipt validation google play

Android : inApp purchase receipt validation (Part 2)

除此之外..您需要检查查询库存中的每个 SKU(您只消费每月)。

    IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {


Purchase gasMonthly = inventory.getPurchase(SKU_MONTHLY);
Purchase gasYearly = inventory.getPurchase(SKU_YEARLY);
if (gasMonthly != null) {
mHelper.consumeAsync(inventory.getPurchase(SKU_MONTHLY), mConsumeFinishedListener);
mSubscribedTo = true;
} else if (gasYearly != null) {
mHelper.consumeAsync(inventory.getPurchase(SKU_YEARLY), mConsumeFinishedListener);
mSubscribedTo = true;
} else {

mSubscribedTo = false;
}

编辑:

how I can know that the subscription days, subscribed packaged after payment?

您将在 mPurchaseFinishedListener/mGotInventoryListener 上获取购买的 sku 项目,将其保存在 sharedpreferences 或服务器上。

用于天数验证。您将从购买中获得购买时间。使用 purchase.getPurchaseTime() 购买,您必须将其存储在本地应用程序或查询购买的 sku 以每次获取时间。

关于Android 应用内购买同一类型产品的多种类型订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35578003/

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