即時開發人員通知參考指南

本主題列出並描述您可從 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,
  "testNotification": TestNotification
}

下表提供這些欄位的說明。

屬性名稱 說明
version string 這則通知的版本。一開始會是「1.0」。此版本與其他版本欄位不同。
packageName string 與這則通知相關的應用程式套件名稱 (例如「com.some.thing」)。
eventTimeMillis long 事件發生時的時間戳記 (以從 Epoch 紀元時間算起的毫秒數表示)。
subscriptionNotification SubscriptionNotification 如有這個欄位,則這則通知與訂閱相關,且這個欄位含有與訂閱相關的其他資訊。請注意,這個欄位與 testNotification 和 oneTimeProductNotification 互斥。
oneTimeProductNotification OneTimeProductNotification 如果有這個欄位,則這則通知與一次性消費相關,且這個欄位含有與消費相關的額外資訊。請注意,這個欄位與 testNotification 和 subscriptionProductNotification 互斥。
testNotification TestNotification 如果有這個欄位,則這則通知與測試發布相關。這些內容只會透過 Google Play 管理中心傳送。請注意,這個欄位與 subscriptionNotification 和 oneTimeProductNotification 互斥。

SubscriptionNotification

SubscriptionNotification 包含下列欄位:

{
  "version": string,
  "notificationType": int,
  "purchaseToken": string,
  "subscriptionId": string
}
屬性名稱 說明
version string 這則通知的版本。一開始會是「1.0」。此版本與其他版本欄位不同。
notificationType int 訂閱項目的 notificationType 可能具有下列值:
  • (1) SUBSCRIPTION_RECOVERED - 訂閱項目已從帳戶保留狀態恢復。
  • (2) SUBSCRIPTION_RENEWED - 目前的訂閱項目已續訂。
  • (3) SUBSCRIPTION_CANCELED - 訂閱項目遭自願取消或非自願取消。如果是自願取消的情況,會在使用者取消時傳送此值。
  • (4) SUBSCRIPTION_PURCHASED - 使用者已購買新的訂閱項目。
  • (5) SUBSCRIPTION_ON_HOLD - 訂閱項目已進入帳戶保留狀態 (如果已啟用)。
  • (6) SUBSCRIPTION_IN_GRACE_PERIOD - 訂閱項目已進入寬限期 (如果已啟用)。
  • (7) SUBSCRIPTION_RESTARTED - 使用者已從「Play」>「帳戶」>「訂閱」還原訂閱項目。訂閱項目已取消,但在使用者還原時尚未到期。詳情請參閱「還原」。
  • (8) SUBSCRIPTION_PRICE_CHANGE_CONFIRMED - 使用者已成功確認訂閱項目價格異動。
  • (9) SUBSCRIPTION_DEFERRED - 訂閱項目的週期時間已延長。
  • (10) SUBSCRIPTION_PAUSED - 訂閱項目已暫停。
  • (11) SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED - 訂閱暫停時間表已變更。
  • (12) SUBSCRIPTION_REVOKED - 使用者在訂閱到期前已取消訂閱項目。
  • (13) SUBSCRIPTION_EXPIRED - 訂閱項目已到期。
purchaseToken string 購買訂閱項目時提供給使用者裝置的權杖。
subscriptionId string 所購買訂閱項目的產品 ID (例如「monthly001」)。

範例

以下是新的訂閱項目購買交易的通知範例:

{
  "version":"1.0",
  "packageName":"com.some.thing",
  "eventTimeMillis":"1503349566168",
  "subscriptionNotification":
  {
    "version":"1.0",
    "notificationType":4,
    "purchaseToken":"PURCHASE_TOKEN",
    "subscriptionId":"monthly001"
  }
}

OneTimeProductNotification

OneTimeProductNotification 包含下列欄位:

{
  "version": string,
  "notificationType": int,
  "purchaseToken": string,
  "sku": string
}
屬性名稱 說明
version string 這則通知的版本。一開始會是「1.0」。此版本與其他版本欄位不同。
notificationType int 通知類型,可能具有下列值:
  • (1) ONE_TIME_PRODUCT_PURCHASED - 使用者已成功購買一次性產品。
  • (2) ONE_TIME_PRODUCT_CANCELED - 使用者已取消待處理的一次性產品購買交易。
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"
  }
}

TestNotification

TestNotification 包含下列欄位:

{
  "version": string
}
屬性名稱 說明
version string 這則通知的版本。一開始會是「1.0」。此版本與其他版本欄位不同。

範例

以下是測試通知範例:

{
  "version":"1.0",
  "packageName":"com.some.thing",
  "eventTimeMillis":"1503350156918",
  "testNotification":
  {
    "version":"1.0"
  }
}