[comment]: # translation:outdated

[comment]: # ({c28978f7-c28978f7})
# 创建

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

[comment]: # ({731e164c-3cdde1b6})
### 描述

`object token.create(object/array tokens)`

此方法允许创建新的令牌。

::: noteclassic
只允许 *Super admin(超级管理员)* 用户可以管理其他用户的令牌。
::: 

::: noteclassic
使用此方法创建令牌后，需要先执行 [generated](generate) 生成令牌，然后才能使用。
:::

[comment]: # ({/731e164c-3cdde1b6})

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

`(object/array)` 要创建的令牌。

此方法接受令牌带有规范的令牌属性[standard token properties](object)。

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

[comment]: # ({da7805eb-da7805eb})
### 返回值

`(object)` 返回一个对象其中包含在 `tokenids` 属性下创建的令牌的 ID。返回的 ID 的顺序与传递的令牌的顺序相匹配。

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

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

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

[comment]: # ({714b0e63-119ef871})
#### 创建令牌

创建一个永不过期的已启用令牌，并对ID为2的用户进行身份验证。

请求：

```json
{
    "jsonrpc": "2.0",
    "method": "token.create",
    "params": {
        "name": "Your token",
        "userid": "2"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "tokenids": [
            "188"
        ]
    },
    "id": 1
}
```

创建2021年1月21日到期的禁用令牌。此令牌将对当前用户进行身份验证。

请求：

```json
{
    "jsonrpc": "2.0",
    "method": "token.create",
    "params": {
        "name": "Your token",
        "status": "1",
        "expires_at": "1611238072"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "tokenids": [
            "189"
        ]
    },
    "id": 1
}
```

[comment]: # ({/714b0e63-119ef871})

[comment]: # ({5c90c156-5c90c156})
### 来源

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

[comment]: # ({/5c90c156-5c90c156})
