android - Google Play 结算 - sku android.test.purchased 的签名验证失败

标签 android in-app-billing

编辑:因为有些人仍在检查这个线程,我想提一下,这是非常过时的,因为它是关于应用程序购买中的 v2,现在已弃用。请查看latest (目前是 v3)文档,非常简单

关于这个问题有很多话题,我想我理解这个问题,但是,目前我无法测试真实的购买,因为我目前没有有效的信用卡,谷歌接受,只有大师,这是不被接受的。这就是我寻求帮助的原因(不是购买验证,而是验证我的思维过程是否良好)。

首先,问题来自于新的 verifyPurchase 方法。新方法检查签名,应该没问题。但是,Google 没有为测试 ID 提供任何签名,例如 android.test.purchased。这导致下面的方法总是失败,并且它总是在验证时返回false,即使假购买已经完成,并且我有一个确认对话框,购买确实成功了。方法:

public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) {
    //if(BuildConfig.DEBUG) return true;

    if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey) ||
            TextUtils.isEmpty(signature)) {
        Log.e(TAG, "Purchase verification failed: missing data.");
        return false;
    }

    PublicKey key = Security.generatePublicKey(base64PublicKey);
    return Security.verify(key, signedData, signature);
}

问题来自 TextUtils.isEmpty() 检查,因为签名将为空,代码将返回 false。我的临时测试解决方法在代码中,已注释掉。如果我在测试方法的开头添加 if(BuildConfig.DEBUG) return true; ,一切正常,用户可以启动并运行高级功能,所以问题确实是关于签名。

另一个问题是,如果我购买了 android.test.purchased,我无法查询用户的库存,所以我无法确定我的检查器方法是否检查用户是否已购买高级功能,有效。

我的两个问题:

如果我从 verifyPurchase 中删除 if(BuildConfig.DEBUG) return true; 行,并替换 android.test.purchased id使用我提供的真实 SKU 的真实 ID,我可以确定在我的情况下一切都会正常工作吗?我再说一遍,添加调试功能后一切正常。如果您需要查看更多代码,请告诉我!

下面的方法检查用户是否购买了高级功能,如果他/她购买了,那么它会设置相应的首选项,否则,如果有任何问题,它会保持原样。这种方法是否正确?我在 Application 类中执行此操作,在每个应用程序启动时,以防止修补。

private void checkPremium()
{
    //get the helper up and running
    final IabHelper helper=new IabHelper(INSTANCE, getBase64Key());
    helper.startSetup(new IabHelper.OnIabSetupFinishedListener()
    {
        @Override
        public void onIabSetupFinished(IabResult result)
        {
            //if the helper is in a correct state, check the inventory
            if(result.isSuccess())
            {
                helper.queryInventoryAsync(new IabHelper.QueryInventoryFinishedListener()
                {
                    @Override
                    public void onQueryInventoryFinished(IabResult result, Inventory inv)
                    {
                        //if the inventory is reachable, check if we got the premium
                        if(result.isSuccess())
                        {
                            setPremium(inv.hasPurchase(ActWidgetSearch.SKU));
                        }
                    }
                });
            }
        }
    });
}

提前致谢!

最佳答案

几天前我遇到了和你一样的问题。对于那些从 Google Play 下载您的实时应用程序的人,如果测试 ID(“android.test.purchased”)如您所说的那样工作,他们将能够购买您的应用程序内购买。 Google Play 将其视为“真实购买”,并且通过与您的个人 SKU 相同的 channel 。见下文:

Test Purchases (In-app Billing Sandbox)

Once authorized with testing access, those users can side-load your app and test the full merchandising, purchase, and fulfillment flow for your products. Test purchases are real orders and Google Play processes them in the same way as other orders. When purchases are complete, Google Play prevents the orders from going to financial processing, ensuring that there are no actual charges to user accounts, and automatically canceling the completed orders after 14 days.

http://developer.android.com/google/play/billing/billing_testing.html#test-purchases

我现在刚刚测试了我自己的个人 SKU,我可以肯定地说它们正在发挥作用! (我在我的 Google Merchant 帐户中看到了订单)。所以出去走走,赚点钱:)

旁注,开发人员对开发人员...您能否向我展示有关如何在 Application 类中运行我的购买验证的任何示例或教程链接?我认为这是我绝对想从你那里窃取的想法。干杯!

关于android - Google Play 结算 - sku android.test.purchased 的签名验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22657519/

相关文章:

java - Android in app billing - 如何知道哪些用户购买了产品

android - NoSuchMethodError :com. android.app.fragment getContext 在 android

android - cpuminer Android 中的 Curl 库

android - 更新后应用内计费不起作用 - Google 商店

java - querySkuDetailsAsync 正在返回带有 BillingResult 代码 SERVICE_UNAVAILABLE 的空列表

java - Play Billing Library v1.0 订单状态

android - 从 sleep 模式恢复时保留 GridView

android - 在 Flutter 项目中获取 iOS 和 Android 的 AdMob 测试设备 ID

android imageview 在 xml 中设置的色调以编程方式覆盖在 DrawableCompat 上设置的色调

android - 在 Android Market 购买产品一段时间(应用内结算)