android应用内计费v3 api中的开发者负载应该是什么?
我正在我的应用中实施应用内计费,以解锁高级功能。 应用内账单设置正确。除了“开发人员有效负载”这件事,一切似乎都很好 示例应用程序显示android应用内计费v3 api中的开发者负载应该是什么?,android,in-app-purchase,in-app-billing,android-billing,Android,In App Purchase,In App Billing,Android Billing,我正在我的应用中实施应用内计费,以解锁高级功能。 应用内账单设置正确。除了“开发人员有效负载”这件事,一切似乎都很好 示例应用程序显示 /* * 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: Local
/*
* 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.
*/
示例应用程序使用空字符串作为开发人员负载。我的问题是使用什么字符串作为开发人员负载?
我可以使用用户的主要电子邮件ID吗
请检查以下答案,它可能会解决您的问题: 如果您使用的是耗材(托管项),则可以使用随机生成的字符串 步骤1:在创建方法之前声明以下内容:
private static final char[] symbols = new char[36];
static {
for (int idx = 0; idx < 10; ++idx)
symbols[idx] = (char) ('0' + idx);
for (int idx = 10; idx < 36; ++idx)
symbols[idx] = (char) ('a' + idx - 10);
}
有关更多信息,请查看此链接:
希望它能解决您的问题。对我来说,随机字符串没有用处,因为首先,它需要依赖于购买它的用户,而不是购买它的设备。其次,它是非消耗性物品,所以空字符串可能适合,但并不理想 所以我的解决方法是基于密钥创建加密哈希。每次购买时,它都是唯一可识别的,因为散列永远不应该相同(这取决于散列方法,例如bcrypt) 由于所有设备上的密钥都是相同的,因此很容易解密并验证秘密消息是否正确 为了使密钥保持秘密,我使用了各种字符串操作函数来屏蔽它,这样它就不会以可见的方式存储 可在此处找到文本管理的示例:
字符串Base64EncodedPublicKey=
递减指令行(“BL4KLE”)+GetMiddleBit()+反向限制(“D349824”)代码>
这种基于密钥创建散列的方法允许有效负载是唯一的和可识别的,同时具有合理的安全性。它不是防弹的,但确实很难破解。检查此链接:。我希望它能解决你所有的疑问。谢谢莫利克。链接中的答案确实帮助了我:)你要么关闭你的问题,要么在下面更正我的答案,让问题得以解决,这样其他人就可以根据自己的需要检查这个问题。你如何用这种方法识别用户?@Renjith,你没有。这种方法是为了确定购买是否合法。请我不明白,如何才能为相同的输入唯一有效载荷?钥匙一直是一样的。来自相同输入的散列返回相同的结果。@t0m这取决于所使用的散列方法。Bcrypt允许您使用相同的字符串来获得不同的哈希结果。不要使用随机字符串。用户可以在一台设备上购买商品,并希望在另一台设备上购买。这一点在任务(第2项)中有描述。当你取消购买并再次尝试购买时,这也是一个问题。Google Play每次都返回第一个有效负载。@mlatu请查看Google网站。我们必须将开发者负载存储在我们自己的web服务器中,以供特定用户解决设备问题。@defhlt我想它已经附加到您用来完成购买的gmail帐户上了。为什么有效载荷很重要?
public class RandomString {
/*
* static { for (int idx = 0; idx < 10; ++idx) symbols[idx] = (char)
* ('0' + idx); for (int idx = 10; idx < 36; ++idx) symbols[idx] =
* (char) ('a' + idx - 10); }
*/
private final Random random = new Random();
private final char[] buf;
public RandomString(int length) {
if (length < 1)
throw new IllegalArgumentException("length < 1: " + length);
buf = new char[length];
}
public String nextString() {
for (int idx = 0; idx < buf.length; ++idx)
buf[idx] = symbols[random.nextInt(symbols.length)];
return new String(buf);
}
}
public final class SessionIdentifierGenerator {
private SecureRandom random = new SecureRandom();
public String nextSessionId() {
return new BigInteger(130, random).toString(32);
}
}
RandomString randomString = new RandomString(36);
System.out.println("RandomString>>>>" + randomString.nextString());
/* String payload = ""; */
// bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ
String payload = randomString.nextString();
Log.e("Random generated Payload", ">>>>>" + payload);
Log.d(TAG, "Launching purchase flow for infinite gas subscription.");
mHelper.launchPurchaseFlow(this, SKU_GAS,
IabHelper.ITEM_TYPE_INAPP, RC_REQUEST,
mPurchaseFinishedListener, payload);