触发推送通知
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
合作伙伴触发的通知
添加消息和通知
背景
用户添加卡券后,您可能需要向其发送与卡券相关的消息,并确保他们收到相关通知。使用 Add Message API 请求(message_type
等于 TEXT_AND_NOTIFY
)时,会发生以下情况:
- 系统会将“消息”项添加到“卡券背面”(也称为详细信息模板),并向保存了卡券的用户发送推送通知。
- 用户点按通知后,Google 钱包会打开到卡券正面(也称为卡片视图),并且用户会在屏幕顶部看到带有“查看消息”按钮的宣传信息。
- 点击宣传信息后,用户会进入卡券背面,其中会突出显示新的消息(未读)。
向用户发送包含通知的消息时的一些注意事项
- 用户必须为其卡券启用通知,才能接收与消息相关的推送通知。
- 消息可能包含指向您的网站或应用的 URI。超链接必须是与卡券相关的网站或应用。将用户引导至与卡券无关的链接违反了可接受的使用政策。
- 您在 24 小时内最多只能发送 3 条可触发推送通知的消息。如果 Google 认为您向用户发送的推送通知属于垃圾内容,可能会限制您的推送通知传送配额。
- 用户在锁定屏幕上看到的推送通知由 Google 钱包控制。
- 您可以使用 UPDATE 或 PATCH 方法,通过常规类或对象端点修改或移除消息数据。
集成步骤
如果您想使用 AddMessage API 向用户发送有关添加的新发卡人消息的通知,则需要更新 AddMessageRequest,以便包含新文本的 Message 的 MessageType 为 TEXT_AND_NOTIFY,而不是 TEXT。
在 Passes 类中添加消息和通知的 JSON 请求示例
…
"id": ISSUER_ID.CLASS_ID",
"message":
{
"header":"My Class message header",
"body": "My Class message body with a <a href="https://wallet.google">Hyperlink<\a>",
"id": "message_id",
"message_type": "TEXT_AND_NOTIFY"
},
…
在卡券对象中添加消息和通知的 JSON 请求示例
…
"id": OBJECT_ID",
"classId": "ISSUER_ID.CLASS_ID",
"message":
{
"header":"My Object message header",
"body": "My Object message body with a <a href="http://play.google.com/store/apps/details?id=com.google.android.apps.maps">Hyperlink<\a>",
"id": "message_id",
"message_type": "TEXT_AND_NOTIFY"
},
…
添加消息并为通过类发送通知的示例响应
// The updated resource
…
{
"kind": "walletobjects#walletObjectMessage",
"header": "My Object message header",
"body": "My Object message body with a <a href="http://play.google.com/store/apps/details?id=com.google.android.apps.maps">Hyperlink<\a>",
"id": "message_id",
"messageType": "textAndNotify"
},
…
异常处理
如果尝试发送通知的次数超过 3 次,系统会返回 QuotaExceededException 响应。如集成步骤中所述,您可以使用“TEXT”而非“TEXT_AND_NOTIFY”设置卡券的任何其他更新。
更新字段和发送通知
背景
用户添加卡券后,您可能希望在更新某些字段时触发推送通知。该通知会显示在用户的锁定屏幕上,告知他们卡券有更新。此通知仅会针对下文中使用 UPDATE 和 PATCH API 方法定义的特定字段子集触发。发出用于更新卡券的 API 调用后,会发生以下情况:
- 系统会触发推送通知并将其显示在用户的锁定屏幕上,告知用户卡券更新。
- 用户点按通知后,Google 钱包会打开到卡券正面(也称为卡片视图),并且用户会在屏幕顶部看到一条宣传信息,其中包含“查看更新”按钮。
- 点击该按钮后,用户会进入一个界面,在其中可以查看更新更改的字段。
发送字段更新通知时的一些注意事项
- 用户必须为其卡券启用通知,才能接收与更新相关的推送通知。
- 您最多可以在 24 小时内发送 3 条会触发推送通知的更新。如果 Google 认为您向用户发送垃圾内容,可能会限制您的推送通知传送配额。
- 用户在锁定屏幕上看到的推送通知由 Google 钱包控制。
notifyPreference
字段是一个暂时性字段,仅在该请求中有效。日后,如果您希望触发通知,则必须在类或对象请求中重置此字段。
集成步骤
如需触发这些通知,您需要使用现有的 UPDATE 或 PATCH 调用并指定 notifyPreference。更新类或对象的字段时,您可以向类或对象请求添加新字段 notifyPreference
以触发通知。
用于在类中更新和通知的 JSON 请求示例
…
"dateTime":
{
"kind": "walletobjects#eventDateTime",
"doorsOpen": "2024-09-23T19:20:50.00"
},
"multipleDevicesAndHoldersAllowedStatus": "multipleHolders",
"notifyPreference": "notifyOnUpdate",
…
将 notifyPreference
设置为 notifyOnUpdate
会触发通知,前提是更新后的字段目前受支持。
支持的字段
- rewardsTier
- secondaryRewardsTier
- programName
- loyaltyPoints.balance
- secondaryLoyaltyPoints.balance
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003e\u003cstrong\u003e\u003ccode\u003eTEXT_AND_NOTIFY\u003c/code\u003e\u003c/strong\u003e message type adds a message to the pass details and triggers a push notification, directing users to the new message within Google Wallet.\u003c/p\u003e\n"],["\u003cp\u003eUpdating specific fields like \u003ccode\u003erewardsTier\u003c/code\u003e, \u003ccode\u003eloyaltyPoints.balance\u003c/code\u003e, and others, along with setting \u003ccode\u003enotifyPreference\u003c/code\u003e to \u003ccode\u003enotifyOnUpdate\u003c/code\u003e, triggers update notifications.\u003c/p\u003e\n"],["\u003cp\u003eBoth message and update notifications are limited to 3 per pass within a 24-hour period to prevent spamming.\u003c/p\u003e\n"],["\u003cp\u003eUsers must have Google Wallet notifications enabled to receive these alerts.\u003c/p\u003e\n"]]],["The `AddMessage` API with `message_type` as `TEXT_AND_NOTIFY` sends a push notification and adds a message to the pass's back. Users tapping the notification see a \"View Message\" button that leads to unread messages. The `UPDATE` or `PATCH` API methods, with `notifyPreference: notifyOnUpdate`, trigger notifications for changes in specific `LoyaltyClass` or `LoyaltyObject` fields. There is a maximum limit of 3 push notifications for both cases in a 24-hour period. Notifications are only received by users with enabled notifications.\n"],null,["# Trigger Push Notifications\n\nPartner Triggered Notifications\n-------------------------------\n\n### Add Message and Notify\n\n#### Background\n\nAfter a user adds a pass you may want to send them a message related to the\npass and ensure they are notified about it. Using the [Add Message API](/wallet/retail/loyalty-cards/rest/v1/loyaltyclass/addmessage)\nrequest with a `message_type` equal to\n**`TEXT_AND_NOTIFY`** the following occurs:\n\n1. A \"[Message](https://developers.google.com/wallet/reference/rest/v1/Message)\" item is added to the \"back of pass\" (aka [Details\n Template](/wallet/retail/loyalty-cards/resources/template#details-template)) and a push notification is sent to users with the pass saved.\n2. Once the user taps the notification it opens Google Wallet to the front of the pass (a.k.a. Card view) and the user will see a callout at the top of the screen with a \"View Message\" button.\n3. Clicking the callout will take users to the back of the pass, where new unread messages are highlighted.\n\n#### Some considerations when sending messages with notifications to users\n\n- Users must have notifications enabled for their passes to receive the push notifications related to messages.\n- Messages may contain URIs to your website or app. Hyperlinks must be a website or app related to the pass. It is a violation of the [Acceptable Use Policy](https://payments.developers.google.com/terms/aup) to send users to links not related to the pass.\n- You may send a maximum of 3 messages that trigger a push notification in a 24 hour period. Google may throttle your push notification delivery quota if it deems you are spamming your users.\n- The push notification users see on their lock screen is controlled by Google Wallet.\n- You can use the [UPDATE](/wallet/retail/loyalty-cards/rest/v1/loyaltyclass/update) or [PATCH](/wallet/retail/loyalty-cards/rest/v1/loyaltyclass/patch) methods to edit or remove message data using the regular class or object endpoint.\n\n#### Integration Steps\n\nWhen you want to notify users about a new issuer message added using the\nAddMessage API, you will need to update the [AddMessageRequest](https://developers.google.com/wallet/reference/rest/v1/AddMessageRequest)\nso that the [Message](https://developers.google.com/wallet/reference/rest/v1/Message)\nwhich contains your new text has the [MessageType](https://developers.google.com/wallet/reference/rest/v1/Message#MessageType)\n**TEXT_AND_NOTIFY** instead of **TEXT**.\n\n#### Example JSON Request to add message and notify in a Passes Class\n\n```carbon\n ...\n \"id\": ISSUER_ID.CLASS_ID\",\n \"message\":\n {\n \"header\":\"My Class message header\",\n \"body\": \"My Class message body with a \u003ca href=\"https://wallet.google\"\u003eHyperlink\u003c\\a\u003e\",\n \"id\": \"message_id\",\n \"message_type\": \"TEXT_AND_NOTIFY\"\n },\n ...\n```\n\n#### Example JSON Request to add message and notify in a Passes Object\n\n```carbon\n ...\n \"id\": OBJECT_ID\",\n \"classId\": \"ISSUER_ID.CLASS_ID\",\n \"message\":\n {\n \"header\":\"My Object message header\",\n \"body\": \"My Object message body with a \u003ca href=\"http://play.google.com/store/apps/details?id=com.google.android.apps.maps\"\u003eHyperlink\u003c\\a\u003e\",\n \"id\": \"message_id\",\n \"message_type\": \"TEXT_AND_NOTIFY\"\n },\n ...\n```\n\n#### Example [Response](/wallet/retail/loyalty-cards/rest/v1/loyaltyclass/addmessage#response-body) to add message and notify for a Pass Class\n\n```scilab\n // The updated resource\n …\n {\n \"kind\": \"walletobjects#walletObjectMessage\",\n \"header\": \"My Object message header\",\n \"body\": \"My Object message body with a \u003ca href=\"http://play.google.com/store/apps/details?id=com.google.android.apps.maps\"\u003eHyperlink\u003c\\a\u003e\",\n \"id\": \"message_id\",\n \"messageType\": \"textAndNotify\"\n },\n …\n```\n\n#### Exception handling\n\nAny attempts to notify more than 3 times will yield a\n**QuotaExceededException** response. Any further updates to the\npass can be set using \"**TEXT** \" instead of\n\"**TEXT_AND_NOTIFY** \" as discussed in the [Integration\nSteps](#add-message-and-notify-integration-steps).\n\n### Update Field and Notify\n\n#### Background\n\nAfter a user adds a pass you may want to trigger a push notification when you update certain\nfields. The notification will appear on the user's lock screen and inform them that there is\nan update on their pass. This notification will only trigger for a specific subset of fields\ndefined [below](#update-field-and-notify-supported-fields) using the UPDATE and PATCH\nAPI methods. Once an API call to update the pass is made the following occurs:\n\n1. A push notification is triggered and displayed on the user's lock screen, informing them of a pass update.\n2. Once the user taps the notification it opens Google Wallet to the front of the pass (a.k.a. Card view) and the user will see a callout at the top of the screen with a \"Review update\" button.\n3. Clicking the button brings the user to a screen where they can see the fields that were changed by the update.\n\n#### Some considerations when sending field update notifications\n\n- Users must have notifications enabled for their passes to receive the push notifications related to updates.\n- You may send a maximum of 3 updates that trigger a push notification in a 24 hour period. Google may throttle your push notification delivery quota if it deems you are spamming your users.\n- The push notification that users see on their lock screen is controlled by Google Wallet.\n- The `notifyPreference` field is a transient field that only lives on this request. For future requests when you wish to trigger a notification, you will have to reset this field on the class or object request.\n\n#### Integration Steps\n\nIn order to trigger these notifications, you will need to use the [existing UPDATE or PATCH\ncalls](/wallet/retail/loyalty-cards/use-cases/updates#use_the_google_wallet_api) and specify the notifyPreference. When updating a field on a class or object, you can\nadd a new field, `notifyPreference`, to the class or object request to trigger the\nnotification.\n\n#### Example JSON Request to update and notify in a Class\n\n```text\n …\n \"dateTime\":\n {\n \"kind\": \"walletobjects#eventDateTime\",\n \"doorsOpen\": \"2024-09-23T19:20:50.00\"\n },\n \"multipleDevicesAndHoldersAllowedStatus\": \"multipleHolders\",\n \"notifyPreference\": \"notifyOnUpdate\",\n …\n \n```\n\nSetting the `notifyPreference` to `notifyOnUpdate` will trigger a notification, provided the updated field is currently supported.\n\n#### Supported fields\n\n##### [LoyaltyClass](/wallet/retail/loyalty-cards/rest/v1/loyaltyclass#resource:-loyaltyclass)\n\n- rewardsTier\n- secondaryRewardsTier\n- programName\n\n##### [LoyaltyObject](/wallet/retail/loyalty-cards/rest/v1/loyaltyobject)\n\n- loyaltyPoints.balance\n- secondaryLoyaltyPoints.balance"]]