5.4 手机号验证码登录【参数校验通过,待业务联调】

POST /tieup/api/v1/auth/sms-login

请求前置:

POST /tieup/api/v1/auth/sms-codes
{
  "phone": "13800000000",
  "scene": "login"
}

请求体:

{
  "phone": "13800000000",
  "sms_code": "123456"
}

请求参数:

参数 类型 必填 说明
phone string 中国大陆 11 位手机号
sms_code string 6 位数字验证码

响应说明:返回完整登录 Token 结构,并在 data 第一层返回 is_new_user;验证码登录自动创建账号时为 true,已注册账号登录时为 falseuser.current_identity 默认为 fanuser 完整字段定义与注册接口一致。

响应字段:

字段 类型 说明
access_token string APP Access Token
refresh_token string APP Refresh Token
expires_in integer Access Token 有效时长,单位秒
is_new_user boolean 是否本次验证码登录自动创建新账号
user object 当前用户完整资料对象
user.profile_completion_step integer 当前资料完善步骤:0=未上传头像,1=已上传头像但核心资料未完善,2=核心资料已完善
user.current_identity string 用户当前使用端
user.available_identities array 当前用户可切换的使用端列表

响应示例:

{
  "code": 200,
  "message": "成功",
  "data": {
    "access_token": "app_access_token",
    "refresh_token": "app_refresh_token",
    "expires_in": 7200,
    "is_new_user": true,
    "user": {
      "id": 10001,
      "rong_user_id": "tieup_fan_10001",
      "group_code": "tieup",
      "channel_code": "appstore",
      "phone": "13800138000",
      "nickname": "用户8000",
      "avatar": "",
      "profile_completion_step": 0,
      "gender": 0,
      "age": null,
      "province_code": null,
      "province_name": null,
      "city_code": null,
      "city_name": null,
      "district_code": null,
      "district_name": null,
      "signature": null,
      "status": 1,
      "is_idol": 2,
      "candy_balance": "0.00",
      "online_status": 0,
      "current_identity": "fan",
      "available_identities": [
        "fan"
      ]
    }
  }
}

业务规则:

  • 服务端根据 X-App-Channel 解析 channel_codegroup_code,验证码只能在当前渠道消费。
  • 验证 login 场景短信验证码后先写入短 TTL 占用标记,不提前删除验证码;登录或自动注册成功后才原子删除验证码和占用标记,业务失败时释放占用并保留验证码原有效期。
  • 同一验证码并发提交时只有一个请求能占用处理,其他请求会提示验证码正在处理中或校验失败,避免重复创建账号或重复消费验证码。
  • 已注册手机号直接登录,登录成功后更新 last_login_atlast_login_iplast_active_at,返回 is_new_user = false
  • 未注册手机号自动创建普通粉丝账号,默认 status = 1is_idol = 2password_hash = null,后续可通过找回密码流程补齐密码,本次返回 is_new_user = true
  • 自动注册写操作使用数据库事务,tieup_user.uk_channel_phone 作为并发创建兜底;旧环境需确认该唯一索引已按注册章节说明完成迁移。
  • status = 2 禁用、status = 3 最终注销的账号禁止登录;status = 4 注销中的账号在 7 天冷静期内登录会自动恢复为正常。
  • 验证码登录接口按 channel_code + phone 做 Redis 限流,默认 60 秒最多 10 次。
  • 自动注册用户头像为空,user.profile_completion_step0;已注册用户按当前资料实时计算步骤。
  • 测试状态:已完成代码实现和 PHP 语法检查,待短信验证码登录链路联调。