เรียกใช้ข้อความ Push
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การแจ้งเตือนที่ทริกเกอร์โดยพาร์ทเนอร์
เพิ่มข้อความและการแจ้งเตือน
ฉากหลัง
หลังจากผู้ใช้เพิ่มบัตรแล้ว คุณอาจต้องการส่งข้อความเกี่ยวกับบัตรให้ผู้ใช้และตรวจสอบว่าผู้ใช้ได้รับการแจ้งเตือนเกี่ยวกับบัตรดังกล่าว เมื่อใช้คำขอ Add Message API ที่มี message_type
เท่ากับ TEXT_AND_NOTIFY
ระบบจะดำเนินการต่อไปนี้
- ระบบจะเพิ่มรายการ "ข้อความ" ลงในส่วน "ด้านหลังบัตร" (หรือที่เรียกว่าเทมเพลตรายละเอียด) และส่งการแจ้งเตือนแบบพุชไปยังผู้ใช้ที่บันทึกบัตรไว้
- เมื่อผู้ใช้แตะการแจ้งเตือน ระบบจะเปิด Google Wallet ไปที่หน้าบัตร (หรือที่เรียกว่ามุมมองการ์ด) และผู้ใช้จะเห็นข้อความไฮไลต์ที่ด้านบนของหน้าจอพร้อมปุ่ม "ดูข้อความ"
- การคลิกข้อความไฮไลต์จะนำผู้ใช้ไปยังด้านหลังบัตร ซึ่งจะมีข้อความใหม่ที่ไม่อ่านไฮไลต์อยู่
สิ่งที่ควรพิจารณาเมื่อส่งข้อความที่มีการแจ้งเตือนถึงผู้ใช้
- ผู้ใช้ต้องเปิดใช้การแจ้งเตือนสำหรับบัตรของตนจึงจะได้รับข้อความ Push ที่เกี่ยวข้องกับข้อความ
- ข้อความอาจมี URI ไปยังเว็บไซต์หรือแอปของคุณ โดยไฮเปอร์ลิงก์ต้องเป็นเว็บไซต์หรือแอปที่เกี่ยวข้องกับบัตร การส่งผู้ใช้ไปยังลิงก์ที่ไม่เกี่ยวข้องกับบัตรเป็นการละเมิดนโยบายการใช้งานที่ยอมรับได้
- คุณส่งข้อความที่ทริกเกอร์ข้อความ Push ได้สูงสุด 3 ข้อความในช่วงเวลา 24 ชั่วโมง Google อาจจำกัดโควต้าการส่งข้อความ Push หากพิจารณาว่าคุณกำลังสแปมผู้ใช้
- Google Wallet จะควบคุมข้อความ Push ที่ผู้ใช้เห็นบนหน้าจอล็อก
- คุณสามารถใช้เมธอด UPDATE หรือ PATCH เพื่อแก้ไขหรือนำข้อมูลข้อความออกโดยใช้ปลายทางคลาสหรือออบเจ็กต์ปกติ
ขั้นตอนการผสานรวม
เมื่อต้องการแจ้งผู้ใช้เกี่ยวกับข้อความของผู้ออกบัตรใหม่ซึ่งเพิ่มโดยใช้ AddMessage API คุณจะต้องอัปเดต AddMessageRequest เพื่อให้ Message ซึ่งมีข้อความใหม่มี MessageType
TEXT_AND_NOTIFY แทน TEXT
ตัวอย่างคําขอ 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 เพื่อเพิ่มข้อความและแจ้งเตือนในแออบเจ็กต์ Passes
…
"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" ตามที่อธิบายไว้ในขั้นตอนการผสานรวม
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-09-04 UTC
[null,null,["อัปเดตล่าสุด 2025-09-04 UTC"],[[["\u003cp\u003eSend messages to Google Wallet pass users and trigger a push notification using the \u003ccode\u003eTEXT_AND_NOTIFY\u003c/code\u003e message type with the Add Message API.\u003c/p\u003e\n"],["\u003cp\u003eUsers will see a callout on their saved pass prompting them to view the new message, leading them to the pass details.\u003c/p\u003e\n"],["\u003cp\u003eYou can send a maximum of 3 notification-triggering messages per pass within a 24-hour period, with potential throttling for excessive notifications.\u003c/p\u003e\n"],["\u003cp\u003eThe message content can include links to relevant websites or apps associated with the pass, adhering to Google's Acceptable Use Policy.\u003c/p\u003e\n"],["\u003cp\u003eMessages and notifications can be managed through the \u003ccode\u003eUPDATE\u003c/code\u003e or \u003ccode\u003ePATCH\u003c/code\u003e methods for editing or removal.\u003c/p\u003e\n"]]],["The `Add Message API` with `message_type` as `TEXT_AND_NOTIFY` adds a message to the pass's back and sends a push notification. Users tap the notification to view the pass and then access the message, highlighted as unread. Messages can include URIs relevant to the pass. A maximum of 3 notifications are allowed per 24 hours. Use the `AddMessageRequest` and set `MessageType` to `TEXT_AND_NOTIFY`. Exceeding the notification limit triggers a `QuotaExceededException`. `TEXT` can still be used.\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/generic/rest/v1/genericclass/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/generic/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/generic/rest/v1/genericclass/update) or [PATCH](/wallet/generic/rest/v1/genericclass/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/generic/rest/v1/genericclass/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)."]]