临时密码 SDK

更新时间:2024-09-12 10:38:56下载pdf

@ray-js/wechat-ms-password SDK 提供设备生成临时密码的能力,包含动态密码、单次密码、限时密码、自定义密码以及清空密码。

密码类型

密码类型 门锁是否必须联网 密码激活方式 如何在密码到期前主动删除
自定义密码 创建成功,即完成激活 门锁连接 App 时,通过 App 删除
限时密码 在生效时间后的 24 小时内,至少使用 1 次后激活。在有效期内可多次使用 使用对应的清空码来清除
单次密码 创建后即生效。创建后的 6 小时内,仅能使用 1 次 使用 1 次后失效
动态密码 创建后即生效。创建后 5-10 分钟内均可直接使用 自动失效
清空密码 创建后 24 小时内使用 1 次 使用 1 次后即失效

安装

yarn add @ray-js/wechat-ms-password

// or

npm install @ray-js/wechat-ms-password

创建临时密码

createPassword

请求参数

参数名 类型 描述 是否必传
device_id string 设备 ID true
pwd_type_code string 密码类型
  • dynamic:动态密码
  • temp:自定义密码
  • once:单次密码
  • multiple:限时密码
  • clear_all:清空所有已经生成的限时密码
  • clear_one:清空一条已经生成的限时密码
true
name string 密码名称,默认为空 false
password_id string 密码 ID,默认为空,当 pwd_type_code 取值为 clear_one 时需要传入 false
effective_time number 生效时间,默认值为当前时间,单位 ms false
invalid_time number 失效时间,默认值为当前时间的下一个小时,单位 ms false

返回参数

参数名 类型 描述
dynamic_password string 动态密码
temp_password string 自定义密码
effective_time number 生效时间
invalid_time number 失效时间
offline_temp_password string 生成的密码
offline_temp_password_id string 密码 ID
offline_temp_password_name number 密码名称

请求示例

import MsPasswordApi from '@ray-js/wechat-ms-password';

MsPasswordApi.createPassword({
  device_id: 'vdevo172164201350692',
  effective_time: 1722397508,
  invalid_time: 1722401108,
  name: '',
  pwd_type_code: 'once',
})
  .then(response => {
    console.log(response);
  })
  .catch(error => console.log(error));

返回示例

{
  effective_time: 1722394800,
  invalid_time: 1722416400,
  offline_temp_password: '4266733256',
  offline_temp_password_id: '697404212',
  offline_temp_password_name: '一次性密码',
}

保存临时密码

savePassword

请求参数

参数名 类型 描述 是否必传
device_id string 设备 ID true
pwd_type_code string 密码类型
  • temp:自定义密码
  • once:单次密码
  • multiple:限时密码
  • clear_all:清空所有已经生成的限时密码
  • clear_one:清空一条已经生成的限时密码
true
password_id number 密码 ID,当 pwd_type_code 取值不为 temp 时使用 true
password_name string 密码名称,当 pwd_type_code 取值不为 temp 时使用 true
password string 密码,当 pwd_type_code 取值为 temp 时使用 true
effective_time number 开始时间,单位 s,例如 new Date()÷1000。当 pwd_type_code 取值为 temp 时使用 true
invalid_time number 结束时间,当 pwd_type_code 取值为 temp 时使用 true
name string 密码名称,当 pwd_type_code 取值为 temp 时使用 false

返回参数

bool | string是否保存成功 | 密码 ID

请求示例

import MsPasswordApi from '@ray-js/wechat-ms-password';

MsPasswordApi.savePassword({
  device_id: 'vdevo172164201350692',
  password_id: 699103212,
  password_name: 'password',
  pwd_type_code: 'temp',
})
  .then(response => {
    console.log(response);
  })
  .catch(error => console.log(error));

返回示例

true;

获取临时密码列表

getTempPwdList

请求参数

参数名 类型 描述 是否必传
device_id string 设备 ID true
page_size number 密码列表长度,默认值为 200 false
pwd_type_codes string 密码类型
  • temp:自定义密码
  • once:单次密码
  • multiple:限时密码
  • clear_all:清空所有已经生成的限时密码
  • clear_one:清空一条已经生成的限时密码
false
query_id string 密码的查询 ID,默认值为""。当密码长度过长时,即 has_moretrue,需要上拉刷新时,query_id 为第 100 个密码的 query_id false

返回参数

参数名 类型 描述
has_more bool 是否有下一页
records recordItem[] 密码记录

recordItem 说明

参数名 类型 描述
auth_result number 授权结果
delivery_status string 进度状态
  • ONGOING:同步中
  • SUCCESS: 生效中
  • FAILED:失败
effective_flag number 是否有效
  • 0:无效
  • 1:生效中
  • 2:由于时间未到,待生效
effective_time number 生效时间
expired_time number 过期时间
gmt_create number 创建时间
name string 名称
operate string 操作类型
password_id string 密码 ID
phone string 电话号码
pwd_type_code string 密码类型
  • temp:自定义密码
  • once:单次密码
  • multiple:限时密码
  • clear_all:清空所有已经生成的限时密码
  • clear_one:清空一条已经生成的限时密码
query_id number 查询 ID
sn number 序列号(SN)
has_clear_pwd bool 是否有清空码。只有当 pwdTypeCode 取值为 multiple 时,该字段才有可能为 true
revoked_pwd_name string 被清空的密码名称。只有当 pwdTypeCode 取值为 clear_one 时,该字段才会有值
revoked_pwd_effective_time string 被清空的密码生效时间。只有当 pwdTypeCode 取值为 clear_one 时,该字段才会有值
revoked_pwd_invalid_time string 被清空的密码失效时间。只有当 pwdTypeCode 取值为 clear_one 时,该字段才会有值

