Skip to content

API Name

API Description

关于 apihub-token

apihub-token 可以是你自行生成的 app_tokenapp_token 拥有最高权限。

也可以是你自行生成的 person_token,需要 token_payload 中 roles 列表包含 ADMIN 元素。

也可以是 用户中心_我的 模块下的 登录/注册/刷新Token 接口返回值中的 token 字段。该 token 实际上是一个 person_token

关于 token 生成,详见:API Key 使用说明

用户

创建用户

person_token 创建出的用户固定为 MEMBER 类型

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/create-user
apihub-token: {{token}}

{
    "username": "lisi3",
    "password": "12345678"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
usernamejsonBodystr登录账号
passwordjsonBodystr密码明文
user_typejsonBodystr枚举:ADMINMEMBER。默认:MEMBER
attrsjsonBodydict用户拓展属性
sys_attrsjsonBodydict用户拓展系统属性

返回值说明

json
{
    "success": true,
    "trace": "636f0a382a0111f0a31dc6807b612ccf",
    "result": {
        "_id": "68193d6e39126a71b209fe94",
        "username": "lisi3",
        "type": "MEMBER",
        "password": "$2b$12$kSMJ6yseeVUjUGlW5JXpO.JNEjpoCyrw31wtErNccgOxk/5vHWDnq",
        "attrs": {
            "avatar": "https://apihub-net.oss-cn-beijing.aliyuncs.com/img/default-avatar.jpg",
            "nickname": "lisi3"
        },
        "enable": true,
        "firstCreated": "2025-05-06T06:36:30.251000",
        "ak": "67fca7a97a883fac3a981a83",
        "isDel": 0
    }
}

查询用户列表

person_token 只能查看 MEMBER 类型的用户。

调用示例

sh
GET https://open.apihub.net/api/user-center-admin/list-users
apihub-token: {{token}}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
user_typejsonBodystr枚举:ADMINMEMBER。默认:MEMBER
searchjsonBodystr模糊查询,username、attrs.nickname、、sys_attrs.name、sys_attrs.email、sys_attrs.phone 等字段
skipqueryParamsnumber跳过前多少条数据。 默认:0
limitqueryParamsnumber至多返回多少条数据。 默认:10
sort_keyqueryParamsstr排序字段。 默认:firstCreated
sort_directionqueryParamsnumber降序:-1 。 升序:1 。默认:-1

返回值说明

json
{
    "success": true,
    "trace": "800c8d442a0311f092bdc6807b612ccf",
    "result": {
        "total": 6,
        "items": [
            {
                "_id": "68193d6e39126a71b209fe94",
                "username": "lisi3",
                "type": "MEMBER",
                "password": "$2b$12$kSMJ6yseeVUjUGlW5JXpO.JNEjpoCyrw31wtErNccgOxk/5vHWDnq",
                "attrs": {
                    "avatar": "https://apihub-net.oss-cn-beijing.aliyuncs.com/img/default-avatar.jpg",
                    "nickname": "lisi3"
                },
                "enable": true,
                "firstCreated": "2025-05-06T06:36:30.251000",
                "ak": "67fca7a97a883fac3a981a83",
                "isDel": 0
            },
            {...}
        ]
    }
}

查询指定用户 by_id

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/get-user-by-id
apihub-token: {{token}}

{
    "target_user_id": "68193d6e39126a71b209fe94"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
target_user_idjsonBodystruser 的 _id 字段

返回值说明

json
{
    "success": true,
    "trace": "636f0a382a0111f0a31dc6807b612ccf",
    "result": {
        "_id": "68193d6e39126a71b209fe94",
        "username": "lisi3",
        "type": "MEMBER",
        "password": "$2b$12$kSMJ6yseeVUjUGlW5JXpO.JNEjpoCyrw31wtErNccgOxk/5vHWDnq",
        "attrs": {
            "avatar": "https://apihub-net.oss-cn-beijing.aliyuncs.com/img/default-avatar.jpg",
            "nickname": "lisi3"
        },
        "enable": true,
        "firstCreated": "2025-05-06T06:36:30.251000",
        "ak": "67fca7a97a883fac3a981a83",
        "isDel": 0
    }
}

查询指定用户列表 by_ids

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/list-users-by-ids
apihub-token: {{token}}

{
    "user_ids": ["68193d6e39126a71b209fe94"]
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
user_idsjsonBodylist[str]user 的 _id 字段

返回值说明

json
{
    "success": true,
    "trace": "435992342a2111f08263c6807b612ccf",
    "result": [
        {
            "_id": "68193d6e39126a71b209fe94",
            "username": "lisi3",
            "type": "MEMBER",
            "password": "$2b$12$fPpRvCqeSoN/tCbGN4RU2OB8s.MBlf9fM/.l2HE6VO/4U5RUWPeu2",
            "attrs": {
                "avatar": "https://apihub-net.oss-cn-beijing.aliyuncs.com/img/default-avatar.jpg",
                "nickname": "lisi3"
            },
            "enable": true,
            "firstCreated": "2025-05-06T06:36:30.251000",
            "ak": "67fca7a97a883fac3a981a83",
            "isDel": 0,
            "lastModified": "2025-05-06T08:14:08.204000",
            "trial_end_at": 1748707200
        }
    ]
}

查询指定用户 by_name

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/get-user-by-username
apihub-token: {{token}}

{
    "username": "lisi3"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
usernamejsonBodystruser 的 username 字段,精确匹配

返回值说明

json
{
    "success": true,
    "trace": "636f0a382a0111f0a31dc6807b612ccf",
    "result": {
        "_id": "68193d6e39126a71b209fe94",
        "username": "lisi3",
        "type": "MEMBER",
        "password": "$2b$12$kSMJ6yseeVUjUGlW5JXpO.JNEjpoCyrw31wtErNccgOxk/5vHWDnq",
        "attrs": {
            "avatar": "https://apihub-net.oss-cn-beijing.aliyuncs.com/img/default-avatar.jpg",
            "nickname": "lisi3"
        },
        "enable": true,
        "firstCreated": "2025-05-06T06:36:30.251000",
        "ak": "67fca7a97a883fac3a981a83",
        "isDel": 0
    }
}

查询指定用户 by_sys_attr

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/get-user-by-sys-attr
apihub-token: {{token}}

{
    "key": "weixin_mp_openid",
    "value": "os8a768v-MjAEh50nI0OgSnFsczU"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
keyjsonBodystrsys_attrs 下的字段名
valuejsonBodystr/number/...sys_attrs 下 key 字段对应的 value 值。精确匹配,包括数据类型也要一致。

返回值说明

只返回一个用户。如果满足条件的用户有多个,也只返回一个用户。

json
{
    "success": true,
    "trace": "18ea23962d6511f08389c6807b612ccf",
    "result": {
        "_id": "68192d48f5c8cf959aeca7ca",
        "username": "chenyan2",
        "type": "MEMBER",
        "password": "$2b$12$eLsyLYkvPaY.x1vgZGeamOZUvnAukWVrIOtNwZPolnYJXw6Ni3Jwe",
        "attrs": {
            "avatar": "https://apihub-net.oss-cn-beijing.aliyuncs.com/img/default-avatar.jpg",
            "nickname": "chenyan2",
            "any": null
        },
        "enable": true,
        "firstCreated": "2025-05-06T05:27:36.755000",
        "ak": "67fca7a97a883fac3a981a83",
        "isDel": 0,
        "lastModified": "2025-05-10T14:05:50.068000",
        "search": "chenyan2    chenyan2",
        "sys_attrs": {
            "weixin_mp_openid": "os8a768v-MjAEh50nI0OgSnFsczU"
        }
    }
}

修改用户属性

注意:普通用户自身也具备接口权限修改 自己的用户属性(attrs) 。如果不希望属性值被用户自行修改,可使用 修改用户系统属性(sys_attrs) 接口。

调用示例

sh
PUT https://open.apihub.net/api/user-center-admin/save-user-attrs
apihub-token: {{token}}

{
    "target_user_id": "68193d6e39126a71b209fe94",
    "attrs": {
        "any.thing": 123
    }
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
target_user_idjsonBodystruser 的 _id 字段
attrsjsonBodydict可以往 user 对象的 attrs 字段中添加任意信息。
注意:用户自身也有权限自行修改 attrs 下的信息。
1. 对于参数中存在,数据库中不存在的字段,将新增字段。
2. 对于参数中不存在,数据库存在的字段,将不受影响。
3. 对于参数中存在,数据库也存在的字段,将进行覆盖更新操作。
4. 参数名中使用点号.分割,可局部更新深层对象。

返回值说明

json
{
    "success": true,
    "trace": "9389fd702a0d11f088d1c6807b612ccf",
    "result": {
        "_id": "68193d6e39126a71b209fe94",
        "username": "lisi3",
        "type": "MEMBER",
        "password": "$2b$12$kSMJ6yseeVUjUGlW5JXpO.JNEjpoCyrw31wtErNccgOxk/5vHWDnq",
        "attrs": {
            "avatar": "https://apihub-net.oss-cn-beijing.aliyuncs.com/img/default-avatar.jpg",
            "nickname": "lisi3",
            "any": {
                "thing": 123
            }
        },
        "enable": true,
        "firstCreated": "2025-05-06T06:36:30.251000",
        "ak": "67fca7a97a883fac3a981a83",
        "isDel": 0,
        "lastModified": "2025-05-06T08:03:44.682000"
    }
}

修改用户系统属性

与 更新用户属性(attrs) 的操作几乎一样。区别是 系统属性(sys_attrs) 不会被用户自行修改。

调用示例

sh
PUT https://open.apihub.net/api/user-center-admin/save-user-sys-attrs
apihub-token: {{token}}

{
    "target_user_id": "68193d6e39126a71b209fe94",
    "sys_attrs": {
        "any.thing": 123
    }
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
target_user_idjsonBodystruser 的 _id 字段
sys_attrsjsonBodydict可以往 user 对象的 sys_attrs 字段中添加任意信息。
1. 对于参数中存在,数据库中不存在的字段,将新增字段。
2. 对于参数中不存在,数据库存在的字段,将不受影响。
3. 对于参数中存在,数据库也存在的字段,将进行覆盖更新操作。
4. 参数名中使用点号.分割,可局部更新深层对象。

返回值说明

json
{
    "success": true,
    "trace": "9389fd702a0d11f088d1c6807b612ccf",
    "result": {
        "_id": "68193d6e39126a71b209fe94",
        "username": "lisi3",
        "type": "MEMBER",
        "password": "$2b$12$kSMJ6yseeVUjUGlW5JXpO.JNEjpoCyrw31wtErNccgOxk/5vHWDnq",
        "attrs": {
            "avatar": "https://apihub-net.oss-cn-beijing.aliyuncs.com/img/default-avatar.jpg",
            "nickname": "lisi3",
            "any": {
                "thing": 123
            }
        },
        "sys_attrs": {
            "any": {
                "thing": 123
            }
        },
        "enable": true,
        "firstCreated": "2025-05-06T06:36:30.251000",
        "ak": "67fca7a97a883fac3a981a83",
        "isDel": 0,
        "lastModified": "2025-05-06T08:03:44.682000"
    }
}

重置用户密码

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/reset-user-password
apihub-token: {{token}}

{
    "target_user_id": "68193d6e39126a71b209fe94",
    "new_password": "12345678"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
target_user_idjsonBodystruser 的 _id 字段
new_passwordjsonBodystr

返回值说明

json
{
    "success": true,
    "trace": "9389fd702a0d11f088d1c6807b612ccf",
    "result": {
        "_id": "68193d6e39126a71b209fe94",
        "username": "lisi3",
        "type": "MEMBER",
        "password": "$2b$12$kSMJ6yseeVUjUGlW5JXpO.JNEjpoCyrw31wtErNccgOxk/5vHWDnq",
        "attrs": {
            "avatar": "https://apihub-net.oss-cn-beijing.aliyuncs.com/img/default-avatar.jpg",
            "nickname": "lisi3"
        },
        "enable": true,
        "firstCreated": "2025-05-06T06:36:30.251000",
        "ak": "67fca7a97a883fac3a981a83",
        "isDel": 0,
        "lastModified": "2025-05-06T08:03:44.682000"
    }
}

禁用用户账号

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/enable-user-account
apihub-token: {{token}}

{
    "target_user_id": "68193d6e39126a71b209fe94",
    "enable": 0
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
target_user_idjsonBodystruser 的 _id 字段
enablejsonBodybool启用:1 或 true 。禁用:0 或 false

返回值说明

json
{
    "success": true,
    "trace": "9389fd702a0d11f088d1c6807b612ccf",
    "result": {
        "_id": "68193d6e39126a71b209fe94",
        "username": "lisi3",
        "type": "MEMBER",
        "password": "$2b$12$kSMJ6yseeVUjUGlW5JXpO.JNEjpoCyrw31wtErNccgOxk/5vHWDnq",
        "attrs": {
            "avatar": "https://apihub-net.oss-cn-beijing.aliyuncs.com/img/default-avatar.jpg",
            "nickname": "lisi3"
        },
        "enable": false,
        "firstCreated": "2025-05-06T06:36:30.251000",
        "ak": "67fca7a97a883fac3a981a83",
        "isDel": 0,
        "lastModified": "2025-05-06T08:03:44.682000"
    }
}

修改账号体验期

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/change-user-trial
apihub-token: {{token}}

{
    "target_user_id": "68193d6e39126a71b209fe94",
    "trial_end_at": 1748707200
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
target_user_idjsonBodystruser 的 _id 字段
trial_end_atjsonBodynumber账号体验期截止时刻,单位:秒 。
传 0 时,表示将个人信息的 trial_end_at 字段设置为 null,表示正式账号。

返回值说明

json
{
    "success": true,
    "trace": "07302a0a2a0f11f088d1c6807b612ccf",
    "result": {
        "_id": "68193d6e39126a71b209fe94",
        "username": "lisi3",
        "type": "MEMBER",
        "password": "$2b$12$fPpRvCqeSoN/tCbGN4RU2OB8s.MBlf9fM/.l2HE6VO/4U5RUWPeu2",
        "attrs": {
            "avatar": "https://apihub-net.oss-cn-beijing.aliyuncs.com/img/default-avatar.jpg",
            "nickname": "lisi3"
        },
        "enable": true,
        "firstCreated": "2025-05-06T06:36:30.251000",
        "ak": "67fca7a97a883fac3a981a83",
        "isDel": 0,
        "lastModified": "2025-05-06T08:14:08.204000",
        "trial_end_at": 1748707200
    }
}

扮演登录

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/impersonate
apihub-token: {{token}}

{
    "target_user_id": "68193d6e39126a71b209fe94",
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
target_user_idjsonBodystruser 的 _id 字段

返回值说明

json
{
    "success": true,
    "trace": "bd20d7ce2a0f11f0a8d9c6807b612ccf",
    "result": {
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2ODE5M2Q2ZTM5MTI2YTcxYjIwOWZlOTQiLCJpc3MiOiI2N2ZjYTdhOTdhODgzZmFjM2E5ODFhODMiLCJpYXQiOjE3NDY0OTA3NTMsImV4cCI6MTc0NjQ5NDM1MywidHlwIjoicGVyc29uX3Rva2VuIiwidXNlcm5hbWUiOiJsaXNpMyIsImdyb3VwcyI6W10sInJvbGVzIjpbIk1FTUJFUiJdfQ.iHHt5cQ03jAXHjjigw-TNzR6XiJr6y9PPmGb5caUUns",
        "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2ODE5M2Q2ZTM5MTI2YTcxYjIwOWZlOTQiLCJpc3MiOiI2N2ZjYTdhOTdhODgzZmFjM2E5ODFhODMiLCJpYXQiOjE3NDY0OTA3NTMsImV4cCI6MTc0NzA5NTU1MywidHlwIjoicGVyc29uX3Rva2VuIiwiYWN0aW9ucyI6WyJ1c2VyX2NlbnRlcjptZV9yZWZyZXNoX3Rva2VuIl19.VUnsuLvAsXkVlMy6sQdPu1CZFFsZkj05IQUTR0g5ALQ"
    }
}

角色

角色相关的接口几乎不会用到 _id 字段,而是使用 code

创建/更新 角色

需要 app_token,或到 Apihub 控制台 操作

调用示例

sh
PUT https://open.apihub.net/api/user-center-admin/save-role
apihub-token: {{token}}

{
    "code": "ADMIN"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
codejsonBodystr角色编码,唯一标识,不可修改
namejsonBodystr显示用的名称。默认:空字符串
descjsonBodystr显示用的长描述。默认:空字符串
orderjsonBodynumber排序字段。默认:当前时间戳,秒

返回值说明

json
{
    "success": true,
    "trace": "cc8023a42a1011f09ba8c6807b612ccf",
    "result": {
        "code": "ADMIN",
        "desc": "",
        "name": "",
        "order": 1747393915
    }
}

查询角色列表

调用示例

sh
GET https://open.apihub.net/api/user-center-admin/list-roles
apihub-token: {{token}}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr

返回值说明

json
{
    "success": true,
    "trace": "b942fb642a2d11f08263c6807b612ccf",
    "result": [
        {
            "code": "ADMIN",
            "desc": "123",
            "name": "",
            "order": 1747393915
        },
        {
            "code": "ADMIN1",
            "desc": "123",
            "name": "",
            "order": 1747393915
        }
    ]
}

删除角色

需要 app_token,或到 Apihub 控制台 操作

调用示例

sh
DELETE https://open.apihub.net/api/user-center-admin/delete-role
apihub-token: {{token}}

{
    "role_code": "ADMIN1"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
role_codejsonBodystrrole 的 code 字段

返回值说明

json
{
    "success": true,
    "trace": "4b0754122a1211f09ba8c6807b612ccf",
    "result": {
        "code": "ADMIN4",
        "name": "",
        "desc": "",
        "order": 1747393915
    }
}

分配角色给用户

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/assign-user-role
apihub-token: {{token}}

{
    "target_user_id": "68193d6e39126a71b209fe94",
    "role_code": "ADMIN"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
target_user_idjsonBodystruser 的 _id 字段
role_codejsonBodystrrole 的 code 字段

返回值说明

json
{
    "success": true,
    "trace": "7f43aca62a1e11f09ba8c6807b612ccf",
    "result": {
        "role_code": "ADMIN",
        "user_id": "68193d6e39126a71b209fe94"
    }
}

取消分配角色给用户

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/unassign-user-role
apihub-token: {{token}}

{
    "target_user_id": "68193d6e39126a71b209fe94",
    "role_code": "ADMIN"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
target_user_idjsonBodystruser 的 _id 字段
role_codejsonBodystrrole 的 code 字段

返回值说明

json
{
    "success": true,
    "trace": "7f43aca62a1e11f09ba8c6807b612ccf",
    "result": {
        "role_code": "ADMIN",
        "user_id": "68193d6e39126a71b209fe94",
        "isDel": 1
    }
}

查询用户拥有的角色

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/list-user-roles
apihub-token: {{token}}

{
    "target_user_id": "68193d6e39126a71b209fe94"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
target_user_idjsonBodystruser 的 _id 字段

返回值说明

result = [user["type"]] + user_roles,user_type 固定为第一个角色。

json
{
    "success": true,
    "trace": "edaf6aee2a1f11f08390c6807b612ccf",
    "result": [
        "ADMIN",
        "ADMIN1"
    ]
}

查询角色下的用户

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/list-role-users
apihub-token: {{token}}

{
    "role_code": "ADMIN1"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
role_codejsonBodystrrole 的 code 字段

返回值说明

返回 user 的 _id 字段列表。

虽然 查用户拥有的角色 列表第一项会固定添加 user_type。但是这里 查角色下的用户 不考虑 user_type 字段的影响。

json

{
    "success": true,
    "trace": "a6b0d8942a1f11f08390c6807b612ccf",
    "result": [
        "68193d6e39126a71b209fe94"
    ]
}

分组

分组名称不能包含一些特殊字符, 比如 /

分组类型不能包含一些特殊字符, 比如 /

空字符串 表示顶级分组的上级id。

创建分组

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/create-group
apihub-token: {{token}}

{
    "name": "部门A"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
namejsonBodystr名称
descjsonBodystr长描述, 默认:空字符串
parentjsonBodystr父级分组的 _id 字段。空字符串表示自身是顶层分组。默认:空字符串
orderjsonBodynumber排序字段,可以是小数、负数,将从小到大排序。默认:0.0
typejsonBodystr分组类型,可以随意指定类型,默认:dept
attrsjsonBodydict其他拓展属性

返回值说明

json
{
    "success": true,
    "trace": "6e89500a2b2711f0ae71c6807b612ccf",
    "result": {
        "_id": "681b2ac0d94cdcdf8ff990dc",
        "name": "部门A",
        "desc": "",
        "parent": "",
        "order": 0,
        "type": "dept",
        "attrs": {},
        "ak": "67fca7a97a883fac3a981a83",
        "firstCreated": "2025-05-07T17:41:20.674000",
        "isDel": 0,
        "children": null,
        "id_path": "/",
        "name_path": "/",
        "type_path": "/"
    }
}

更新分组信息

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/update-group
apihub-token: {{token}}

{
    "id":"681b2ac0d94cdcdf8ff990dc",
    "desc": "A"
}

参数说明

局部更新,未传参数时,将不会影响对应字段。attrs 内的字段名可以使用 . 分割以局部更新内层字段。

参数位置类型必传说明
apihub-tokenHeaderstr
idjsonBodystrgroup 的 _id 字段
namejsonBodystr名称
descjsonBodystr长描述
parentjsonBodystr父级分组的 _id 字段。空字符串表示设置成顶级分组
orderjsonBodynumber排序字段,可以是小数、负数,将从小到大排序。
typejsonBodystr分组类型,可以随意指定类型
attrsjsonBodydict其他拓展属性

返回值说明

json
{
    "success": true,
    "trace": "b76ba0ac2b2711f0ae71c6807b612ccf",
    "result": {
        "_id": "681b2ac0d94cdcdf8ff990dc",
        "name": "部门A",
        "desc": "A",
        "parent": "",
        "order": 0,
        "type": "dept",
        "attrs": {},
        "ak": "67fca7a97a883fac3a981a83",
        "firstCreated": "2025-05-07T17:41:20.674000",
        "isDel": 0,
        "lastModified": "2025-05-07T17:43:22.953000",
        "children": null,
        "id_path": "/",
        "name_path": "/",
        "type_path": "/"
    }
}

查询指定分组

调用示例

sh
GET https://open.apihub.net/api/user-center-admin/get-group?id=6819920b37e1bfd14cc10f7e&recursive=1
apihub-token: {{token}}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
idqueryParamsstrgroup 的 _id 字段
recursivequeryParamsbool是否递归包含子分组。默认:false

返回值说明

children 为 null 时,表示并未查找下级分组。为空数组时,表示没有下级分组。

删除分组

调用示例

sh
DELETE {{host}}/api/user-center-admin/delete-group?id=68199cb443d409491f536ce3
apihub-token: {{apihub_uc_token}}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
idqueryParamsstrgroup 的 _id 字段

查询子分组列表

调用示例

sh
GET https://open.apihub.net/api/user-center-admin/list-child-groups?
apihub-token: {{token}}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
parentqueryParamsstrgroup 的 _id 字段, 空表示顶层分组
recursivequeryParamsbool是否递归包含子分组。默认:false

返回值说明

children 为 null 时,表示并未查找下级分组。为空数组时,表示没有下级分组。

添加用户到分组

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/add-user-to-group
apihub-token: {{token}}

{
    "group_id": "681b2ac0d94cdcdf8ff990dc",
    "target_user_id": "680f1cfbbfc637de9478e64a"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
group_idjsonBodystrgroup 的 _id 字段
target_user_idjsonBodystruser 的 _id 字段

移除分组内的用户

调用示例

sh
POST https://open.apihub.net/api/user-center-admin/remove-user-from-group
apihub-token: {{token}}

{
    "group_id": "681b2ac0d94cdcdf8ff990dc",
    "target_user_id": "680f1cfbbfc637de9478e64a"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
group_idjsonBodystrgroup 的 _id 字段
target_user_idjsonBodystruser 的 _id 字段

列出分组内的用户

调用示例

sh
POST {{host}}/api/user-center-admin/list-group-users
apihub-token: {{apihub_uc_token}}

{
    "group_id": "681b2ac0d94cdcdf8ff990dc"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
group_idjsonBodystrgroup 的 _id 字段

返回值说明

返回 user_id 的列表

json
{
    "success": true,
    "trace": "b9a26f342b2911f09e7fc6807b612ccf",
    "result": [
        "680f1cfbbfc637de9478e64a"
    ]
}

查询用户归属的分组

调用示例

sh
POST {{host}}/api/user-center-admin/list-user-groups
apihub-token: {{apihub_uc_token}}

{
    "target_user_id": "680f1cfbbfc637de9478e64a"
}

参数说明

参数位置类型必传说明
apihub-tokenHeaderstr
target_user_idjsonBodystruser 的 _id 字段

返回值说明

json
{
    "success": true,
    "trace": "d6b6f8222b2b11f0930cc6807b612ccf",
    "result": [
        {
            "_id": "681b2ac0d94cdcdf8ff990dc",
            "name": "部门A",
            "desc": "A",
            "parent": "",
            "order": -1,
            "type": "dept",
            "attrs": {},
            "ak": "67fca7a97a883fac3a981a83",
            "firstCreated": "2025-05-07T17:41:20.674000",
            "isDel": 0,
            "lastModified": "2025-05-07T18:12:25.997000",
            "children": null,
            "id_path": "/",
            "name_path": "/",
            "type_path": "/"
        },
        {
            "_id": "6819920b37e1bfd14cc10f7e",
            "name": "部门1",
            "desc": "",
            "parent": "",
            "order": 0,
            "type": "dept",
            "attrs": {},
            "ak": "67fca7a97a883fac3a981a83",
            "firstCreated": "2025-05-06T12:37:31.491000",
            "isDel": 0,
            "children": null,
            "id_path": "/",
            "name_path": "/",
            "type_path": "/"
        }
    ]
}

拓展阅读

第三方登录

从 别人的系统 进 我们的系统 时,不需要密码。下面简单演示了如何二开接入微信小程序登录:

在小程序端:

js
// app.js
App({
  onLaunch() {
    wx.login({
      success: res => {
        wx.request({
          url: 'https://xxx.net/noauth/weixin-mp/code-2-token',
          data: {code: res.code, auto_create_user: true},
          success: (res) => { }
        })
      }
    })
  }
})

在您自己的服务端:

python
import time

import jwt
import requests
from fastapi import FastAPI

from common.config import config

app = FastAPI()


def gen_apihub_app_token():
    return jwt.encode(
        {
            "sub": config.get("apihub", "ak"),
            "iss": config.get("apihub", "ak"),
            "typ": "app_token",
            "iat": int(time.time()) - 300,
            "exp": int(time.time()) + 2 * 3600,
        },
        config.get("apihub", "sk"), algorithm="HS256",
    )


@app.get("/noauth/weixin-mp/code-2-token")
def weixin_mp_code_2_token(code: str, auto_create_user: bool = False):
    response = requests.get("https://api.weixin.qq.com/sns/jscode2session", {
        "appid": config.get("weixin", "mp.appid"),
        "secret": config.get("weixin", "mp.secret"),
        "js_code": code,
        "grant_type": "authorization_code",
    })
    openid = response.json().get("openid")

    exists_user = requests.post("https://open.apihub.net/api/user-center-admin/get-user-by-sys-attr",
                                headers={"apihub-token": gen_apihub_app_token()},
                                json={
                                    "key": "weixin_mp_openid",
                                    "value": openid
                                }).json()["result"]
    if not exists_user and auto_create_user:
        exists_user = requests.post("https://open.apihub.net/api/user-center-admin/create-user",
                                    headers={"apihub-token": gen_apihub_app_token()},
                                    json={
                                        "username": openid,
                                        "password": openid,
                                        "sys_attrs": {
                                            "weixin_mp_openid": openid,
                                            "username_password_temporary": True
                                        }
                                    }).json()["result"]
    if not exists_user:
        return {
            "success": False,
            "code": "ACCOUNT_NOT_FOUND",
            "msg": "账号不存在"
        }

    return requests.post("https://open.apihub.net/api/user-center-admin/impersonate",
                         headers={"apihub-token": gen_apihub_app_token()},
                         json={"target_user_id": exists_user["_id"]}).json()

单点登录

从 我们的系统 进 别人的系统 时,不需要密码。此时,无需与 Apihub 交互。

大致的认证逻辑如下:

  1. 为已在您系统登录的用户生成一个临时的一次性 code,将这个 code 交予第三方系统。
  2. 给第三方提供一个接口,验证 code 并返回用户信息,用户信息至少包含用户的唯一标识。

最后更新于: