Automatyczna weryfikacja SMS-ów za pomocą interfejsu SMS Retriever API
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Interfejs SMS Fetcher API umożliwia automatyczną weryfikację użytkowników przy użyciu SMS-ów w aplikacji na Androida bez konieczności ręcznego wpisywania kodów weryfikacyjnych i bez wymagania dodatkowych uprawnień aplikacji. Gdy zaimplementujesz w swojej aplikacji automatyczną weryfikację SMS, proces weryfikacji wygląda tak:

- Użytkownik inicjuje weryfikację SMS-em w Twojej aplikacji. Aplikacja może poprosić użytkownika o podanie numeru telefonu lub użycie selektora Smart Lock na hasła, jeśli te informacje nie są potrzebne do utworzenia konta.
- Aplikacja wysyła do serwera żądanie weryfikacji numeru telefonu użytkownika.
W zależności od tego, jakie informacje są dostępne w bazie danych użytkowników, żądanie może obejmować identyfikator użytkownika, numer telefonu użytkownika lub oba te elementy.
- Jednocześnie aplikacja wywołuje interfejs SMS Fetcher API, który zaczyna słuchać odpowiedzi z serwera.
- Serwer wysyła do użytkownika SMS-a z kodem jednorazowym, który ma zostać wysłany z powrotem na serwer, oraz haszem identyfikującym aplikację.
- Gdy urządzenie użytkownika otrzyma SMS-a, Usługi Google Play korzystają z haszu aplikacji, aby określić, czy wiadomość jest przeznaczona dla aplikacji, i udostępnia jej treść za pomocą interfejsu SMS Fetcher.
- Aplikacja analizuje jednorazowy kod z tekstu wiadomości i wysyła go z powrotem na serwer.
- Serwer odbiera jednorazowy kod z aplikacji, weryfikuje go, a na koniec rejestruje, że użytkownik potwierdził własność konta.
Aby zaimplementować w aplikacji automatyczną weryfikację SMS, zapoznaj się z przewodnikami dotyczącymi Androida i serwera:
Przewodnik Androida
Przewodnik po serwerze
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-25 UTC.
[null,null,["Ostatnia aktualizacja: 2025-07-25 UTC."],[[["\u003cp\u003eThe SMS Retriever API enables automatic SMS verification in Android apps, eliminating manual code entry for users.\u003c/p\u003e\n"],["\u003cp\u003eThis API streamlines user verification by having your app listen for an SMS message containing a one-time code, sent by your server after a verification request.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Play services identifies the incoming SMS message as intended for your app using an app hash included in the message, ensuring secure delivery of the verification code.\u003c/p\u003e\n"],["\u003cp\u003eThe SMS Retriever API enhances user experience and security by automating verification without requiring extra app permissions.\u003c/p\u003e\n"]]],[],null,["# Automatic SMS Verification with the SMS Retriever API\n\nWith the SMS Retriever API, you can perform SMS-based user verification in your\nAndroid app automatically, without requiring the user to manually type\nverification codes, and without requiring any extra app permissions. When you\nimplement automatic SMS verification in your app, the verification flow looks\nlike this:\n\n[](/static/identity/sms-retriever/flow-overview.png)\n\n1. A user initiates SMS verification in your app. Your app might prompt the user to provide a phone number or use the [Smart Lock for Passwords hint selector](/identity/smartlock-passwords/android/retrieve-hints) if that information wasn't required to create the user's account.\n2. Your app makes a request to your server to verify the user's phone number. Depending on what information is available in your user database, this request might include the user's ID, the user's phone number, or both.\n3. At the same time, your app calls the SMS Retriever API to begin listening for an SMS response from your server.\n4. Your server sends an SMS message to the user that includes a one-time code to be sent back to your server, and a hash that identifies your app.\n5. When the user's device receives the SMS message, Google Play services uses the app hash to determine that the message is intended for your app, and makes the message text available to your app through the SMS Retriever API.\n6. Your app parses out the one-time code from the message text and sends it back to your server.\n7. Your server receives the one-time code from your app, verifies the code, and finally records that the user has successfully verified their account.\n\nTo implement automatic SMS verification in your app, see the Android and server\nguides:\n\n[Android Guide](/identity/sms-retriever/request)\n[Server Guide](/identity/sms-retriever/verify)"]]