Skip to content

电子钥匙

电子钥匙是用于 APP/小程序蓝牙开锁的凭证,用户需拥有电子钥匙才能使用蓝牙开锁功能。

与其他凭证的区别

特性电子钥匙其他凭证
使用方式APP/小程序操作门锁端直接验证
网络要求需蓝牙连接无需网络
典型场景远程授权、临时访客日常使用

电子钥匙的特殊性

电子钥匙是唯一一种纯软件凭证,不需要在门锁端录入任何数据。添加电子钥匙时,门锁只需存储凭证元数据(有效期、权限等),验证时通过蓝牙协议的会话鉴权完成身份确认。

指令列表

指令码名称方向说明
0x0400ListKeysAPP → 设备获取电子钥匙列表
0x0401GetKeyAPP → 设备获取电子钥匙详情
0x0402AddKeyAPP → 设备添加电子钥匙
0x0403UpdateKeyAPP → 设备更新电子钥匙
0x0404DeleteKeyAPP → 设备删除电子钥匙
0x0405ClearKeysAPP → 设备清空所有电子钥匙

数据结构

protobuf
message Key {
  uint32 credential_id = 1;    // 凭证ID(锁内唯一)
  uint32 user_id = 2;          // 归属用户ID
  uint32 created_by = 3;       // 创建者用户ID
  uint64 created_at = 4;       // 创建时间(UNIX毫秒时间戳)
  ValidityPeriod validity = 5; // 有效期
  uint32 use_count_limit = 6;  // 使用次数限制(0=不限)
  uint32 use_count = 7;        // 已使用次数
  string label = 8;            // 标签(如"张三的钥匙")
  bool is_duress = 9;          // 是否胁迫凭证
}
字段类型说明
credential_iduint32凭证ID,锁内唯一标识
user_iduint32归属用户ID
created_byuint32创建者用户ID
created_atuint64创建时间(UNIX毫秒时间戳)
validityValidityPeriod有效期,详见 凭证期限
use_count_limituint32使用次数限制,0 表示不限制
use_countuint32已使用次数
labelstring用户自定义标签
is_duressbool是否胁迫凭证

ListKeys - 获取电子钥匙列表

指令码: 0x0400

ListKeysReq

protobuf
message ListKeysReq {
  optional uint32 user_id = 1;  // 按用户ID筛选(不指定则返回所有)
}

ListKeysResp

protobuf
message ListKeysResp {
  uint32 code = 1;
  string message = 2;
  repeated Key keys = 3;  // 电子钥匙列表
}

GetKey - 获取电子钥匙详情

指令码: 0x0401

GetKeyReq

protobuf
message GetKeyReq {
  uint32 credential_id = 1;  // 凭证ID
}

GetKeyResp

protobuf
message GetKeyResp {
  uint32 code = 1;
  string message = 2;
  Key key = 3;  // 电子钥匙详情
}

AddKey - 添加电子钥匙

指令码: 0x0402

AddKeyReq

protobuf
message AddKeyReq {
  optional uint32 user_id = 1;          // 归属用户ID(不指定则自动创建用户)
  optional ValidityPeriod validity = 2; // 有效期
  optional uint32 use_count_limit = 3;  // 使用次数限制
  optional string label = 4;            // 标签
  optional bool is_duress = 5;          // 是否胁迫凭证
}
字段必填说明
user_id不指定时自动创建新用户
validity不指定时永久有效
use_count_limit默认 0(不限制)
label默认空字符串
is_duress默认 false

AddKeyResp

protobuf
message AddKeyResp {
  uint32 code = 1;
  string message = 2;
  uint32 credential_id = 3;  // 新建的凭证ID
  uint32 user_id = 4;        // 归属用户ID(自动创建时返回新用户ID)
}

UpdateKey - 更新电子钥匙

指令码: 0x0403

部分更新

仅更新请求中包含的字段,未包含的字段保持不变。

UpdateKeyReq

protobuf
message UpdateKeyReq {
  uint32 credential_id = 1;             // 凭证ID(必填)
  optional ValidityPeriod validity = 2; // 有效期
  optional uint32 use_count_limit = 3;  // 使用次数限制
  optional string label = 4;            // 标签
  optional bool is_duress = 5;          // 是否胁迫凭证
}

UpdateKeyResp

protobuf
message UpdateKeyResp {
  uint32 code = 1;
  string message = 2;
}

DeleteKey - 删除电子钥匙

指令码: 0x0404

DeleteKeyReq

protobuf
message DeleteKeyReq {
  uint32 credential_id = 1;  // 凭证ID
}

DeleteKeyResp

protobuf
message DeleteKeyResp {
  uint32 code = 1;
  string message = 2;
}

ClearKeys - 清空所有电子钥匙

指令码: 0x0405

危险操作

此操作将删除门锁上所有电子钥匙,不可恢复。

ClearKeysReq

protobuf
message ClearKeysReq {
  // 无参数
}

ClearKeysResp

protobuf
message ClearKeysResp {
  uint32 code = 1;
  string message = 2;
  uint32 count = 3;  // 删除的数量
}

相关文档

物联网设备通信协议文档