Android 计费客户端库:如何指定开发人员负载(额外数据)

Android Billing Client library : How to specify Developer Payload(extra data)

我正在尝试使用新的 Android Billing Client library(1.0)

以前,在尝试执行购买时,可以选择向意图添加额外数据。

但是,在使用新库时,事情已经大大简化了。但是有没有办法将开发人员有效负载(额外字符串)添加到购买流程中?

找到答案了,名称已更改,因此混乱。

BillingFlowParams 构建器公开了一个名为 setAccountId(String accountId) 的函数。此函数的定义是:

Specify an optional obfuscated string that is uniquely associated with the user's account in your app. If you pass this value, Google Play can use it to detect irregular activity, such as many devices making purchases on the same account in a short period of time. Do not use the developer ID or the user's Google ID for this field. In addition, this field should not contain the user's ID in cleartext. We recommend that you use a one-way hash to generate a string from the user's ID and store the hashed string in this field.

我认为这是指定开发人员负载或用于额外验证层的任何额外字符串的新方法。 所以代码看起来像这样:

private fun makePurchaseFromGoogle(developerPayload : String) {
    val purchaseParams = BillingFlowParams.newBuilder()
            .setSku(product.sku)
            .setType(product.type)
            .setAccountId(developerPayload) // dev-payload
            .build()
    googleBillingClient.launchBillingFlow(activity, purchaseParams)
}

新版本的计费库支持开发者负载

您可以在确认购买或消费时设置开发者负载。

val client: BillingClient = ...
val listener: AcknowledgePurchaseResponseListener = ...

val acknowledgePurchaseParams =
AcknowledgePurchaseParams.newBuilder()
    .setPurchaseToken(/* token */)
    .setDeveloperPayload(/* payload */)
    .build()

client.acknowledgePurchase(acknowledgePurchaseParams, listener)

Attach a developer payload in Android Billing Library v2.0