使用 SMS Retriever API 自动进行短信验证
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 SMS Retriever API,您可以在 Android 应用中自动执行基于短信的用户验证,而无需用户手动输入验证码,也无需任何额外的应用权限。在应用中实现自动短信验证时,验证流程将如下所示:

- 用户在您的应用中启动短信验证。如果用户创建用户的帐号并不需要此信息,您的应用可能会提示用户提供手机号码或使用 Smart Lock(密码专用)提示选择器。
- 应用向服务器请求验证用户的电话号码。
根据用户数据库中提供的信息,此请求可能包含用户 ID 和/或用户电话号码。
- 同时,您的应用调用 SMS Retriever API 开始监听来自服务器的短信响应。
- 您的服务器向用户发送一条短信,其中包含要发回到服务器的一次性代码,以及用于标识应用的哈希值。
- 当用户的设备收到短信时,Google Play 服务使用应用哈希确定该短信是否适用于您的应用,并通过 SMS Retriever API 向您的应用提供短信文字。
- 应用从消息文本中解析出一次性代码并将其发送回服务器。
- 您的服务器从您的应用接收一次性代码,验证代码,并最终记录用户已成功验证其帐号。
如需在您的应用中实现自动短信验证,请参阅 Android 和服务器指南:
Android 指南
服务器指南
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-11-04 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"没有我需要的信息"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"太复杂/步骤太多"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"内容需要更新"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻译问题"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"示例/代码问题"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"易于理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"解决了我的问题"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]