devgo 文档 更新 API 验证码 API 版本管理后台

通用验证码服务 API

与登录流程解耦的邮箱验证码服务:发送验证码、校验验证码、消费验证凭证。登录、改密、换绑、敏感操作、客户端接入等任意场景均可复用。

目录
  1. 基础信息
  2. 场景(scene)
  3. 发送验证码
  4. 校验验证码
  5. 消费验证凭证
  6. 典型接入流程
  7. 错误码

基础信息

Base URLhttps://devgo.online/api/verify
认证三个端点均无需认证(公开验证接口)
Content-Typeapplication/json
响应格式{"code":0,"data":...,"msg":"..."};code=0 成功,code<0 失败
验证码与凭证均有有效期与尝试次数限制(防爆破),且一次性使用后立即作废。请勿在生产环境用固定邮箱反复测试。

场景(scene)

scene 用于区分验证码用途,同一邮箱不同场景的验证码互不影响。取值规则:^[a-z0-9_-]{1,32}$(字母、数字、下划线、连字符,32 字以内)。

scene用途
login登录 / 注册(默认值)
reset_password重置密码
change_password修改密码
change_email更换邮箱
bind / unbind绑定 / 解绑账号
delete_account注销账号
自定义任意合法标识,邮件内会显示「身份验证」通用文案

发送验证码

POST/api/verify/send无需认证

向指定邮箱发送 6 位数字验证码。

请求参数

参数类型必填说明
emailstring是接收验证码的邮箱
scenestring否场景标识,默认 login

请求 / 响应示例

curl -X POST https://devgo.online/api/verify/send \
  -H "Content-Type: application/json" \
  -d '{"email":"user@example.com","scene":"login"}'

# 成功
{"code":0,"data":null,"msg":"验证码已发送,请查收邮箱(注意垃圾箱)"}

# 发送太频繁(60 秒内重发)
{"code":-1,"msg":"发送太频繁,请 42 秒后再试"}   # HTTP 429

校验验证码

POST/api/verify/check无需认证

校验验证码,成功后返回一次性验证凭证 verify_token。

请求参数

参数类型必填说明
emailstring是邮箱
codestring是6 位验证码
scenestring否场景标识,默认 login,需与发送时一致

响应字段

字段类型说明
verify_tokenstring一次性验证凭证,用于后续敏感操作
emailstring通过验证的邮箱
scenestring验证的场景
expires_atstring凭证过期时间(10 分钟)

请求 / 响应示例

curl -X POST https://devgo.online/api/verify/check \
  -H "Content-Type: application/json" \
  -d '{"email":"user@example.com","code":"123456","scene":"login"}'

# 成功
{"code":0,"data":{
  "verify_token":"042a07d8a7f99e2d510a8ad7f071a6d1...",
  "email":"user@example.com",
  "scene":"login",
  "expires_at":"2026-11-27 20:23:14"
},"msg":"验证通过"}

# 失败(错误或过期)
{"code":-1,"msg":"验证码错误或已过期,请重新获取"}

消费验证凭证

POST/api/verify/confirm无需认证

消费一次性 verify_token,确认「某邮箱刚通过了某场景的验证」。供改密码、换绑邮箱、注销等两步式敏感操作调用。

请求参数

参数类型必填说明
verify_tokenstring是校验验证码得到的凭证
scenestring否期望的场景,不匹配则拒绝

请求 / 响应示例

curl -X POST https://devgo.online/api/verify/confirm \
  -H "Content-Type: application/json" \
  -d '{"verify_token":"042a07d8...","scene":"reset_password"}'

# 成功(凭证已作废,不可复用)
{"code":0,"data":{"email":"user@example.com","scene":"reset_password"},"msg":"凭证有效"}

# 无效 / 已过期 / 已使用
{"code":-2,"msg":"验证凭证无效或已过期"}   # HTTP 401

典型接入流程

① 登录(一步式)

# 直接用现有登录接口即可,无需 verify_token
curl -X POST https://devgo.online/api/auth/send_code -d '{"email":"user@example.com"}'
curl -X POST https://devgo.online/api/auth/login -d '{"email":"user@example.com","code":"123456"}'

② 改密码(两步式,推荐用 verify_token)

# 第一步:发码 + 校验,拿到 verify_token
curl -X POST https://devgo.online/api/verify/send -d '{"email":"user@example.com","scene":"reset_password"}'
curl -X POST https://devgo.online/api/verify/check -d '{"email":"user@example.com","code":"123456","scene":"reset_password"}'
# → 得到 verify_token

# 第二步:用 verify_token 执行实际改密(业务接口自行校验凭证)
curl -X POST https://devgo.online/api/account/reset_password \
  -d '{"verify_token":"042a07d8...","new_password":"..."}'
verify_token 是「这个邮箱通过了验证」的凭据,与具体业务解耦。你的后端拿到 token 后,调一次 /api/verify/confirm 确认有效,再执行改密/换绑/注销等操作即可,无需自己保存验证码状态。

错误码

codeHTTP含义
0200成功
-1200/429业务失败(参数错误、验证码错误、发送太频繁等,见 msg)
-2401凭证无效 / 已过期 / 场景不匹配

安全限制

项值
验证码有效期10 分钟
重发间隔60 秒
最大尝试次数5 次(超出作废)
verify_token 有效期10 分钟,一次性