Skip to content

用户注册

接口说明

新用户注册账号,自动创建亲密度记录。

请求信息

  • Method: POST
  • Path: /v1/auth/register
  • 认证: 不需要

请求参数

json
{
  "username": "string",  // 用户名,3-20个字符,字母数字下划线
  "password": "string"   // 密码,至少6个字符
}

响应示例

json
{
  "code": 0,
  "message": "success",
  "data": {
    "user_id": "95af8297-ae59-4802-bcce-b0e984195d48",
    "username": "testuser",
    "created_at": "2025-10-03T12:29:13Z"
  }
}

错误情况

  • 409: 用户名已存在
  • 400: 参数验证失败

示例代码

bash
curl -X POST http://localhost:8081/v1/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "password": "testpass123"
  }'
javascript
const response = await fetch('http://localhost:8081/v1/auth/register', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    username: 'testuser',
    password: 'testpass123'
  })
});

const data = await response.json();
console.log(data);
python
import requests

response = requests.post(
    'http://localhost:8081/v1/auth/register',
    json={
        'username': 'testuser',
        'password': 'testpass123'
    }
)

print(response.json())

Released under the MIT License.