本文档列出了您可以从 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,
"pendingRefundReviewNotification": PendingRefundReviewNotification,
"testNotification": TestNotification
}
下表对这些字段进行了说明。
| 属性名称 | 值 | 说明 |
|---|---|---|
| version | string | 此通知的版本。最初,此值为“1.0”。此版本与其他版本字段不同。 |
| packageName | string | 与此通知相关的应用的软件包名称(例如“com.some.thing”)。 |
| eventTimeMillis | long | 事件发生的时间戳,以从公元纪年开始计算的毫秒数表示。 |
| subscriptionNotification | SubscriptionNotification | 如果此字段存在,则此通知与订阅相关,并且此字段包含与订阅相关的其他信息。 请注意,此字段与 pendingRefundReviewNotification、oneTimeProductNotification、voidedPurchaseNotification 和 testNotification 互斥。 |
| oneTimeProductNotification | OneTimeProductNotification | 如果此字段存在,则此通知与单次购买相关,并且此字段包含与购买交易相关的其他信息。 请注意,此字段与 pendingRefundReviewNotification、subscriptionNotification、voidedPurchaseNotification 和 testNotification 互斥。 |
| voidedPurchaseNotification | VoidedPurchaseNotification | 如果此字段存在,则此通知与作废的购买交易相关,并且此字段包含与作废的购买交易相关的其他信息。 请注意,此字段与 pendingRefundReviewNotification、oneTimeProductNotification、subscriptionNotification 和 testNotification 互斥。 |
| pendingRefundReviewNotification | PendingRefundReviewNotification | 如果存在此字段,则表示相应通知与退款申请相关,您可以针对该申请提出解决方案建议。 通过调用 `ReviewRefund` API 来响应此通知。 请注意,此字段与 subscriptionNotification、oneTimeProductNotification、voidedPurchaseNotification 和 testNotification 互斥。 |
| testNotification | TestNotification | 如果此字段存在,则此通知与测试发布相关。这些只通过 Google Play 管理中心发送。 请注意,此字段与 pendingRefundReviewNotification、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 | 字符串 | 在用户购买时向用户设备提供的令牌。 |
| 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:指定使相应购买交易失效的退款类型。
PendingRefundReviewNotification
当用户针对某项购买交易申请退款,且该申请需要开发者审核时,系统会发送 PendingRefundReviewNotification。收到此通知后,您应评估相应请求,并在 24 小时内通过调用 ReviewRefund API 提供退款建议和购买使用情况证据。
PendingRefundReviewNotification 包含以下字段:
{
"version": string,
"pendingRefundToken": string,
"orderId": string,
"refundReason": int,
"obfuscatedAccountId": string,
"obfuscatedProfileId": string
}
| 属性名称 | 值 | 说明 |
|---|---|---|
| version | string | 此通知的版本。最初,此值为“1.0”。此版本与其他版本字段不同。 |
| pendingRefundToken | 字符串 | 用于标识正在审核中的待处理退款请求的唯一令牌。在调用 ReviewRefund API 时传递此令牌。 |
| orderId | 字符串 | 正在接受退款审核的购买交易的订单 ID。 |
| refundReason | int | 申请退款的原因。待处理的评价仅支持将 CHARGEBACK (7) 作为退款原因。您的代码应能够处理新原因。 |
| obfuscatedAccountId | 字符串 | (如果适用)购买交易发生时提供的经过混淆处理的开发者指定的用户账号 ID。 |
| obfuscatedProfileId | 字符串 | (如果适用)购买时提供的经过混淆处理的开发者指定个人资料 ID。 |
示例
以下是待处理的退款审核通知示例:
{
"version":"1.0",
"packageName":"com.some.thing",
"eventTimeMillis":"1503350156918",
"pendingRefundReviewNotification":
{
"version":"1.0",
"pendingRefundToken":"example-token",
"orderId":"GPA.1234-5678-9012-34567",
"refundReason":7,
"obfuscatedAccountId":"user-account-id",
"obfuscatedProfileId":"user-profile-id"
}
}
TestNotification
TestNotification 包含以下字段:
{
"version": string
}
| 属性名称 | 值 | 说明 |
|---|---|---|
| version | string | 此通知的版本。最初,此值为“1.0”。此版本与其他版本字段不同。 |
示例
下面是测试通知的示例:
{
"version":"1.0",
"packageName":"com.some.thing",
"eventTimeMillis":"1503350156918",
"testNotification":
{
"version":"1.0"
}
}