我无法在我的 Android 应用中实现应用计费。 我收到购买签名验证失败。 在我第一次遇到困难时,它是base64 key ,但我检查了很多次,但我仍然收到错误,然后在我查看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);
}
我得到“签名为空”。 即使我按照以下步骤操作: - 使用我的发布 key 签署 apk - 上传草稿 - 使用“adb -d install app.apk”将其安装在设备上
我正在测试真实的购买。 谢谢。
编辑 购买流程很好,当我调用 queryInventoryAsync
最佳答案
您可以使用测试 SKU 进行测试,as explained here .它们是:
android.test.purchased
android.test.canceled
android.test.refunded
android.test.item_unavailable
即使在测试和调试场景中,这些购买也会成功(至少是 android.test.purchased),而无需取消购买。
在 verifyPurchase 中,我将 return false
更改为:
Log.e(TAG, "Purchase verification failed: missing data.");
if (BuildConfig.DEBUG) {
return true;
}
return false;
但您应该注意仅在测试场景中使用它。
如果您有调试版本,并且签名数据丢失,这将返回 true。由于 BuildConfig.DEBUG 在生产构建中将是错误的,这应该没问题。但最好是在调试完所有内容后删除此代码。
关于android in app billing 购买验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19732025/