账密登录注册一体 API
最近更新日期:2026-01-24 19:17:59
接口说明
登录和注册一体化的接口。如果账号不存在,会先自动注册,然后登录;如果账号已存在,则直接验证密码进行登录。
请求信息
接口地址
POST /user/login请求头
Content-Type: application/x-www-form-urlencoded请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
| account | string | 是 | 登录账号 | - |
| password | string | 是 | 登录密码 | - |
| day | integer | 否 | Token 有效期(天),默认 3 天 | 3 |
响应信息
成功响应
- 状态码: 200
- Content-Type:
application/json - 说明: 请求成功,返回登录结果
响应体示例
json
{
"code": 0,
"message": "success",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user_info": {
"id": 1,
"account": "user@example.com"
}
}
}使用示例
cURL
bash
curl -X POST "https://api.example.com/api/user/login" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "account=user@example.com&password=yourpassword&day=7"Python
python
import requests
url = "https://api.example.com/api/user/login"
data = {
"account": "user@example.com",
"password": "yourpassword",
"day": 7
}
response = requests.post(url, data=data)
print(response.json())注意事项
- 首次使用不存在的账号调用此接口,系统会自动注册该账号
- 密码建议使用加密传输
- Token 有效期最长建议不超过 30 天
- 该接口仍在开发中,可能会有所调整
状态码说明
- 200: 请求成功
- 400: 请求参数错误
- 401: 账号或密码错误
- 500: 服务器内部错误