2023-08-08 09:42:35 +08:00
|
|
|
|
import 'dart:convert';
|
2023-08-09 15:42:26 +08:00
|
|
|
|
import 'dart:typed_data';
|
2023-08-08 09:42:35 +08:00
|
|
|
|
|
2023-08-09 15:42:26 +08:00
|
|
|
|
import '../../tools/storage.dart';
|
2023-08-08 09:42:35 +08:00
|
|
|
|
import '../io_tool/io_tool.dart';
|
2023-08-10 09:52:05 +08:00
|
|
|
|
import '../sender_manage.dart';
|
2023-08-08 09:42:35 +08:00
|
|
|
|
import 'io_reply.dart';
|
|
|
|
|
|
import 'io_sender.dart';
|
|
|
|
|
|
import 'io_type.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class GetPublicKeyCommand extends SenderProtocol {
|
|
|
|
|
|
|
|
|
|
|
|
String? lockID;
|
|
|
|
|
|
GetPublicKeyCommand({
|
|
|
|
|
|
this.lockID,
|
|
|
|
|
|
}) : super(CommandType.getLockPublicKey);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
List<int> messageDetail() {
|
|
|
|
|
|
List<int> data = [];
|
2023-08-10 18:56:29 +08:00
|
|
|
|
|
|
|
|
|
|
// 指令类型
|
|
|
|
|
|
int type = commandType!.typeValue;
|
|
|
|
|
|
double typeDouble = type/256;
|
|
|
|
|
|
int type1 = typeDouble.toInt();
|
|
|
|
|
|
int type2 = type%256;
|
|
|
|
|
|
data.add(type1);
|
|
|
|
|
|
data.add(type2);
|
2023-08-12 18:32:49 +08:00
|
|
|
|
// print("type:$type");
|
|
|
|
|
|
// print("type1:$type1");
|
|
|
|
|
|
// print("type2:$type2");
|
2023-08-10 18:56:29 +08:00
|
|
|
|
|
2023-08-08 09:42:35 +08:00
|
|
|
|
print("lockID:${lockID!} lockID.utf8.encode${utf8.encode(lockID!)}");
|
2023-08-09 15:42:26 +08:00
|
|
|
|
int length = utf8.encode(lockID!).length;
|
2023-08-08 09:42:35 +08:00
|
|
|
|
data.addAll(utf8.encode(lockID!));
|
2023-08-09 15:42:26 +08:00
|
|
|
|
data = getFixedLengthList(data, 40 - length);
|
2023-08-12 18:32:49 +08:00
|
|
|
|
// print("dataaaaaa:$data");
|
2023-08-08 09:42:35 +08:00
|
|
|
|
return data;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class GetPublicKeyReply extends Reply {
|
|
|
|
|
|
GetPublicKeyReply.parseData(CommandType commandType, List<int> dataDetail)
|
|
|
|
|
|
: super.parseData(commandType, dataDetail) {
|
2023-08-11 14:50:42 +08:00
|
|
|
|
var tokenData = dataDetail.sublist(3);
|
|
|
|
|
|
print('获取公钥:dataDetail:$dataDetail tokenData:$tokenData');
|
|
|
|
|
|
switch(dataDetail[2]){
|
2023-08-09 09:32:09 +08:00
|
|
|
|
case 0x00:
|
|
|
|
|
|
//成功
|
2023-08-11 14:50:42 +08:00
|
|
|
|
String stringEncoded = base64.encode(tokenData);
|
2023-08-09 15:42:26 +08:00
|
|
|
|
print('获取公钥成功 publickey:$stringEncoded');
|
|
|
|
|
|
// 储存公钥
|
2023-08-12 18:32:49 +08:00
|
|
|
|
// Storage.setData("bluePublicKey", stringEncoded);
|
2023-08-11 15:54:38 +08:00
|
|
|
|
IoSenderManage.getPrivateKey("TMH_c3570480da8d", "1", "1", 1, tokenData, 1);
|
2023-08-09 09:32:09 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case 0x07:
|
|
|
|
|
|
//无权限
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0x0f:
|
|
|
|
|
|
//用户已存在
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
//失败
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2023-08-08 09:42:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|