简体   繁体   English

android在app结算购买验证失败

[英]android in app billing purchase verification failed

i' having trouble implementing in app billing in my android app. 我在我的Android应用程序中实现应用程序计费时遇到问题。 i'm getting a purchase signature verification failed. 我收到购买签名验证失败。 In a first time i tough it was the base64 key but i checked it many times and i'm still getting the error, then after i took a look at the Security.java file and i found this method which i edited for get some informations about what was wrong: 在第一次我很难,它是base64键,但我检查了很多次,我仍然得到错误,然后我看了一下Security.java文件,我发现这个方法,我编辑得到一些信息关于什么是错的:

    public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) {
    if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey) ||
            TextUtils.isEmpty(signature)) {
        if(TextUtils.isEmpty(signedData)) Log.d(TAG, "SIGNED DATA EMPTY");
        if(TextUtils.isEmpty(base64PublicKey)) Log.d(TAG, "KEY IS EMPTY");
        if(TextUtils.isEmpty(signature)) Log.d(TAG, "SIGNATURE IS EMPTY");
        Log.e(TAG, "Purchase verification failed: missing data.");
        return false;
    }

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

And i'm getting "signature is empty". 我得到“签名是空的”。 Even after i follow the steps below: -Sign the apk with my release key -upload it as a draft -install it on a device with "adb -d install app.apk" 即使我按照以下步骤操作: - 使用我的发布密钥设置apk - 将其作为草稿添加 - 在设备上安装“adb -d install app.apk”

I'm testing with real purchases. 我正在测试真实购买。 Thanks. 谢谢。

Edit The purchase flow is fine, i get the error when i call queryInventoryAsync 编辑购买流程很好,我在调用queryInventoryAsync时收到错误

You can use the test SKU's to do testing, as explained here . 您可以使用测试SKU进行测试, 如此处所述 These are: 这些是:

  • android.test.purchased
  • android.test.canceled
  • android.test.refunded
  • android.test.item_unavailable

These purchases will be successful (at least the android.test.purchased) even in test and debug scenario's, without the need to cancel the purchase. 即使在测试和调试方案中,这些购买也将成功(至少是android.test.purchased),而无需取消购买。

In the verifyPurchase I changed return false to: 在verifyPurchase中我将return false更改为:

    Log.e(TAG, "Purchase verification failed: missing data.");
    if (BuildConfig.DEBUG) {
            return true;
    }
    return false;           

but you should be aware to use this only in test scenario's. 但是你应该知道只在测试场景中使用它。

This will return true, if you have a debug build, and the signature data is missing. 如果您有调试版本,则返回true,并且缺少签名数据。 Since the BuildConfig.DEBUG will be false in a production build this should be OK. 由于BuildConfig.DEBUG在生产版本中将为false,因此应该没问题。 But better is to remove this code after everything is debugged. 但更好的是在调试完所有内容后删除此代码。

Replace your verifyPurchase() method with below one. verifyPurchase()方法替换为下面的方法。 Use old code that given below, google developer are trying to solve this error in the near future but before they updated their code you should prefer below code. 使用下面给出的旧代码,谷歌开发人员试图在不久的将来解决此错误,但在他们更新代码之前,您应该更喜欢下面的代码。

 public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) {
              if (signedData == null) {
                Log.e(TAG, "data is null");
                return false;
            }

            boolean verified = false;
            if (!TextUtils.isEmpty(signature)) {
                PublicKey key = Security.generatePublicKey(base64PublicKey);
                verified = Security.verify(key, signedData, signature);
                if (!verified) {
                    Log.w(TAG, "signature does not match data.");
                    return false;
                }
            }
            return true;
        }

check this link for more information: 查看此链接以获取更多信息:

In App billing not working after update - Google Store 更新后的应用结算中无法使用 - Google商店

Use try to replace OLD CODE method verifyPurchase() method in your project. 使用try替换项目中的OLD CODE方法verifyPurchase()方法。 But It should be only happens when you are trying to purchase test products. 但它应该只在您尝试购买测试产品时才会发生。 Let me know for the real products purchase also after using this code. 使用此代码后,请告知我购买的真实产品。

Edit: 编辑:

Why it happens because we will not get any signature while we are using dummy product like "android.test.purchased". 为什么会发生这种情况,因为我们在使用像“android.test.purchased”这样的虚拟产品时不会获得任何签名。 So in the old code it is working good because we were return true even if signature is not given and for the New code we are returning false. 因此,在旧代码中,它工作正常,因为即使没有给出签名我们也返回true,而对于新代码我们返回false。

more information about the signature data null or blank from link1 and link2 有关签名数据的更多信息null或来自link1和link2的空白

So I suggest you just replace old code method verifyPurchase() instead of New Code method. 所以我建议你只需要替换旧代码方法verifyPurchase()而不是New Code方法。

I think may be New Code will work fine for the real product but not in the dummy product. 我认为新代码可能适用于真实产品,但不适用于虚拟产品。 But yet I have not tested for the real product. 但我还没有测试过真正的产品。

or 要么

use GvS's answer for the test purchases it also the good solution for the new code. 使用GvS的测试购买答案它也是新代码的好解决方案。

Hope it will solve your problem. 希望它能解决你的问题。

Make sure that you are logged in with the right user on your phone or eg add your phone's google account as a test user in the developer console. 确保您使用手机上的合适用户登录,或者在开发者控制台中以测试用户身份添加手机的Google帐户。

http://developer.android.com/google/play/billing/billing_testing.html#billing-testing-static : http://developer.android.com/google/play/billing/billing_testing.html#billing-testing-static

In some cases, the reserved items may return signed static responses, which lets you test signature verification in your application. 在某些情况下,保留的项目可能会返回已签名的静态响应,这使您可以在应用程序中测试签名验证。 The reserved items only return signed responses if the user running the application has a developer or test account. 如果运行应用程序的用户具有开发人员或测试帐户,则保留项仅返回已签名的响应。

set return value to true In 将返回值设置为true

public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) {
    return true;
}

after tesing undo the change 在测试后撤消更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM