---
name: "createTempCustom"
mode: "api"
versionRequirements:
  - { name: "@ray-js/lock-sdk", version: "1.0.0" }
title: "createTempCustom - 创建自定义临时密码，支持设置密码内容、名称和时效配置。"
summary: "创建自定义临时密码，支持设置密码内容、名称和时效配置。"
---

## createTempCustom

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

### 描述

创建自定义临时密码。

### 参数

| 参数 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| `password` | `string` | 是 | 密码内容，必须是数字 |
| `name` | `string` | 否 | 密码名称，长度不能超过 20 |
| `effective` | `EffectiveConfig` | 是 | 密码时效配置 |

### 返回值

类型: `Promise<TempPasswordResult>`

创建结果

##### TempPasswordResult

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

### 错误码

| 错误码 | 错误信息 |
| --- | --- |
| `1052` | 同一设备上一次操作尚未完成 |
| `1030` | 密码格式不合法 |
| `1031` | 密码名称过长（超过 20 字符） |
| `1032` | 缺少生效时间配置 |
| `1033` | 缺少生效日期 |
| `1034` | 缺少过期日期 |
| `1010` | 生效时间大于过期时间 |
| `1035` | 周重复模式下未传入 weeks |
| `1043` | 云端未返回序号（近场通道） |
| `1001` | 设备不在线（近场通道） |
| `1002` | 操作超时（近场通道） |
| `1041` | 设备上报创建失败：密码重复（近场通道） |
| `1042` | 设备上报创建失败（近场通道） |
| `1037` | 云端：密码已存在（USER_PWD_ALREADY_EXIST） |
| `1038` | 云端：密码名称重复（LOCK_PWD_NAME_REPEAT） |
| `1039` | 云端：时间参数不正确（START_END_DATE_NOT_RIGHT） |

### 引用对象

##### `type` BitStatus

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

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

##### `type` Week

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

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


### 示例代码

#### 示例

```ts
import { createTempCustom } from '@ray-js/lock-sdk';
await createTempCustom({ password: '123456', effectiveTime: 1700000000, invalidTime: 1700086400 });
```
