Send a one-time code over email, SMS, or WhatsApp, then check it by recipient, with no verification id to keep between the two calls. The channel order, sender, and code rules already resolve per country automatically. Same auth and idempotency as every other Bird channel, because the same team built them all. Voice is rolling out next.
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;
从npm install到用户验证,仅需两次调用
用您已熟悉的语言发送并验证验证码。
Create-or-retry 发送验证码;check 按接收方确认验证码。两次调用,无需在它们之间传递验证 ID。
const verification = await bird.verify.verifications.create({
to: { phone_number: "+15551234567" },
});
console.log(verification.id, verification.status);十项您无需自行构建的功能
——当验证就是 API。
具体的基础组件,命名清晰、可配置。绝不含糊。
- 01
一次调用即可创建或重试。
重新提交相同的接收方,我们会恢复当前会话,并在冷却时间过后重新发送。无需单独的重发端点,不会产生重复验证。
- 02
按目标检查,无需存储。
提交接收方和验证码;我们通过配置与接收方的组合解析会话。发送和检查之间无需持久化验证 ID。
- 03
首发支持邮件、SMS 和 WhatsApp。
您传入的收件人决定了使用哪个通道:电子邮件地址通过邮件验证,电话号码通过 SMS 或 WhatsApp 验证。切换通道只需更改一个字段,无需重新集成。语音通道即将上线,通道间自动降级回退也在规划中。
- 04
Per-country channel order, already resolved.
Channel order, sender, and which channels are on differ by country. Bird's per-country base decides this, so a create call already resolves to the right plan everywhere.
- 05
您永远看不到的验证码。
验证码通过加密随机源生成,仅以 HMAC 形式存储,并在恒定时间内进行比较。明文验证码不会触及您的技术栈或我们的日志。
- 06
可配置的验证码、TTL 和尝试次数。
Six-digit default, 4–10 configurable per request; a 10-minute window; 5 attempts; a 60-second resend cooldown.
- 07
每个验证码在会话结束前始终有效。
延迟送达的消息和重新发送的验证码都可用于验证,因为我们不会在发送新验证码时使旧验证码失效。
- 08
错误的验证码返回 200,而非异常。
通过布尔结果校验答案——该验证码是否通过验证,是或否——并附带原因说明失败情况:无效、已过期、已验证或尝试次数用尽。您只需根据字段值进行分支判断,无需捕获抛出的异常。
- 09
内置速率限制。
按接收者的发送上限和按验证的猜测次数限制——每项超限均返回 429 及 Retry-After,让暴力攻击在耗尽您的资源之前先耗尽自身。
- 10
与 Bird 其他产品相同的接口契约。
Bearer 认证、幂等键、带类型的 vrf_ ID、统一错误信封。您为邮件编写的处理逻辑同样适用于验证。
探索 Verify 平台
每项能力的深度解析。一套 API,一组密钥。
在发送和验证之间无需存储任何内容。
大多数验证 API 会返回一个 ID,需要您持久化、查询并提交验证码进行校验。Bird 通过接收者解析会话,因此您无需维护任何按验证的状态。
大多数验证 API
创建请求返回一个您需要存储的 ID,然后查找该验证记录以校验验证码。
const { id } = await api.verifications.create({
to: "+15551234567",
});
// persist id somewhere, then later…
await api.verifications.check({ id, code });
Bird Verify
按接收者校验。两次调用之间无需传递任何内容。
await bird.verify.verifications.create({
to: { phone_number: "+15551234567" },
}).safe();
// no id to store; check by the same recipient
await bird.verify.verifications.check({
to: { phone_number: "+15551234567" }, code,
}).safe();
Routing already knows the country.
Channel order, senders, and which channels are on differ by country: WhatsApp-first in one market, SMS-only in another. Bird's per-country base decides this, so a create call already resolves to the right plan. See channel orchestration.
// Brazil already resolves WhatsApp, then SMS.
const { data, error } = await bird.verify.verifications.create({
to: { phone_number: "+5511998765432" },
}).safe();
if (error) throw error;
我们为何构建 Verify
因为让用户登录的验证码不应该需要一张专属数据库表。
OTP 是这样一种渠道:验证码送达失败意味着注册流程中断。Bird 已大规模运行邮件和 SMS,因此 Verify 就是在此投递能力之上加上验证码生成、会话管理、按国家渠道方案和速率限制——仅需两个端点,您无需存储任何内容,响应格式与所有其他 Bird 渠道一致。
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;
如果您已集成 SMS,就等于已集成 Verify。
相同的认证模型、相同的幂等性契约、相同的错误信封。不同之处在于 Verify 负责生成验证码、选择渠道并执行速率限制,您无需处理这些。
Verify
一次调用发送验证码,一次调用按接收者校验。验证码、会话和频率限制均由我们管理。
await bird.verify.verifications.create({
to: { phone_number: "+15551234567" },
});SMS
原始发送模式,适用于您希望自行控制验证码生成和重试策略的场景。
await bird.sms.send({
from: "Bird",
to: "+15551234567",
text: `Your code is ${code}.`,
category: "authentication",
});选择用户看到的发送者身份
验证码默认以 Bird Verify 的身份发送,无需注册或设置模板。将某个渠道切换为 Authifly 后,用户看到的将是一个中立的验证身份,而非平台供应商:OTP 邮件来自 otp@verify.authifly.com,SMS 在目的地国家允许品牌发送者的情况下显示 Authifly 发送者。Bird 同时运营两种身份,因此切换不会产生任何额外费用,且您可以按渠道和国家自由选择。在邮件渠道上,您还可以更进一步,使用您自己验证过的域名进行发送。如果收件人收到了意外的验证码,authifly.com 会向其确认 Authifly 是代表企业发送合法一次性验证码的服务。Authifly 由 Bird B.V. 运营。
访问 authifly.com