用户 API 函数
本节介绍与用户相关的操作。
创建用户
创建一个新的用户账户。
端点:https://petstore3.swagger.io/api/v3/user
操作:POST
示例
- API 密钥
- OAuth 2.0
POST "https://petstore3.swagger.io/api/v3/user" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "api_key: <YOUR_API_KEY>" \
-d '{
"id": 0,
"username": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"phone": "string",
"userStatus": 0
}'
POST "https://petstore3.swagger.io/api/v3/user" \
-H "accept: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"id": 0,
"username": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"phone": "string",
"userStatus": 0
}'
响应
| 代码 | 描述 | | default | 操作成功 |
响应示例
200: successful operation
{
"id": 10,
"username": "theUser",
"firstName": "John",
"lastName": "James",
"email": "john@email.com",
"password": "12345",
"phone": "12345",
"userStatus": 1
}
参数
请求正文
| 名称 | 类型 | 描述 |
|---|---|---|
| body | User 对象 | (必填) 要创建的 User 对象。 |
使用列表创建用户列表
使用给定的输入列表创建用户列表。
端点:https://petstore3.swagger.io/api/v3/user/createWithList
操作:POST
示例
- API 密钥
- OAuth 2.0
POST "https://petstore3.swagger.io/api/v3/user/createWithList" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "api_key: <YOUR_API_KEY>" \
-d \
[
{
"id": 0,
"username": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"phone": "string",
"userStatus": 0
}
]
POST "https://petstore3.swagger.io/api/v3/user/createWithList" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>" \
-d \
[
{
"id": 0,
"username": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"phone": "string",
"userStatus": 0
}
]
响应
| 代码 | 描述 |
|---|---|
| 默认 | 操作成功 |
响应示例
200: Successful operation
{
"id": 0,
"username": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"phone": "string",
"userStatus": 0
}
参数
请求正文
| 名称 | 类型 | 描述 |
|---|---|---|
| body | User 对象数组 | (必填) 要创建的 User 对象列表。 |
登录
将用户登录到系统。
端点:https://petstore3.swagger.io/api/v3/user/login
操作:GET
示例
- API 密钥
- OAuth 2.0
GET "https://petstore3.swagger.io/api/v3/user/login?username=string&password=string" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"
GET "https://petstore3.swagger.io/api/v3/user/login?username=string&password=string" \
-H "accept: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>"
响应
| 代码 | 描述 |
|---|---|
| 200 | 操作成功 |
| 400 | 提供的用户名/密码无效 |
| default | 意外错误 |
响应示例
200: successful operation
{
"message": "logged in user session:abcdef12345"
}
标头:
| 名称 | 描述 | 类型 |
|---|---|---|
X-Rate-Limit | 用户每小时允许的调用次数。 | 整数 |
X-Expires-After | 令牌过期的 UTC 时间。 | 字符串 |
参数
查询参数
| 名称 | 类型 | 描述 |
|---|---|---|
| 用户名 | 字符串 | 用于登录的用户名。 |
| 密码 | 字符串 | 用于登录的明文密码。 |
注销
注销当前已登录用户的会话。
端点:https://petstore3.swagger.io/api/v3/user/logout
操作:GET
示例
- API 密钥
- OAuth 2.0
GET "https://petstore3.swagger.io/api/v3/user/logout" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"
GET "https://petstore3.swagger.io/api/v3/user/logout" \
-H "accept: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>"
响应
| 代码 | 描述 |
|---|---|
| 200 | 操作成功 |
| 默认 | 操作成功 |
响应示例
200: successful operation
{
"message": "Successfully logged out"
}
参数
无
按用户名获取用户
根据用户名获取用户。
端点:https://petstore3.swagger.io/api/v3/user/{username}
操作:GET
示例
- API 密钥
- OAuth 2.0
GET "https://petstore3.swagger.io/api/v3/user/user1" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"
GET "https://petstore3.swagger.io/api/v3/user/user1" \
-H "accept: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>"
响应
| 代码 | 描述 |
|---|---|
| 200 | 操作成功 |
| 400 | 提供的用户名无效 |
| 404 | 未找到用户 |
| default | 意外错误 |
200: successful operation
{
"id": 0,
"username": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"phone": "string",
"userStatus": 0
}
参数
路径参数
| 名称 | 类型 | 描述 |
|---|---|---|
| username | 字符串 | 要查询的用户名。测试时请使用 "user"。 |
更新用户
更新用户。
端点:https://petstore3.swagger.io/api/v3/user/{username}
操作:PUT
示例
- API 密钥
- OAuth 2.0
PUT "https://petstore3.swagger.io/api/v3/user/user1" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "api_key: <YOUR_API_KEY>" \
-d '{
"id": 0,
"username": "user1",
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"phone": "string",
"userStatus": 0
}'
PUT "https://petstore3.swagger.io/api/v3/user/user1" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>" \
-d '{
"id": 0,
"username": "user1",
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"phone": "string",
"userStatus": 0
}'
响应
| 状态码 | 说明 |
|---|---|
| 200 | 操作成功 |
| 400 | 提供的用户名无效 |
| 404 | 用户不存在 |
| 默认 | 意外错误 |
(更新成功时返回 200 状态码,且无响应正文。)
参数
路径参数
| 名称 | 类型 | 描述 |
|---|---|---|
| username | 字符串 | 要更新的用户的用户名 |
请求正文
| 名称 | 类型 | 描述 |
|---|---|---|
| body | User 对象 | (必填) 包含更新信息的 User 对象。 |
删除用户
删除用户。
端点:https://petstore3.swagger.io/api/v3/user/{username}
操作:DELETE
示例
- API 密钥
- OAuth 2.0
DELETE "https://petstore3.swagger.io/api/v3/user/user1" \
-H "accept: application/json" \
-H "api_key: <YOUR_API_KEY>"
DELETE "https://petstore3.swagger.io/api/v3/user/user1" \
-H "accept: application/json" \
-H "Authorization: Bearer <YOUR_OAUTH_TOKEN>"
响应
| 状态码 | 描述 |
|---|---|
| 200 | 用户已删除 |
| 400 | 提供的用户名无效 |
| 404 | 未找到用户 |
(删除成功将返回 200 状态码,且无响应正文。)
参数
路径参数
| 名称 | 类型 | 描述 |
|---|---|---|
| username | 字符串 | 要删除的用户名 |