Skip to content

登录

通过用户名与密码进行身份验证,成功后返回访问令牌及用户信息。支持区分登录来源(前台用户端 / 管理端)和设备类型(移动端、PC、大屏)。

项目
Method POST
URL /api/auth/login
鉴权
参数名 类型 必填 说明
username string 登录用户名
password string 登录密码
device_type string 设备类型:mobile / pc / screen,默认 pc
login_type string 登录来源:frontend / admin,默认 frontend
Terminal window
curl -X POST "https://devapi.fengshengshou.com/api/auth/login" \
-H "Content-Type: application/json" \
-d '{
"username": "zhangsan",
"password": "Pass@1234",
"device_type": "pc",
"login_type": "frontend"
}'
字段 类型 说明
code int 0=成功
message string 提示信息
data.access_token string 访问令牌
data.token_type string 令牌类型,固定值 “Bearer”
data.expires_in int 令牌有效期(秒)
data.user.id int 用户 ID
data.user.username string 登录用户名
data.user.name string 显示名称
data.user.avatar string|null 头像地址,可为空
data.user.user_type int 用户类型编码
data.user.user_type_label string 用户类型名称
data.user.department object|null 所属部门(含 id、name),无则为 null
data.user.position string|null 职位,可为空
data.user.roles array 角色标识字符串数组
data.user.permissions array 权限标识字符串数组
{
"code": 0,
"message": "登录成功",
"data": {
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"token_type": "Bearer",
"expires_in": 3600,
"user": {
"id": 101,
"username": "zhangsan",
"name": "张三",
"avatar": null,
"user_type": 1,
"user_type_label": "普通用户",
"department": { "id": 5, "name": "研发部" },
"position": "工程师",
"roles": ["user"],
"permissions": ["profile:read", "profile:update"]
}
}
}
{ "code": 10001, "message": "用户名或密码错误", "data": null }
{ "code": 10002, "message": "账号已禁用", "data": null }