我已经在我的应用中实现了应用内计费 - 最近 google 对其进行了更新,之前我正在使用 "android.test.purchased"
测试应用内计费并且它正在工作很好(购买完整版并恢复完整版)。
现在我从这里学习了改变的类(class) https://code.google.com/p/marketbilling/source/detail?r=7bc191a004483a1034b758e1df0bda062088d840
之后我无法测试应用程序,它在 Logcat “IabHelper:应用内计费错误:Sku android.test.purchased 的购买签名验证失败”中给出以下错误
"。
我已经检查了我的 key 、包名和应用程序版本都正确,有人遇到过这个问题吗?
请帮帮我。
最佳答案
这是因为 Security 类中的 verifyPurchase() 方法已在新修复中进行了更改。让我告诉你确切的问题是什么:
安全类更改
旧代码
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;
}
新代码
public static boolean verifyPurchase(String base64PublicKey,
String signedData, String signature) {
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);
}
根据我从新代码中搜索和测试的内容,
为什么会发生,因为我们在使用像“android.test.purchased”这样的虚拟产品时不会得到任何签名。所以在旧代码中它工作得很好,因为即使没有给出签名,我们也会返回 true,而对于新代码,我们会返回 false。
更多关于签名数据 null 或空白的信息来自 link1和 link2
所以我建议你只替换旧的代码方法 verifyPurchase() 而不是 New Code 方法。
我认为新代码可能适用于真实产品,但不适用于虚拟产品。但是我还没有测试过真正的产品。
让我详细搜索一下,他们为什么更改代码以及背后的目的是什么。
编辑:
BuildConfig.DEBUG 还将为您提供测试购买的解决方案。
在 verifyPurchase 中,我将 return false
更改为:
Log.e(TAG, "Purchase verification failed: missing data.");
if (BuildConfig.DEBUG) {
return true;
}
return false;
但您应该注意仅在测试场景中使用它。
如果您有调试版本,并且签名数据丢失,这将返回 true。由于 BuildConfig.DEBUG 在生产构建中将是错误的,这应该没问题。但最好是在调试完所有内容后删除此代码。
我在 verifyPurchase() 方法中编辑了一些代码,请在下面查看:
public static boolean verifyPurchase(String base64PublicKey,
String signedData, String signature) {
if (signedData == null) {
Log.e(TAG, "data is null");
return false;
}
if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey)
|| TextUtils.isEmpty(signature)) {
Log.e(TAG, "Purchase verification failed: missing data.");
if (BuildConfig.DEBUG) {
Log.d("DeBUG", ">>>"+BuildConfig.DEBUG);
return true;
}
return false;
}
PublicKey key = Security.generatePublicKey(base64PublicKey);
return Security.verify(key, signedData, signature);
}
我从 GvS 的回答中得到这个
android in app billing purchase verification failed .
希望对你有帮助。
关于android - 更新后应用内计费不起作用 - Google 商店,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19534210/