【发布时间】:2015-07-07 21:15:18
【问题描述】:
我在对我的应用内商品进行许可测试时遇到问题。我有一个发布到 Google Play Beta 频道的应用程序,并且我的相关 Google 帐户在开发控制台中列为许可证测试员。 (这意味着我可以在不实际支付商品的情况下进行“购买”。)
当我第一次访问应用内商店时,一切正常。但是,在“购买”商品时,我在购买流程响应中收到签名验证错误。从那时起,我在查询 商店库存时也会收到相同的签名错误。
这部分我需要帮助。我看到posts 指出Security.java 中的方法verifyPurchase 是罪魁祸首。那些other posts 表示问题在于android.test.purchased 返回一个空字符串作为签名。我看到的不一样。我的电话通过了isEmpty(signature) 测试,但随后在代码中被拒绝。 为什么 Google In-App Billing 会返回一个无效的签名?我在下面包含了相关代码。
public class Security {
// ...
// This method is part of the trace from
// IabHelper.queryInventory and IabHelper.onActivityResult
public static boolean verifyPurchase(String base64PublicKey, String signedData,
String signature) {
if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey) ||
TextUtils.isEmpty(signature)) { // Most say their problem is here
Log.e(TAG, "Purchase verification failed: missing data.");
return false;
}
PublicKey key = Security.generatePublicKey(base64PublicKey);
return Security.verify(key, signedData, signature); // My code gets here, but...
}
public static boolean verify(PublicKey publicKey, String signedData,
String signature) {
Signature sig;
try {
sig = Signature.getInstance(SIGNATURE_ALGORITHM);
sig = initVerify(publicKey);
sig.update(signedData.getBytes());
if (!sig.verify(Base64.decode(signature))) { // ...verify fails; return false
Log.e(TAG, "Signature verification failed.");
return false;
}
return true;
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "NoSuchAlgorithmException.");
} catch (InvalidKeyException e) {
Log.e(TAG, "Invalid key specification.");
} catch (SignatureException e) {
Log.e(TAG, "Signature exception.");
} catch (Base64DecoderException e) {
Log.e(TAG, "Base64 decoding failed.");
}
return false;
}
}
更新:正如我在评论中提到的,我正在运行一个签名的 APK,并将 debuggable 标志设置为 true。我现在尝试使用真正的信用卡进行实际购买;我看到了完全相同的结果。尽管 Google Play 购买流程按预期完成,但我实际上并没有收到我的产品。返回商店后,Google Play 没有退回应用内库存。
【问题讨论】:
-
您正在测试的应用程序的版本代码与测试版开发控制台中的应用程序相同?它是在发行版中编译的吗?您无法使用调试应用测试应用内应用,并且您使用的应用的版本代码必须为 Google 所知。
-
哦...您使用的是模拟器还是真实设备?你也需要谷歌播放更新的应用程序!
-
我已经满足了所有这些条件。我能够确定确切的行,因为我正在运行一个签名的 APK,其版本代码与 Play Store beta 相同,但可调试标志设置为 true。我承认我可能有点抓不住稻草,但我看到的最终结果与运行从 Play 商店下载的测试版时相同。购买未按预期完成,并且在尝试购买后调用库存失败。
标签: android in-app-purchase google-play-services in-app-billing