修改管理员密码
1. 接口定位
- 接口名称: 修改管理员密码
- 所属域: admin/account
- 业务目标: 修改指定管理员账号的密码
2. 请求定义
- Method:
POST - Path:
/account/change_password - Content-Type: 推荐
application/json - operationID: 必填,请通过 Header
operationID传入 - 鉴权: 需要 Header
token,且必须是管理员 token - 幂等性: 非幂等
3. 请求参数
Header 参数
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| operationID | 是 | string | 链路追踪 ID |
| token | 是 | string | 管理员 token |
Body 参数
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| userID | 是 | string | 目标管理员用户 ID |
| currentPassword | 是 | string | 目标管理员当前密码 |
| newPassword | 是 | string | 新密码 |
字段约束
userID不能为空。currentPassword不能为空。newPassword不能为空。currentPassword与newPassword不能相同。
4. 响应结构
通用响应包裹
| 字段 | 类型 | 说明 |
|---|---|---|
| errCode | int | 错误码,0 表示成功 |
| errMsg | string | 错误简述 |
| errDlt | string | 错误详情 |
| data | object | 业务数据 |
data 字段
- 成功时返回空对象。
5. 业务规则
- 中间件只要求调用方是管理员,并不会把
userID限定为当前登录管理员。 - RPC 层会按
userID查询目标管理员记录,并用currentPassword做明文比较。 - 只有当
currentPassword与目标管理员当前密码一致时,才会把密码更新成newPassword。 - 本接口没有超级管理员权限校验。
6. 错误码与失败场景
| 错误码 | 场景 | 典型报错 |
|---|---|---|
| 1001 | userID 为空 | userID is empty |
| 1001 | currentPassword 为空 | currentPassword is empty |
| 1001 | newPassword 为空 | newPassword is empty |
| 1001 | 新旧密码相同 | currentPassword is equal to newPassword |
| - | 目标管理员不存在 | 由数据库层返回 |
| - | 当前密码不匹配 | password error |
7. 示例
fetch 请求示例
javascript
fetch("http://localhost:10009/account/change_password", {
method: "POST",
headers: {
operationID: "550e8400-e29b-41d4-a716-446655440104",
token: "eyJhbGciOi...",
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "1000000001",
currentPassword: "OpenIM@123",
newPassword: "OpenIM@456",
}),
})
.then((res) => res.json())
.then((data) => console.log(data));请求示例(JSON)
json
{
"userID": "1000000001",
"currentPassword": "OpenIM@123",
"newPassword": "OpenIM@456"
}成功响应示例
json
{
"errCode": 0,
"errMsg": "",
"errDlt": "",
"data": {}
}失败响应示例
json
{
"errCode": 1001,
"errMsg": "ArgsError",
"errDlt": "currentPassword is equal to newPassword"
}8. 时序流程
- 中间件校验管理员 token。
- 校验
userID/currentPassword/newPassword基本合法性。 - 读取目标管理员记录。
- 比较
currentPassword是否匹配。 - 更新目标管理员密码。
- 返回统一成功响应。
9. 变更记录
- 2026-03-31: 首版发布,基于
ChangeAdminPasswordReq校验规则与 admin RPC 实现补全文档。