门户端接口【内部使用】3、个人中心
3.6 邮箱绑定
POST
/api/oauth/email/bind/code3.6 邮箱绑定
邮箱绑定
接口地址: POST /api/oauth/email/bind/code
权限要求: 🔐 需要登录(User权限)
描述: 使用邮箱验证码绑定邮箱
请求头:
token: {access_token}请求头说明:
token(必填): 访问令牌
请求参数:
email(string, 必填): 新邮箱code(string, 必填): 新邮箱验证码(type 为 bind_change_email)
请求示例:
curl -X POST "https://your-domain.com/api/oauth/email/bind/code" \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \ -H "Content-Type: application/json" \ -d '{ "email": "user@example.com", "code": "123456" }'实现逻辑:
- 根据新邮箱和新邮箱验证码查询
email_verifications表,条件为:email= 新邮箱type=bind_change_emailis_used=falseexpired_at> 当前时间(未过期)
- 如果查询结果存在且验证码匹配,则验证通过
- 验证通过后,将该邮箱的所有验证码的
is_used都设置为true - 检查新邮箱是否已被其他用户使用
- 更新当前用户的邮箱
- 返回绑定成功
返回数据:
{ "success": true, "message": ""}