curl -X POST "http://localhost:5001/manager/login" \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"password": "your_password"
}'
const response = await fetch('http://localhost:5001/manager/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: 'admin',
password: 'your_password'
})
});
const data = await response.json();
console.log(data);
import requests
data = {
"username": "admin",
"password": "your_password"
}
response = requests.post('http://localhost:5001/manager/login', json=data)
result = response.json()
print(result)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
data := map[string]string{
"username": "admin",
"password": "your_password",
}
jsonData, _ := json.Marshal(data)
resp, err := http.Post(
"http://localhost:5001/manager/login",
"application/json",
bytes.NewBuffer(jsonData),
)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expire": 3600,
"user": {
"username": "admin",
"role": "administrator",
"permissions": ["read", "write", "admin"]
}
}
{
"error": "Invalid username or password"
}
管理员
管理员登录
管理员用户登录获取访问令牌
POST
/
manager
/
login
curl -X POST "http://localhost:5001/manager/login" \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"password": "your_password"
}'
const response = await fetch('http://localhost:5001/manager/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: 'admin',
password: 'your_password'
})
});
const data = await response.json();
console.log(data);
import requests
data = {
"username": "admin",
"password": "your_password"
}
response = requests.post('http://localhost:5001/manager/login', json=data)
result = response.json()
print(result)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
data := map[string]string{
"username": "admin",
"password": "your_password",
}
jsonData, _ := json.Marshal(data)
resp, err := http.Post(
"http://localhost:5001/manager/login",
"application/json",
bytes.NewBuffer(jsonData),
)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expire": 3600,
"user": {
"username": "admin",
"role": "administrator",
"permissions": ["read", "write", "admin"]
}
}
{
"error": "Invalid username or password"
}
概述
管理员用户登录接口,用于获取管理后台的访问令牌。请求体
必传参数
string
必填
管理员用户名
string
必填
管理员密码
curl -X POST "http://localhost:5001/manager/login" \
-H "Content-Type: application/json" \
-d '{
"username": "admin",
"password": "your_password"
}'
const response = await fetch('http://localhost:5001/manager/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: 'admin',
password: 'your_password'
})
});
const data = await response.json();
console.log(data);
import requests
data = {
"username": "admin",
"password": "your_password"
}
response = requests.post('http://localhost:5001/manager/login', json=data)
result = response.json()
print(result)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
data := map[string]string{
"username": "admin",
"password": "your_password",
}
jsonData, _ := json.Marshal(data)
resp, err := http.Post(
"http://localhost:5001/manager/login",
"application/json",
bytes.NewBuffer(jsonData),
)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expire": 3600,
"user": {
"username": "admin",
"role": "administrator",
"permissions": ["read", "write", "admin"]
}
}
{
"error": "Invalid username or password"
}
响应字段
string
必填
访问令牌,用于后续 API 调用的认证
integer
必填
令牌过期时间(秒)
状态码
| 状态码 | 说明 |
|---|---|
| 200 | 登录成功 |
| 401 | 用户名或密码错误 |
| 429 | 登录尝试过于频繁 |
| 500 | 服务器内部错误 |
最佳实践
- 密码安全:使用强密码策略,定期更换密码
- 令牌管理:实施令牌自动刷新机制
- 权限控制:基于角色和权限的访问控制
- 登录限制:实施登录尝试次数限制
- 会话管理:合理设置令牌过期时间
- 安全存储:敏感信息不要存储在不安全的地方
⌘I

