我應該使用哪個 API?
Google Play 服務有兩個 API,可用來簡化以簡訊為基礎的驗證程序:SMS Retriever API 和 SMS User Consent API。
SMS Retriever API 提供全自動化的使用者體驗,請盡可能使用。不過,您必須自行在郵件內文中加上自訂雜湊碼,否則即使您並非該訊息的寄件者,這也很難做到。
如果您無法控制訊息內容,例如您的應用程式與金融機構合作,想在驗證付款交易前驗證使用者的電話號碼,則可使用 SMS User Consent API,不需要自訂雜湊碼。不過,使用者必須核准應用程式存取包含驗證碼的訊息。為盡量減少向使用者顯示錯誤訊息的機會,簡訊使用者同意授權訊息會檢查訊息是否包含長度至少為一組 4 至 10 個字元的英數代碼。藉此過濾來自使用者聯絡人清單中的寄件者寄出的郵件。
下表匯總了不同之處:
|
簡訊擷取器 |
簡訊使用者同意聲明 |
訊息規定 |
11 位數的雜湊代碼,可用於識別應用程式 |
至少包含 1 位數的 4 到 10 位數英數字元代碼 |
寄件者規定 |
無 |
寄件者不在使用者的聯絡人清單中 |
使用者互動 |
無 |
輕觸一下即可核准 |
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2022-10-18 (世界標準時間)。
[null,null,["上次更新時間:2022-10-18 (世界標準時間)。"],[[["Google Play services offers two APIs, SMS Retriever and SMS User Consent, to simplify SMS-based verification in your app."],["SMS Retriever API automates verification but requires a custom hash code in the SMS message, ideal when you control message content."],["SMS User Consent API, best for scenarios where you don't control the SMS message (like with financial institutions), requires user approval to access the message but doesn't need a custom hash code."],["SMS User Consent API enhances security by filtering messages from known contacts and focusing on messages containing a 4-10 digit alphanumeric code with at least one number."]]],[]]