3

从周日开始,我已经通过六种方式在谷歌上搜索了这个概念,但我觉得我找不到一个直接的答案。谷歌官方文档说这不是为了安全,但是我发现的一堆答案似乎暗示了其他方面,等等。

从文档:

第五个参数包含一个“开发人员有效负载”字符串,您可以使用它来发送有关订单的补充信息(它可以是一个空字符串)。如果您指定字符串值,Google Play 会将此字符串与购买响应一起返回。随后,当您查询此次购买时,Google Play 会返回此字符串以及购买详情。

注意:请勿将 developerPayload 字段用于安全验证目的。完成与应用内结算相关的任务时,此字段并不总是可用。有关安全最佳实践的更多信息,请参阅应用内计费安全和设计指南。

来自谷歌官方测试项目:

/** Verifies the developer payload of a purchase. */
boolean verifyDeveloperPayload(Purchase p) {
    String payload = p.getDeveloperPayload();

    /*
     * TODO: verify that the developer payload of the purchase is correct. It will be
     * the same one that you sent when initiating the purchase.
     *
     * WARNING: Locally generating a random string when starting a purchase and
     * verifying it here might seem like a good approach, but this will fail in the
     * case where the user purchases an item on one device and then uses your app on
     * a different device, because on the other device you will not have access to the
     * random string you originally generated.
     *
     * So a good developer payload has these characteristics:
     *
     * 1. If two different users purchase an item, the payload is different between them,
     *    so that one user's purchase can't be replayed to another user.
     *
     * 2. The payload must be such that you can verify it even when the app wasn't the
     *    one who initiated the purchase flow (so that items purchased by the user on
     *    one device work on other devices owned by the user).
     *
     * Using your own server to store and verify developer payloads across app
     * installations is recommended.
     */

    return true;
}

我完全不知道这意味着什么。如果我没有自己的服务器,我应该只使用空白字符串吗?我应该如何区分用户、购买和设备?

这些对我来说都不是很清楚,这段代码/官方文档也没有提供真正的澄清,大多数在线答案也同样稀疏。

谁能简单地说一下:我应该发送什么作为我的开发人员有效负载参数?

4

2 回答 2

0

谷歌代码的最后一点似乎很有帮助

建议使用您自己的服务器来存储和验证跨应用安装的开发人员有效负载。

如果你有一个服务器,你可以有一个getRandomString端点,服务器创建并添加到与用户帐户关联的可用随机字符串列表中。

当字符串返回给客户端时,这可以用作开发人员有效负载。

然后,在验证服务器上的购买令牌时,您可以获得有效负载并根据服务器上可用的随机字符串列表检查它。

但是,我不确定这是否会增加任何安全性。而且我看不出这对“跨应用程序安装”有何帮助。因为对于托管产品,无论应用程序安装如何,您都无法购买多个托管产品。在再次购买之前,它们必须被消耗掉......

你最后有没有解决你的问题。我很想知道你最后做了什么,因为我面临同样的问题,只有我有一个服务器后端。

于 2018-05-25T19:37:38.690 回答
0

至少你有安全理由生成随机字符串:两个相同的购买具有不同的 developerPayload 总是会有不同的购买数据和签名。

String developerPayload = UUID.randomUUID().toString();

如果您不在服务器上处理答案,则没有任何理由记住并检查此字符串(请参阅 google 测试中的警告)。

于 2017-08-14T12:13:50.120 回答