---
name: "createTempOnce"
mode: "api"
versionRequirements:
  - { name: "@ray-js/lock-sdk", version: "1.0.0" }
title: "createTempOnce - 创建一次性密码。"
summary: "创建一次性密码。"
---

## createTempOnce

> [VERSION] @ray-js/lock-sdk >= 1.0.0

### 描述

创建单次临时密码

### 参数

| 参数 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| `name` | `string` | 否 | 密码名称，长度不能超过 20 |

### 返回值

类型: `Promise<TempPasswordResult>`

单次临时密码创建结果

##### TempPasswordResult

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `type` | `"once" \| "limit" \| "custom" \| "clear" \| "clearOne" \| "dynamic"` | 密码类型或 dynamic（动态码） |
| `name` | `string` | 展示名称 |
| `password` | `string` | 密码明文或展示串 |
| `unlockBindingId` | `string` | 云端绑定关系 id |
| `effectiveConfig` | `EffectiveConfig` | 生效时间配置 |

### 错误码

| 错误码 | 错误信息 |
| --- | --- |
| `1031` | 密码名称过长（超过 20 字符） |
| `1038` | 云端：密码名称重复（OFFLINE_PWD_NAME_REPEAT） |
| `1067` | 云端：该周期离线密码已耗尽（OFFLINE_PWD_EXAUST_IN_PERIOD） |

### 引用对象

##### `type` Week

周重复位图：下标 0–6 对应周日–周六，0 不生效 1 生效

```typescript
export type Week = [
  BitStatus,
  BitStatus,
  BitStatus,
  BitStatus,
  BitStatus,
  BitStatus,
  BitStatus,
];
```

##### `type` BitStatus

位开关：0 关、1 开 / Single-bit flag

```typescript
export type BitStatus = 0 | 1;
```


### 示例代码

#### 示例

```ts
import { createTempOnce } from '@ray-js/lock-sdk';
const result = await createTempOnce({});
```
