fix: 调整第三方平台设置

This commit is contained in:
liyi 2025-10-22 09:37:26 +08:00
parent 4f1b1dd02f
commit e1011688de
7 changed files with 192 additions and 82 deletions

View File

@ -46,7 +46,7 @@ class BlueManage {
StreamSubscription<BluetoothConnectionState>? _connectionStateSubscription; StreamSubscription<BluetoothConnectionState>? _connectionStateSubscription;
StreamSubscription<int>? _mtuSubscription; StreamSubscription<int>? _mtuSubscription;
int? _mtuSize = 20; int? _mtuSize = 30;
// //
String connectDeviceName = ''; String connectDeviceName = '';
@ -813,30 +813,33 @@ class BlueManage {
/// ///
Future<void> writeCharacteristicWithResponse(List<int> value) async { Future<void> writeCharacteristicWithResponse(List<int> value) async {
// MTU还是默认值
if (_mtuSize == 23 && bluetoothConnectDevice != null) {
try {
if (Platform.isAndroid) {
await bluetoothConnectDevice!.requestMtu(512);
}
} catch (e) {
AppLog.log('重新请求MTU失败: $e');
}
}
final List<BluetoothService> services = await bluetoothConnectDevice!.discoverServices(); final List<BluetoothService> services = await bluetoothConnectDevice!.discoverServices();
for (final BluetoothService service in services) { for (final BluetoothService service in services) {
if (service.uuid == _serviceIdConnect) { if (service.uuid == _serviceIdConnect) {
for (final BluetoothCharacteristic characteristic in service.characteristics) { for (final BluetoothCharacteristic characteristic in service.characteristics) {
if (characteristic.characteristicUuid == _characteristicIdWrite) { if (characteristic.characteristicUuid == _characteristicIdWrite) {
try { try {
_initGetMtuSubscription();
// MTU还是默认值
if ((_mtuSize == 23 || _mtuSize == 20) && bluetoothConnectDevice != null) {
try {
if (Platform.isAndroid) {
await bluetoothConnectDevice!.requestMtu(512);
}
} catch (e) {
AppLog.log('重新请求MTU失败: $e');
}
}
// //
int retryCount = 0; int retryCount = 0;
const int maxRetries = 3; const int maxRetries = 3;
const int retryDelayMs = 500; const int retryDelayMs = 500;
final List<int> valueList = value; final List<int> valueList = value;
AppLog.log('发送数据时当前的mtuSize是:${_mtuSize}');
final List subData = splitList(valueList, _mtuSize!); final List subData = splitList(valueList, _mtuSize!);
for (int i = 0; i < subData.length; i++) { for (int i = 0; i < subData.length; i++) {
// //
bool packetSent = false; bool packetSent = false;

View File

@ -1,24 +1,109 @@
import 'dart:convert';
class ActivateInfoResponse { class ActivateInfoResponse {
ActivateInfoResponse({ ActivateInfoResponse({
this.description, this.description,
this.errorCode, this.errorCode,
this.data, // List<ActivateInfo> this.data, // List<ActivateInfo>
this.errorMsg, this.errorMsg,
}); });
ActivateInfoResponse.fromJson(dynamic json) { ActivateInfoResponse.fromJson(dynamic json) {
description = json['description']; description = json['description'];
errorCode = json['errorCode']; errorCode = json['errorCode'];
// json['data'] List<ActivateInfo> // ActivateInfo
data = json['data'] != null data = json['data'] != null ? ActivateInfo.fromJson(json['data']) : null;
? (json['data'] as List).map((item) => ActivateInfo.fromJson(item)).toList()
: [];
errorMsg = json['errorMsg']; errorMsg = json['errorMsg'];
} }
String? description; String? description;
int? errorCode; int? errorCode;
List<ActivateInfo>? data; // List<ActivateInfo> ActivateInfo? data; // List<ActivateInfo>
String? errorMsg;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['description'] = description;
map['errorCode'] = errorCode;
if (data != null) {
// ActivateInfo JSON
map['data'] = data!.toJson();
}
map['errorMsg'] = errorMsg;
return map;
}
@override
String toString() {
return 'ActivateInfoResponse{description: $description, errorCode: $errorCode, data: $data, errorMsg: $errorMsg}';
}
}
class ActivateInfo {
String? authCode;
String? activatedAt;
Map<String, dynamic>? extraParams; // Map
ActivateInfo({
this.authCode,
this.activatedAt,
this.extraParams,
});
ActivateInfo.fromJson(dynamic json) {
authCode = json['auth_code'] ?? '';
activatedAt = json['activated_at'] ?? '';
// extraParams Map
if (json['extra_params'] != null) {
if (json['extra_params'] is Map) {
extraParams = json['extra_params'];
} else if (json['extra_params'] is String) {
// JSON
try {
extraParams = jsonDecode(json['extra_params']);
} catch (e) {
// null map
extraParams = {};
}
}
} else {
extraParams = {};
}
}
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['authCode'] = authCode;
map['activatedAt'] = activatedAt;
map['extraParams'] = extraParams;
return map;
}
@override
String toString() {
return 'ActivateInfo{authCode: $authCode, activatedAt: $activatedAt, extraParams: $extraParams}';
}
}
class TppSupportResponse {
TppSupportResponse({
this.description,
this.errorCode,
this.data, // List<ActivateInfo>
this.errorMsg,
});
TppSupportResponse.fromJson(dynamic json) {
description = json['description'];
errorCode = json['errorCode'];
// json['data'] List<ActivateInfo>
data = json['data'] != null ? (json['data'] as List).map((item) => TppSupportInfo.fromJson(item)).toList() : [];
errorMsg = json['errorMsg'];
}
String? description;
int? errorCode;
List<TppSupportInfo>? data; // List<ActivateInfo>
String? errorMsg; String? errorMsg;
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -35,33 +120,28 @@ class ActivateInfoResponse {
@override @override
String toString() { String toString() {
return 'ActivateInfoResponse{description: $description, errorCode: $errorCode, data: $data, errorMsg: $errorMsg}'; return 'TppSupportResponse{description: $description, errorCode: $errorCode, data: $data, errorMsg: $errorMsg}';
} }
} }
class ActivateInfo { class TppSupportInfo {
String? platformName;
int? platform; int? platform;
String? platformName;
ActivateInfo({ TppSupportInfo({
this.platformName,
this.platform, this.platform,
this.platformName,
}); });
ActivateInfo.fromJson(dynamic json) { TppSupportInfo.fromJson(dynamic json) {
platformName = json['platformName'] ?? ''; platform = json['platform'] as int? ?? -1;
platform = json['platform'] ?? ''; platformName = json['platform_name'] as String? ?? '';
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final map = <String, dynamic>{}; final map = <String, dynamic>{};
map['platformName'] = platformName;
map['platform'] = platform; map['platform'] = platform;
map['platform_name'] = platformName;
return map; return map;
} }
@override
String toString() {
return 'ActivateInfo{platformName: $platformName, platform: $platform}';
}
} }

View File

@ -658,6 +658,7 @@ class LockDetailLogic extends BaseGetXController {
if (list.isEmpty) { if (list.isEmpty) {
return; return;
} }
AppLog.log('list:${list}');
final KeyOperationRecordEntity entity = final KeyOperationRecordEntity entity =
await ApiRepository.to.lockRecordUploadData(lockId: state.keyInfos.value.lockId.toString(), records: list); await ApiRepository.to.lockRecordUploadData(lockId: state.keyInfos.value.lockId.toString(), records: list);
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {

View File

@ -29,7 +29,24 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
super.onReady(); super.onReady();
await getActivateInfo(); await getActivateInfo();
_initReplySubscription(); _initReplySubscription();
getServerDatetime(); await getServerDatetime();
showEasyLoading();
showBlueConnetctToastTimer(action: () {
dismissEasyLoading();
});
BlueManage().blueSendData(
BlueManage().connectDeviceName,
(BluetoothConnectionState connectionState) async {
if (connectionState == BluetoothConnectionState.connected) {
IoSenderManage.readRegisterKey(
lockID: BlueManage().connectDeviceName,
);
} else if (connectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
}
},
);
} }
@override @override
@ -57,6 +74,7 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
Future<void> getServerDatetime() async { Future<void> getServerDatetime() async {
final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData(isUnShowLoading: true); final GetServerDatetimeEntity entity = await ApiRepository.to.getServerDatetimeData(isUnShowLoading: true);
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
state.serverTime = entity.data!.date! ~/ 1000;
state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000; state.differentialTime = entity.data!.date! ~/ 1000 - DateTime.now().millisecondsSinceEpoch ~/ 1000;
} }
} }
@ -72,7 +90,6 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
return; return;
} }
_replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async { _replySubscription = EventBusManager().eventBus!.on<Reply>().listen((Reply reply) async {
AppLog.log('输出了listen${_replySubscription.hashCode}');
if (reply is SenderReadRegisterKeyCommandReply) { if (reply is SenderReadRegisterKeyCommandReply) {
_handleReadRegisterKeyReply(reply); _handleReadRegisterKeyReply(reply);
} }
@ -158,7 +175,7 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
uuid: response.data?.extraParams?['uuid'], uuid: response.data?.extraParams?['uuid'],
key: response.data?.authCode, key: response.data?.authCode,
mac: response.data?.extraParams?['mac'], mac: response.data?.extraParams?['mac'],
platform: 1, platform: state.selectPlatFormIndex.value,
utcTimeStamp: getUTCNetTime(), utcTimeStamp: getUTCNetTime(),
); );
} else if (connectionState == BluetoothConnectionState.disconnected) { } else if (connectionState == BluetoothConnectionState.disconnected) {
@ -191,25 +208,11 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
void savePlatFormSetting() { void savePlatFormSetting() {
if (state.selectPlatFormIndex.value == 1 || state.selectPlatFormIndex.value == 0) { if (state.selectPlatFormIndex.value == 1 || state.selectPlatFormIndex.value == 0) {
showEasyLoading(); if (state.registerKey.isNotEmpty) {
showBlueConnetctToastTimer(action: () { _requestAuthorizationCode();
dismissEasyLoading(); }
});
BlueManage().blueSendData(
BlueManage().connectDeviceName,
(BluetoothConnectionState connectionState) async {
if (connectionState == BluetoothConnectionState.connected) {
IoSenderManage.readRegisterKey(
lockID: BlueManage().connectDeviceName,
);
} else if (connectionState == BluetoothConnectionState.disconnected) {
dismissEasyLoading();
cancelBlueConnetctToastTimer();
}
},
);
} else { } else {
showToast('目前只支持切换至涂鸦智能协议'.tr); showToast('目前只支持切换至涂鸦智能、锁通通协议'.tr);
} }
} }
@ -232,15 +235,14 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
switch (status) { switch (status) {
case 0x00: case 0x00:
final platform = reply.data[7];
// RegisterKey (740) // RegisterKey (740)
final List<int> registerKeyBytes = reply.data.sublist(7, 47); final List<int> registerKeyBytes = reply.data.sublist(8, 48);
final String registerKey = String.fromCharCodes(registerKeyBytes); final String registerKey = String.fromCharCodes(registerKeyBytes);
state.selectPlatFormIndex.value = platform;
print('platform: $platform');
print('Register Key: $registerKey'); print('Register Key: $registerKey');
state.registerKey.value = registerKey; state.registerKey.value = registerKey;
if (registerKey.isNotEmpty) {
_requestAuthorizationCode();
}
// //
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
dismissEasyLoading(); dismissEasyLoading();
@ -265,8 +267,8 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
IoSenderManage.senderGetStarLockStatuInfo( IoSenderManage.senderGetStarLockStatuInfo(
lockID: BlueManage().connectDeviceName, lockID: BlueManage().connectDeviceName,
userID: await Storage.getUid(), userID: await Storage.getUid(),
utcTimeStamp: 0, utcTimeStamp: state.serverTime,
unixTimeStamp: 0, unixTimeStamp: getLocalTime2(),
isBeforeAddUser: false, isBeforeAddUser: false,
privateKey: getPrivateKeyList, privateKey: getPrivateKeyList,
); );
@ -278,6 +280,18 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
}); });
} }
int getLocalTime() {
final DateTime now = DateTime.now();
final Duration timeZoneOffset = now.timeZoneOffset;
return state.differentialTime + timeZoneOffset.inSeconds;
}
int getLocalTime2() {
final DateTime now = DateTime.now();
final Duration timeZoneOffset = now.timeZoneOffset;
return state.serverTime + timeZoneOffset.inSeconds;
}
void _handleAuthorizationCodeReply(SenderAuthorizationCodeCommandReply reply) { void _handleAuthorizationCodeReply(SenderAuthorizationCodeCommandReply reply) {
final int status = reply.data[6]; final int status = reply.data[6];
switch (status) { switch (status) {
@ -285,7 +299,12 @@ class ThirdPartyPlatformLogic extends BaseGetXController {
// //
cancelBlueConnetctToastTimer(); cancelBlueConnetctToastTimer();
dismissEasyLoading(); dismissEasyLoading();
showToast('操作成功请在24小时内用涂鸦APP添加门锁否则将过期'.tr); if (state.selectPlatFormIndex.value == 1) {
showSuccess('操作成功,请尽快用"涂鸦”APP配置如不使用请关闭该设置支持'.tr);
} else if (state.selectPlatFormIndex.value == 0) {
showSuccess('操作成功'.tr);
}
break; break;
default: default:
// //

View File

@ -128,25 +128,27 @@ class _ThirdPartyPlatformPageState extends State<ThirdPartyPlatformPage> {
// 线 // 线
isHaveDirection: false, isHaveDirection: false,
isHaveRightWidget: true, isHaveRightWidget: true,
rightWidget: Radio<String>( rightWidget: Obx(
// Radio 使 id () => Radio<String>(
value: platform, // Radio 使 id
// selectPlatFormIndex id value: platform,
groupValue: state.platFormSet.value[state.selectPlatFormIndex.value], // selectPlatFormIndex id
// groupValue: state.platFormSet.value[state.selectPlatFormIndex.value],
activeColor: AppColors.mainColor, //
// Radio activeColor: AppColors.mainColor,
onChanged: (value) { // Radio
if (value != null) { onChanged: (value) {
setState(() { if (value != null) {
// id setState(() {
final newIndex = state.platFormSet.value.indexWhere((p) => p == value); // id
if (newIndex != -1) { final newIndex = state.platFormSet.value.indexWhere((p) => p == value);
state.selectPlatFormIndex.value = newIndex; if (newIndex != -1) {
} state.selectPlatFormIndex.value = newIndex;
}); }
} });
}, }
},
),
), ),
action: () { action: () {
setState(() { setState(() {

View File

@ -13,7 +13,7 @@ class ThirdPartyPlatformState {
} }
Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs; Rx<LockSetInfoData> lockSetInfoData = LockSetInfoData().obs;
int differentialTime = 0;// UTC+0 int differentialTime = 0; // UTC+0
// UI // UI
final RxList<String> platFormSet = List.of({ final RxList<String> platFormSet = List.of({
@ -25,8 +25,11 @@ class ThirdPartyPlatformState {
// UI // UI
final RxList<TppSupportInfo> tppSupportList = RxList<TppSupportInfo>([]); final RxList<TppSupportInfo> tppSupportList = RxList<TppSupportInfo>([]);
RxInt selectPlatFormIndex = 1.obs; RxInt selectPlatFormIndex = (-1).obs;
RxBool openNumber = false.obs;
RxString registerKey = ''.obs; RxString registerKey = ''.obs;
Map lockInfo = {}; Map lockInfo = {};
int serverTime = 0; // UTC+0
} }

View File

@ -305,6 +305,8 @@ abstract class Api {
'/lockSetting/updateLockSetting'; // '/lockSetting/updateLockSetting'; //
final String reportBuyRequestURL = final String reportBuyRequestURL =
'/service/reportBuyRequest'; // '/service/reportBuyRequest'; //
final String getActivateInfoURL = final String getTppSupportURL =
'/api/authCode/getTppSupport'; // ttp '/api/authCode/getTppSupport'; // ttp
final String getActivateInfoURL =
'/api/authCode/getActivateInfo'; // ttp
} }