请求示例

import MsPasswordApi from '@ray-js/wechat-ms-password';

MsPasswordApi.getTempPwdList({
  device_id: 'vdevo172164201350692',
  page_size: 200,
  pwd_type_codes: 'multiple,once,clear_all,clear_one,temp',
  query_id: '',
  session_id: '1722411999842',
  target_status: '',
})
  .then(response => {
    console.log(response);
  })
  .catch(error => console.log(error));

返回示例

{
  records: [
    {
      effective_flag: 1,
      effective_time: 1722409200000,
      expired_time: 1722430800000,
      gmt_create: 1722411994000,
      has_clear_pwd: false,
      name: "一次性密码",
      password_id: 697404512,
      phone: "",
      pwd_type_code: "once",
      query_id: 3652502812,
      revoked_pwd_name: "",
    },
     {
      effective_flag: 1,
      effective_time: 1722409200000,
      expired_time: 1722495600000,
      gmt_create: 1722411895000,
      has_clear_pwd: false,
      name: "清空码",
      password_id: 697404412,
      phone: "",
      pwd_type_code: "clear_all",
      query_id: 3652502812,
      revoked_pwd_name: "",
    }
  ],
  has_more: false,
}

更新有效的临时密码名称

updatePasswordName

请求参数

参数名 类型 描述 是否必传
device_id string 设备 ID true
password_id number 密码 ID true
password_name string 密码名称 true
pwd_type_code string 密码类型
  • temp:自定义密码
  • once:单次密码
  • multiple:限时密码
  • clear_all:清空所有已经生成的限时密码
  • clear_one:清空一条已经生成的限时密码
true

返回参数

返回参数为 Boolean 类型,表示有效的临时密码名称是否更新成功。

请求示例

import MsPasswordApi from '@ray-js/wechat-ms-password';

MsPasswordApi.updatePasswordName({
  device_id: 'vdevo172164201350692',
  password_id: 699103212,
  password_name: 'password',
  pwd_type_code: 'temp',
})
  .then(response => {
    console.log(response);
  })
  .catch(error => console.log(error));

返回示例

true;

删除临时密码

deletePassword

只能删除自定义密码(即 pwd_type_code 取值为 temp),以及处于无效状态的非自定义密码(即 pwd_type_code 取值不为 temp)。

请求参数

参数名 类型 描述 是否必传
device_id string 设备 ID true
password_id number 密码 ID true
effective_flag number 是否有效
  • 0:无效
  • 1:生效中
  • 2:由于时间未到,待生效
true
pwd_type_code string 密码类型
  • temp:自定义密码
  • once:单次密码
  • multiple:限时密码
  • clear_all:清空所有已经生成的限时密码
  • clear_one:清空一条已经生成的限时密码
true

返回参数

返回参数为 Boolean 类型,表示密码是否删除成功。

请求示例

import MsPasswordApi from '@ray-js/wechat-ms-password';

MsPasswordApi.deletePassword({
  device_id: 'vdevo172164201350692',
  password_id: 699100912,
  effective_flag: 0,
  pwd_type_code: 'once',
})
  .then(response => {
    console.log(response);
  })
  .catch(error => console.log(error));

返回示例

true;

获取有效的限时密码列表

listOfflinePassword

只有清空码选择清空单个限时密码时,才能获取有效的限时密码列表。

请求参数

参数名 类型 描述 是否必传
device_id string 设备 ID true
page_no number 每一页的索引值,默认为 1 false
page_size number 每一页面的个数,默认为 200 false

返回参数

参数名 类型 描述
records recordItem[] 限时密码记录
has_more bool 是否有下一页
total number 总记录条数
total_pages bool 总页数

recordItem 说明

参数名 类型 描述
auth_result number 授权结果
delivery_status string 进度状态
  • ONGOING:同步中
  • SUCCESS:生效中
  • FAILED:失败
effective_flag number 是否有效
  • 0:无效
  • 1:生效中
  • 2:由于时间未到,待生效
effective_time number 生效时间
expired_time number 过期时间
gmt_create number 创建时间
name string 名称
operate string 操作类型
password_id string 密码 ID
phone string 电话号码
pwd_type_code string 密码类型
  • temp:自定义密码
  • once:单次密码
  • multiple:限时密码
  • clear_all:清空所有已经生成的限时密码
  • clear_one:清空一条已经生成的限时密码
query_id number 查询 ID
sn number 序列号(SN)
has_clear_pwd bool 是否有清空码。只有当 pwdTypeCode 取值为 multiple 时,该字段才有可能为 true
revoked_pwd_name string 被清空的密码名称。只有当 pwdTypeCode 取值为 clear_one 时,该字段才会有值
revoked_pwd_effective_time string 被清空的密码生效时间。只有当 pwdTypeCode 取值为 clear_one 时,该字段才会有值
revoked_pwd_invalid_time string 被清空的密码失效时间。只有当 pwdTypeCode 取值为 clear_one 时,该字段才会有值

请求示例

import MsPasswordApi from '@ray-js/wechat-ms-password';

MsPasswordApi.listOfflinePassword({
  device_id: 'vdevo172164201350692',
})
  .then(response => {
    console.log(response);
  })
  .catch(error => console.log(error));

返回示例

{
  records: [
    {
      gmt_create: 1722844885,
      gmt_expired: "1722848400",
      gmt_start: "1722844800",
      has_clear_pwd: false,
      opt_uid: "ay1557901851281KP4Ug",
      pwd: "0000960001",
      pwd_id: "699104112",
      pwd_name: "离线不限次数密码",
      pwd_type_code: "multiple",
      revoked_pwd_name: "",
      status: 1,
    }
  ],
  has_more: false,
  total: 1,
  total_pages: 1,
}