總覽
Google Wallet 票證 API 可讓合作夥伴將旋轉條碼儲存到 Google 錢包。這些條碼只會在短時間內有效,可提供額外安全性,降低條碼截圖的風險。條碼會根據 RFC 6238 在裝置上產生,合作夥伴會提供密鑰。不過,如果合作夥伴偏好自行產生條碼,Google 提供的 API 可讓他們將條碼批次上傳至 Google。這些條碼會傳送到使用者的手機,並以旋轉條碼的形式顯示一段時間。我們稱這項解決方案為「合作夥伴產生的旋轉條碼」。
合作夥伴產生的輪替條碼 API
合作夥伴產生的旋轉條碼會使用相同的 RotatingBarcode 物件建立。您只需要提供類型,不過我們也建議您建立一組小型初始條碼 (約 10 分鐘的內容),並透過 initialRotatingBarcodeValues
傳送。合作夥伴必須負責確保使用者隨時都能取得有效的條碼,initialRotatingBarcodeValues
則可讓後續的批次上傳呼叫為非同步。
rotatingBarcode {
initialRotatingBarcodeValues: object (RotatingBarcodeValues),
type: enum (BarcodeType),
}
欄位 |
說明 |
initialRotatingBarcodeValues |
object (RotatingBarcodeValues)
要在條碼中編碼的值。至少要提供一個值。這些初始條碼可在使用者首次取得票證,以及後續批次上傳呼叫之間,提供連結功能。
|
type |
enum (BarcodeType)
必要欄位。這個條碼的類型。
可接受的值為:
|
RotatingBarcodeValues
欄位 |
說明 |
startDateTime |
string
第一個條碼的有效日期/時間。系統會使用 periodMillis 旋轉條碼。
日期/時間採用 ISO 8601 擴充格式 (含有偏移量)。
|
values[] |
string
要在條碼中編碼的值。至少須輸入一個值。
值數量沒有上限,但請注意,要求主體的大小不得超過 5 MB。
|
periodMillis |
number
每個條碼的有效時間。
|
批次更新條碼值
建立 RotatingBarcode 物件後,建議您每天上傳一天份的條碼,直到使用者的票證到期為止。您可以使用下列 REST API 端點執行這項操作。
方法:transitobject.uploadrotatingbarcodevalues
將旋轉條碼值上傳至指定物件 ID 參照的大眾運輸物件。
HTTP 要求
POST
https://walletobjects.googleapis.com/upload/walletobjects/v1/transitObject/{resourc
eId}/uploadRotatingBarcodeValues
路徑參數
參數 |
說明 |
resourceId |
string
物件的專屬 ID。
|
要求主體
要求主體 (不得超過 5 MB) 包含 RotatingBarcodeValues 的例項。
方法:transitobject.downloadrotatingbarcodevalues
為指定物件 ID 參照的大眾運輸物件,下載旋轉條碼值。如果合作夥伴想驗證最新批次,這個方法就很實用。
HTTP 要求
GET
https://walletobjects.googleapis.com/walletobjects/v1/transitObject/{resourceId}/do
wnloadRotatingBarcodeValues?alt=media
路徑參數
參數 |
說明 |
resourceId |
string
物件的專屬 ID。
|
備用機制
請注意,如果原本有效的 RotatingBarcode 沒有有效的條碼可供顯示 (尚未上傳,或已使用所有目前的條碼),系統會向使用者顯示錯誤訊息。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-11-30 (世界標準時間)。
[null,null,["上次更新時間:2024-11-30 (世界標準時間)。"],[[["Google Wallet now supports Partner-Generated Rotating Barcodes for enhanced security, allowing partners to generate and upload time-limited barcodes directly."],["Partners can integrate Rotating Barcodes using the `rotatingBarcode` object within the Google Wallet Passes API, specifying the barcode type and initial values."],["The API provides methods for batch uploading (`transitobject.uploadrotatingbarcodevalues`) and downloading (`transitobject.downloadrotatingbarcodevalues`) barcode values for ongoing updates."],["To ensure continuous barcode availability, it is recommended to upload a day's worth of barcodes daily until a user's pass expires, utilizing the `initialRotatingBarcodeValues` for a smooth initial experience."],["If a Rotating Barcode lacks valid values, an error message will be displayed to the user, highlighting the importance of timely barcode updates."]]],["The Google Wallet Passes API enables partners to use Partner-Generated Rotating Barcodes, enhancing security by having barcodes valid for a short time. Partners can define a `RotatingBarcode` object specifying the barcode `type` and `initialRotatingBarcodeValues`. They then batch upload barcode values using the `transitobject.uploadrotatingbarcodevalues` API endpoint and should upload a day's worth of barcodes each day. Barcode values can be downloaded via `transitobject.downloadrotatingbarcodevalues` for verification. If no valid barcodes are available, an error message is shown.\n"]]