本主题列出了您可以从 Google Play 收到的实时开发者通知类型,并提供了说明。
编码
发布到 Cloud Pub/Sub 主题的每条消息都包含一个 base64 编码的数据字段。
{
"message": {
"attributes": {
"key": "value"
},
"data": "eyAidmVyc2lvbiI6IHN0cmluZywgInBhY2thZ2VOYW1lIjogc3RyaW5nLCAiZXZlbnRUaW1lTWlsbGlzIjogbG9uZywgIm9uZVRpbWVQcm9kdWN0Tm90aWZpY2F0aW9uIjogT25lVGltZVByb2R1Y3ROb3RpZmljYXRpb24sICJzdWJzY3JpcHRpb25Ob3RpZmljYXRpb24iOiBTdWJzY3JpcHRpb25Ob3RpZmljYXRpb24sICJ0ZXN0Tm90aWZpY2F0aW9uIjogVGVzdE5vdGlmaWNhdGlvbiB9",
"messageId": "136969346945"
},
"subscription": "projects/myproject/subscriptions/mysubscription"
}
解码 base64 编码的数据字段后,DeveloperNotification
将包含以下字段
{
"version": string,
"packageName": string,
"eventTimeMillis": long,
"oneTimeProductNotification": OneTimeProductNotification,
"subscriptionNotification": SubscriptionNotification,
"voidedPurchaseNotification": VoidedPurchaseNotification,
"testNotification": TestNotification
}
以下表格描述了这些字段。
属性名称 | 值 | 说明 |
version | string | 此通知的版本。最初版本为 "1.0"。此版本与其他版本字段不同。 |
packageName | string | 此通知相关的应用的软件包名称(例如,`com.some.thing`)。 |
eventTimeMillis | long | 事件发生时的时间戳,以自 Epoch 以来的毫秒为单位。 |
subscriptionNotification | SubscriptionNotification | 如果此字段存在,则此通知与订阅相关,且此字段包含与订阅相关的额外信息。请注意,此字段与 oneTimeProductNotification、voidedPurchaseNotification 和 testNotification 互斥。 |
oneTimeProductNotification | OneTimeProductNotification | 如果此字段存在,则此通知与一次性购买相关,且此字段包含与该购买相关的额外信息。请注意,此字段与 subscriptionNotification、voidedPurchaseNotification 和 testNotification 互斥。 |
voidedPurchaseNotification | VoidedPurchaseNotification | 如果此字段存在,则此通知与已作废的购买相关,且此字段包含与该已作废购买相关的额外信息。请注意,此字段与 oneTimeProductNotification、subscriptionNotification 和 testNotification 互斥。 |
testNotification | TestNotification | 如果此字段存在,则此通知与测试发布相关。这些通知仅通过 Google Play 管理中心发送。请注意,此字段与 oneTimeProductNotification、subscriptionNotification 和 voidedPurchaseNotification 互斥。 |
SubscriptionNotification
SubscriptionNotification
包含以下字段
{
"version": string,
"notificationType": int,
"purchaseToken": string
}
属性名称 | 值 | 说明 |
version | string | 此通知的版本。最初版本为 "1.0"。此版本与其他版本字段不同。 |
notificationType | int | 订阅的 notificationType 可以具有以下值
|
purchaseToken | string | 购买订阅时提供给用户设备的令牌。 |
示例
以下是新订阅购买通知的示例
{
"version":"1.0",
"packageName":"com.some.thing",
"eventTimeMillis":"1503349566168",
"subscriptionNotification":
{
"version":"1.0",
"notificationType":4,
"purchaseToken":"PURCHASE_TOKEN"
}
}
OneTimeProductNotification
OneTimeProductNotification
包含以下字段
{
"version": string,
"notificationType": int,
"purchaseToken": string,
"sku": string
}
属性名称 | 值 | 说明 |
version | string | 此通知的版本。最初版本为 "1.0"。此版本与其他版本字段不同。 |
notificationType | int | 通知类型。可以具有以下值
|
purchaseToken | string | 进行购买时提供给用户设备的令牌。 |
sku | string | 购买的一次性产品 ID(例如,“sword_001”) |
示例
以下是新一次性购买通知的示例
{
"version":"1.0",
"packageName":"com.some.thing",
"eventTimeMillis":"1503349566168",
"oneTimeProductNotification":
{
"version":"1.0",
"notificationType":1,
"purchaseToken":"PURCHASE_TOKEN",
"sku":"my.sku"
}
}
VoidedPurchaseNotification
VoidedPurchaseNotification
包含以下字段
属性名称 |
值 |
说明 |
|
|
与已作废购买相关联的令牌。在发生新购买时向开发者提供此信息。 |
|
|
与已作废交易相关联的唯一订单 ID。对于一次性购买,这表示为该购买生成的唯一订单 ID。对于自动续订订阅,每次续订交易都会生成新的订单 ID。 |
|
|
已作废购买的
|
|
|
已作废购买的
请注意,当多数量购买中剩余总数量被退款时, |
示例
以下是新的已作废购买通知的示例
{
"version":"1.0",
"packageName":"com.some.app",
"eventTimeMillis":"1503349566168",
"voidedPurchaseNotification":
{
"purchaseToken":"PURCHASE_TOKEN",
"orderId":"GS.0000-0000-0000",
"productType":1
"refundType":1
}
}
使用 VoidedPurchaseNotification
当您的 RTDN 客户端收到 VoidedPurchaseNotification
时,请注意以下信息
packageName
:用于识别应用。eventTimeMillis
:告知开发者状态更改发生的时间。purchaseToken
:购买产品时提供给用户设备的令牌。orderId
:用于识别与已作废交易相关联的订单。productType
:告知您已作废购买是应用内购买还是订阅。refundType
:告知您导致购买作废的退款类型。
如果您只需定位正确的购买和订单即可调整用户权利,那么您目前已拥有所需的所有信息。要了解如何获取有关已作废购买的更多信息,请查看 Google Play 已作废购买 API,这是一个拉取模式 API,它在给定时间戳之间为已作废购买提供额外数据。
对于部分作废的多数量购买,由 purchases.products
提供的 refundableQuantity
字段包含尚未作废的已购买产品剩余数量。
TestNotification
TestNotification
包含以下字段
{
"version": string
}
属性名称 | 值 | 说明 |
version | string | 此通知的版本。最初版本为 "1.0"。此版本与其他版本字段不同。 |
示例
以下是测试通知的示例
{
"version":"1.0",
"packageName":"com.some.thing",
"eventTimeMillis":"1503350156918",
"testNotification":
{
"version":"1.0"
}
}