Android 发布者 API - 获取额外数据(检测哪个用户进行了购买)

Android Publisher API - get extra data (detect which user made purchase)

对于应用内订阅,我使用此代码(在 Kotlin 中)

iabHelper.launchSubscriptionPurchaseFlow(act, "month", 1001, this@SubscriptionActivity, extraKey)

在此之后我向服务器请求进行购买验证。为了在服务器上进行验证,我正在使用此代码(在 Go 中)

result, err := androidpublisher.Purchases.Subscriptions.Get(packageName, product, token).Do()
success := err == nil

如何获取我在app中传入的extraKey?我需要它知道哪个用户进行了购买

我对参数名称 "extraData" 感到困惑,并在请求结果中寻找相同的字段。 但是当我查看 IabHelper 源代码时,我发现了这个

@param extraData Extra data (developer payload), which will be returned with the purchase * data when the purchase completes. This extra data will be permanently bound to that * purchase and will always be returned when the purchase is queried

因此,额外的数据在 DeveloperPayload 字段中

result, err := publ.Purchases.Subscriptions.Get(packageName, product, token).Do()
success := err == nil && result.DeveloperPayload == extraKey

另外,请注意,这对那些不读书的人很有用docs

Note: Do not use the user's email address in the payload string, since that address may change.