远程开锁优化

第三方平台
This commit is contained in:
sky_min 2025-12-10 16:27:48 +08:00
parent 07fb7a6542
commit 3224fd342a
3 changed files with 57 additions and 71 deletions

View File

@ -225,7 +225,6 @@ class LockDetailLogic extends BaseGetXController {
StartChartManage().lockPeerId.isNotEmpty) { StartChartManage().lockPeerId.isNotEmpty) {
sendStarChartOpenLockMessage(reply); sendStarChartOpenLockMessage(reply);
} }
break; break;
case 0x16: case 0x16:
// ... // ...
@ -277,6 +276,7 @@ class LockDetailLogic extends BaseGetXController {
// //
// AppLog.log('开锁失败'); // AppLog.log('开锁失败');
openDoorError(); openDoorError();
showToast('开锁失败'.tr);
break; break;
} }
} }
@ -514,22 +514,39 @@ class LockDetailLogic extends BaseGetXController {
); );
BlueManage().blueSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!, BlueManage().blueSendData(state.keyInfos.value.bluetooth!.bluetoothDeviceName!,
(BluetoothConnectionState deviceConnectionState) async { (BluetoothConnectionState deviceConnectionState) async {
if (deviceConnectionState == BluetoothConnectionState.connected) { if (deviceConnectionState == BluetoothConnectionState.connected) {
BuglyTool.uploadException(message: '蓝牙连接成功', detail: '蓝牙连接成功,发送开锁指令--OpenLockCommand:$command', upload: false); BuglyTool.uploadException(message: '蓝牙连接成功', detail: '蓝牙连接成功,发送开锁指令--OpenLockCommand:$command', upload: false);
// FlutterBuglyPlugin.reportException(exceptionName: '蓝牙连接成功', reason: '蓝牙连接成功,发送开锁指令'); // FlutterBuglyPlugin.reportException(exceptionName: '蓝牙连接成功', reason: '蓝牙连接成功,发送开锁指令');
IoSenderManage.senderOpenLock( IoSenderManage.senderOpenLock(
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(), userID: await Storage.getUid(),
openMode: state.openDoorModel, openMode: state.openDoorModel,
openTime: getUTCNetTime(), openTime: getUTCNetTime(),
onlineToken: state.lockNetToken, onlineToken: state.lockNetToken,
token: getTokenList, token: getTokenList,
needAuthor: 1, needAuthor: 1,
signKey: signKeyDataList, signKey: signKeyDataList,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
); );
}); } else if (deviceConnectionState == BluetoothConnectionState.disconnected) {
cancelBlueConnetctToastTimer();
BuglyTool.uploadException(
message: '蓝牙连接失败-开锁失败', detail: '蓝牙连接失败,断开连接, 开锁失败--OpenLockCommand:$command', upload: true);
final String getMobile = (await Storage.getMobile())!;
ApmHelper.instance.trackEvent('open_lock', {
'lock_name': state.keyInfos.value.lockName!,
'account': getMobile.isNotEmpty ? getMobile : (await Storage.getEmail())!,
'date': DateTool().getNowDateWithType(1),
'open_lock_result': '断开连接',
});
// if (state.ifCurrentScreen.value == true) {
// showBlueConnetctToast();
// }
resetOpenDoorState();
}
});
} }
// //
@ -683,14 +700,12 @@ class LockDetailLogic extends BaseGetXController {
var lockId = currentKeyInfo.lockId ?? 0; var lockId = currentKeyInfo.lockId ?? 0;
var remoteUnlock = currentKeyInfo.lockSetting?.remoteUnlock ?? 0; var remoteUnlock = currentKeyInfo.lockSetting?.remoteUnlock ?? 0;
var lockPeerId = StartChartManage().lockPeerId; // 使peerId使
final network = currentKeyInfo.network;
if (lockPeerId.isEmpty) { var lockPeerId = '';
final network = currentKeyInfo.network; if (network != null && network.peerId != null && network.peerId!.isNotEmpty) {
if (network != null && network.peerId != null && network.peerId!.isNotEmpty) { lockPeerId = network.peerId!;
lockPeerId = network.peerId!; StartChartManage().lockPeerId = lockPeerId;
StartChartManage().lockPeerId = lockPeerId;
}
} }
if (remoteUnlock == 1) { if (remoteUnlock == 1) {
@ -762,7 +777,6 @@ class LockDetailLogic extends BaseGetXController {
if (userID == null || userID.isEmpty) { if (userID == null || userID.isEmpty) {
throw Exception('未找到用户ID'); throw Exception('未找到用户ID');
} }
AppLog.log('用户ID: $userID');
// //
final OpenLockCommand openLockCommand = OpenLockCommand( final OpenLockCommand openLockCommand = OpenLockCommand(
@ -776,11 +790,9 @@ class LockDetailLogic extends BaseGetXController {
signKey: signKeyList, signKey: signKeyList,
privateKey: privateKeyList, privateKey: privateKeyList,
); );
AppLog.log('构建开锁命令成功');
// //
final List<int> messageDetail = openLockCommand.packageData(); final messageDetail = openLockCommand.packageData();
// //
StartChartManage().sendRemoteUnLockMessage( StartChartManage().sendRemoteUnLockMessage(
bluetoothDeviceName: bluetoothDeviceName, bluetoothDeviceName: bluetoothDeviceName,
@ -894,8 +906,6 @@ class LockDetailLogic extends BaseGetXController {
} }
} }
//
int _networkQualityScore = 5; // 1-55
/// ///
void sendMonitorMessage() async { void sendMonitorMessage() async {
final catEyeConfig = state.keyInfos.value.lockSetting?.catEyeConfig ?? []; final catEyeConfig = state.keyInfos.value.lockSetting?.catEyeConfig ?? [];
@ -909,30 +919,6 @@ class LockDetailLogic extends BaseGetXController {
return; return;
} }
} }
//
switch (_networkQualityScore) {
case 1:
state.networkQualityMessage.value = '很差';
break;
case 2:
state.networkQualityMessage.value = '较差';
break;
case 3:
state.networkQualityMessage.value = '一般';
break;
case 4:
state.networkQualityMessage.value = '良好';
break;
case 5:
state.networkQualityMessage.value = '优秀';
break;
default:
state.networkQualityMessage.value = '';
}
//
if (_networkQualityScore < 4) {
showToast('网络质量'.tr + ':${state.networkQualityMessage.value}');
}
if (catEyeConfig.isNotEmpty && catEyeConfig.length > 0 && catEyeConfig[0].catEyeMode != 0) { if (catEyeConfig.isNotEmpty && catEyeConfig.length > 0 && catEyeConfig[0].catEyeMode != 0) {
if (network == null || network?.peerId == null || network?.peerId == '') { if (network == null || network?.peerId == null || network?.peerId == '') {
showToast('设备未配网'.tr); showToast('设备未配网'.tr);

View File

@ -29,10 +29,10 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
super.onReady(); super.onReady();
await getActivateInfo(); await getActivateInfo();
// //
final savedIndex = await state.getSavedSelectedPlatformIndex(); // final savedIndex = await state.getSavedSelectedPlatformIndex();
if (savedIndex != null && savedIndex < state.platFormSet.length) { // if (savedIndex != null && savedIndex < state.platFormSet.length) {
state.selectPlatFormIndex.value = savedIndex; // state.selectPlatFormIndex.value = savedIndex;
} // }
_initReplySubscription(); _initReplySubscription();
await getServerDatetime(); await getServerDatetime();
showEasyLoading(); showEasyLoading();
@ -215,8 +215,8 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
if (state.selectPlatFormIndex.value == 1 || state.selectPlatFormIndex.value == 0) { if (state.selectPlatFormIndex.value == 1 || state.selectPlatFormIndex.value == 0) {
if (state.registerKey.isNotEmpty) { if (state.registerKey.isNotEmpty) {
// //
state.saveSelectedPlatformIndex(state.selectPlatFormIndex.value); // state.saveSelectedPlatformIndex(state.selectPlatFormIndex.value);
_requestAuthorizationCode(); // _requestAuthorizationCode();
} }
} else { } else {
showToast('目前只支持切换至涂鸦智能、锁通通协议'.tr); showToast('目前只支持切换至涂鸦智能、锁通通协议'.tr);

View File

@ -35,14 +35,14 @@ class ThirdPartyPlatformState {
int serverTime = 0; // UTC+0 int serverTime = 0; // UTC+0
// //
static const String _SELECTED_PLATFORM_INDEX_KEY = 'selected_platform_index'; // static const String _SELECTED_PLATFORM_INDEX_KEY = 'selected_platform_index';
Future<void> saveSelectedPlatformIndex(int index) async { // Future<void> saveSelectedPlatformIndex(int index) async {
final prefs = await SharedPreferences.getInstance(); // final prefs = await SharedPreferences.getInstance();
await prefs.setInt(_SELECTED_PLATFORM_INDEX_KEY, index); // await prefs.setInt(_SELECTED_PLATFORM_INDEX_KEY, index);
} // }
// // //
Future<int?> getSavedSelectedPlatformIndex() async { // Future<int?> getSavedSelectedPlatformIndex() async {
final prefs = await SharedPreferences.getInstance(); // final prefs = await SharedPreferences.getInstance();
return prefs.getInt(_SELECTED_PLATFORM_INDEX_KEY); // return prefs.getInt(_SELECTED_PLATFORM_INDEX_KEY);
} // }
} }