视频对讲中的远程开锁优化

This commit is contained in:
sky.min 2026-02-02 09:24:19 +08:00
parent e47a22a53f
commit df03d58dde

View File

@ -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, // 6APP开锁
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);
}
}