视频对讲中的远程开锁优化
This commit is contained in:
parent
e47a22a53f
commit
df03d58dde
@ -14,6 +14,7 @@ import 'package:image_gallery_saver/image_gallery_saver.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:star_lock/app_settings/app_settings.dart';
|
||||
import 'package:star_lock/blue/io_protocol/io_openLock.dart';
|
||||
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockDetail/lockDetail_logic.dart';
|
||||
import 'package:star_lock/main/lockDetail/lockDetail/lockDetail_state.dart';
|
||||
@ -1197,6 +1198,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
|
||||
|
||||
var lockId = currentKeyInfo.lockId ?? 0;
|
||||
var remoteUnlock = currentKeyInfo.lockSetting?.remoteUnlock ?? 0;
|
||||
var hasGateway = currentKeyInfo.hasGateway ?? 0; // 0 表示 WiFi 锁,1 表示网关锁
|
||||
|
||||
final lockPeerId = StartChartManage().lockPeerId;
|
||||
final LockListInfoGroupEntity? lockListInfoGroupEntity = await Storage.getLockMainListData();
|
||||
@ -1210,20 +1212,61 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
|
||||
if (peerId == lockPeerId) {
|
||||
lockId = lockInfo.lockId ?? 0;
|
||||
remoteUnlock = lockInfo.lockSetting?.remoteUnlock ?? 0;
|
||||
hasGateway = lockInfo.hasGateway ?? 0; // 更新锁类型信息
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (remoteUnlock == 1) {
|
||||
|
||||
if (remoteUnlock != 1) {
|
||||
showToast('该锁的远程开锁功能未启用'.tr);
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据锁的类型选择开锁方式
|
||||
if (hasGateway == 1) {
|
||||
// 网关锁,使用远程API开锁
|
||||
final LoginEntity entity = await ApiRepository.to.remoteOpenLock(lockId: lockId.toString(), timeOut: 60);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
showToast('已开锁'.tr);
|
||||
StartChartManage().lockListPeerId = [];
|
||||
}
|
||||
} else {
|
||||
showToast('该锁的远程开锁功能未启用'.tr);
|
||||
// WiFi锁,使用蓝牙透传开锁指令
|
||||
await _sendBluetoothOpenLockCommand(lockId);
|
||||
}
|
||||
}
|
||||
|
||||
/// 通过蓝牙发送开锁指令
|
||||
Future<void> _sendBluetoothOpenLockCommand(int lockId) async {
|
||||
try {
|
||||
// 使用当前用户信息和时间戳创建开锁命令
|
||||
final userId = (await Storage.getLoginData())?.userid?.toString() ?? '';
|
||||
final openTime = DateTime.now().millisecondsSinceEpoch ~/ 1000; // 转换为秒级时间戳
|
||||
|
||||
// 创建开锁命令对象
|
||||
final openLockCommand = OpenLockCommand(
|
||||
lockID: lockId.toString().padRight(40, '\0'), // 确保长度为40
|
||||
userID: userId.padRight(20, '\0'), // 确保长度为20
|
||||
openMode: 6, // 开锁模式,通常为6表示APP开锁
|
||||
openTime: openTime,
|
||||
token: [0, 0, 0, 0], // 初始token为0
|
||||
needAuthor: 0, // 不需要授权
|
||||
onlineToken: '', // 空的在线token
|
||||
signKey: CommonDataManage().currentKeyInfo.bluetooth?.signKey, // 从当前钥匙信息中获取签名密钥
|
||||
privateKey: CommonDataManage().currentKeyInfo.bluetooth?.privateKey, // 从当前钥匙信息中获取私钥
|
||||
);
|
||||
|
||||
// 通过蓝牙发送命令
|
||||
// 这里使用LockDetailLogic中的remoteOpenLock方法,该方法内部已经包含了蓝牙发送逻辑
|
||||
await Get.find<LockDetailLogic>().remoteOpenLock();
|
||||
|
||||
AppLog.log('已发送蓝牙开锁指令'.tr);
|
||||
} catch (e) {
|
||||
AppLog.log('蓝牙开锁失败: $e');
|
||||
showToast('蓝牙开锁失败'.tr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user