SMS OTP
通过 SMS 发送验证码。 按接收者校验。
SMS 验证会向手机号码发送一次性验证码,并确认输入该验证码的人持有该号码。Bird 生成验证码、发送验证码、对每个接收者设置频率上限,并按接收者进行验证——无需存储 id,也无需对接重发接口。
import { BirdClient } from "@messagebird/sdk";
const bird = new BirdClient({
apiKey: process.env.BIRD_API_KEY!,
});
// Send the code, then check it by recipient.
await bird.verify.verifications.create({
to: { phone_number: "+15551234567" },
}).safe();
const { data, error } = await bird.verify.verifications.check({
to: { phone_number: "+15551234567" },
code: userInput,
}).safe();
if (error) throw error;
Your account
Confirm it’s you.
Enter the code sent to
+1 ••• ••• 4567Example verification code
深受构建世界级软件团队的日常信赖
查看更多客户故事SMS OTP 只需一次调用发送,一次调用校验。
SMS 是 Bird Verify API 上的电话类通道:提交一个包含电话号码的验证请求,我们会通过 Bird 托管的共享发送方发送验证码,默认使用 Bird Verify,也可选择 Authifly;然后通过同一号码进行验证。重新提交创建请求即为重发(创建或重试),会话中的每个验证码在验证通过、过期或尝试次数用尽之前均保持有效。
SMS 验证为您提供的功能。
内置功能,每次发送均生效。
- 01
按手机号寻址。
传入一个 E.164 格式的手机号,我们会自动规范化处理,并通过该号码所属国家对应的发送方以 SMS 发送。
- 02
服务器生成的哈希验证码。
A 6-digit code by default (4–8 configurable), generated with a cryptographic random source and stored only as an HMAC. You never see the plaintext.
- 03
重发即同一调用。
60 秒冷却期过后,重新发送创建请求即可重发验证码:同一会话、新验证码,两个验证码均有效。无需单独的重发接口。
- 04
内置按接收者频率限制。
按接收者的发送上限可控制发送量,防止费用失控,超限时返回 429 并附带 Retry-After。
- 05
覆盖范围按国家扩展。
SMS 目前通过 Bird 托管的共享发送方(Bird Verify 或 Authifly)发送,在允许品牌发送方 ID 的国家/地区显示品牌标识,在有要求的地方使用短代码或本地号码;随着专属和注册发送方的上线,覆盖范围将进一步扩展。
完整流程,仅需两次调用。
创建或重试请求将验证码发送到手机号码;验证请求通过该号码进行确认。两者之间无需传递 id:接收者即为唯一标识。
await bird.verify.verifications.create({
to: { phone_number: "+15551234567" },
}).safe();
const { data, error } = await bird.verify.verifications.check({
to: { phone_number: "+15551234567" },
code: userInput,
}).safe();
if (error) throw error;
// data.success is true or false; data.reason elaborates ("incorrect_code", "expired", "attempts_exhausted")无需存储的验证 API。
SMS 是 Bird Verify 的渠道之一:电子邮件和 WhatsApp 随附提供,语音通道正在上线中,所有渠道共用同一组两个接口。