Goo*_*ofy 15 android billing in-app-purchase in-app-billing android-billing
我已在我的应用中实施了应用内结算 - 最近谷歌已对其进行了更新,之前我正在测试应用内结算"android.test.purchased"
并且工作正常(购买完整版和恢复完整版).
现在我从这里接受了更改的课程 https://code.google.com/p/marketbilling/source/detail?r=7bc191a004483a1034b758e1df0bda062088d840
之后,我无法测试应用程序,它在Logcat中给出以下错误 "IabHelper: In-app billing error: Purchase signature verification FAILED for sku android.test.purchased
".
我已经检查了我的密钥,包名和app版本都是正确的,有没有人遇到过这个问题?
请帮我解决一下这个.
Mau*_*lik 31
这是因为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;
}
Run Code Online (Sandbox Code Playgroud)
新规范
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);
}
Run Code Online (Sandbox Code Playgroud)
根据我从新代码中搜索和测试的内容,
为什么会发生这种情况,因为我们在使用像"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;
Run Code Online (Sandbox Code Playgroud)
但是你应该知道只在测试场景中使用它.
如果您有调试版本,则返回true,并且缺少签名数据.由于BuildConfig.DEBUG在生产版本中将为false,因此应该没问题.但更好的是在调试完所有内容后删除此代码.
我在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);
}
Run Code Online (Sandbox Code Playgroud)
我从GvS's answer
Android应用程序计费购买验证失败了.
希望它对你有所帮助.
我是向Google安全小组通报这些安全漏洞的人.在我公开披露这些错误之前请耐心等待,因为我已经给了Google时间来修复它们.如果没有大型网站写这个问题,我将在11月6日披露一个有效的漏洞.
正如您已经查看了verifyPurchase(),这个bug应该是显而易见的.如果给定签名是一个空String,则该方法仍返回true(因为它在默认情况下返回true).
归档时间: |
|
查看次数: |
10394 次 |
最近记录: |