[comment]: # translation:outdated

[comment]: # ({4480ea6d-4480ea6d})
# 生成

[comment]: # ({/4480ea6d-4480ea6d})

[comment]: # ({7d5e371f-3f13b874})
### 描述

`object token.generate(array tokenids)`

此方法允许生成令牌。

::: noteclassic
用户角色必须具有 *Manage API tokens* [权限](/manual/web_interface/frontend_sections/users/user_roles#configuration)，才能管理其他用户的令牌。
:::

::: noteimportant
只有在令牌已被[创建](create)后，才能通过此方法生成。
:::

[comment]: # ({/7d5e371f-3f13b874})

[comment]: # ({db2ee95a-db2ee95a})
### 参数

`(array)` 要生成的令牌的ID。

[comment]: # ({/db2ee95a-db2ee95a})

[comment]: # ({27f911c0-101a0040})
### 返回值

`(array)` 返回一个对象数组，其中在 `tokenid` 属性下包含生成的
令牌 ID，在 `token` 属性下包含生成的授权字符串。

|属性|[Type](/manual/api/reference_commentary#data-types)|描述|
|--|--|------|
|tokenid|ID|令牌的 ID。|
|token|string|为此令牌生成的授权字符串。|

[comment]: # ({/27f911c0-101a0040})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({7c083659-c0623539})
#### 生成多个令牌

生成两个令牌。

[请求](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "token.generate",
    "params": [
        "1",
        "2"
    ],
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "tokenid": "1",
            "token": "bbcfce79a2d95037502f7e9a534906d3466c9a1484beb6ea0f4e7be28e8b8ce2"
        },
        {
            "tokenid": "2",
            "token": "fa1258a83d518eabd87698a96bd7f07e5a6ae8aeb8463cae33d50b91dd21bd6d"
        }
    ],
    "id": 1
}
```

[comment]: # ({/7c083659-c0623539})

[comment]: # ({39ba5785-39ba5785})
### 来源

*ui/include/classes/api/services/CToken.php* 中的 CToken::generate()。

[comment]: # ({/39ba5785-39ba5785})
