From 41995c4cd30ca1c5a814ea0af6f70d3b86368137 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期五, 20 八月 2021 09:07:07 +0800
Subject: [PATCH] 2021-08-20 09:06:44
---
HDL_ON/DAL/Mqtt/MqttClient.cs | 65 +++++++++++++++++++++-----------
1 files changed, 42 insertions(+), 23 deletions(-)
diff --git a/HDL_ON/DAL/Mqtt/MqttClient.cs b/HDL_ON/DAL/Mqtt/MqttClient.cs
index 4212f96..ab7a620 100644
--- a/HDL_ON/DAL/Mqtt/MqttClient.cs
+++ b/HDL_ON/DAL/Mqtt/MqttClient.cs
@@ -20,7 +20,7 @@
/// <summary>
/// 鍔犲瘑閫氳KEY
/// </summary>
- static string mqttEncryptKey = "";
+ //static string mqttEncryptKey = "";
static string tuyaEncryptKey = "";
//static string checkGatewayTopicBase64 = "";
static bool hadGateway = true;
@@ -206,10 +206,16 @@
};
#region 鏁版嵁鏇存柊鎺ㄩ�佷富棰�
- //appHomeRefresh锛氫綇瀹呮暟鎹埛鏂伴�氱煡
+ //appHomeRefresh锛氫綇瀹呮暟鎹埛鏂伴�氱煡--鏉ㄦ稕
var appHomeRefresh = new MqttTopicFilter()
{
Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appHomeRefresh/up",
+ QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
+ };
+ //浣忓畢娑堟伅鍙樻洿鎺ㄩ��--璞嗚眴
+ var residenceChange = new MqttTopicFilter()
+ {
+ Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appDeviceRefresh/up",
QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
};
//appRoomRefresh锛氭埧闂存暟鎹埛鏂伴�氱煡
@@ -221,13 +227,13 @@
//appDeviceRefresh锛氳澶囨暟鎹埛鏂伴�氱煡
var appDeviceRefresh = new MqttTopicFilter()
{
- Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appDeviceRefresh/up",
+ Topic = $"/user/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/app/thing/event/appHomeRefresh/up",
QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
};
- //缃戝叧瀵嗛挜鏇存柊閫氱煡
+ //涓�绔彛瀵嗛挜鏇存柊閫氱煡
var mqttkeyChange = new MqttTopicFilter()
{
- Topic = $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/custom/mqtt/secret/change",
+ Topic = $"/user/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/custom/mqtt/secret/change",
QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce
};
@@ -237,7 +243,7 @@
Utlis.WriteLine("寮�濮嬭闃咃紒");
var result = await RemoteMqttClient.SubscribeAsync(new MqttTopicFilter[] {
pirStatus,pirStudy,
- appDeviceRefresh,appHomeRefresh,appRoomRefresh,
+ appDeviceRefresh,appHomeRefresh,appRoomRefresh,residenceChange,
topicFilterPush2, topicAlinkStatus ,mqttkeyChange});
if (result.Items[0].ResultCode == MQTTnet.Client.Subscribing.MqttClientSubscribeResultCode.GrantedQoS0)
{
@@ -295,7 +301,7 @@
try
{
var topic = e.ApplicationMessage.Topic;
- //MainPage.Log($"鏀跺埌mqtt涓婚:{topic}");
+ MainPage.Log($"鏀跺埌mqtt涓婚:{topic}");
//涓�绔彛涓婚澶勭悊
if (DB_ResidenceData.Instance.GatewayType == 0 && !DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull())
{
@@ -322,10 +328,7 @@
}
//涓�浜涚壒娈婄殑涓婚澶勭悊(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣� true:鎵ц浜嗙壒娈婂鐞� false:娌℃湁鎵ц鐗规畩澶勭悊)
- if (Stan.HdlCloudReceiveLogic.Current.CloudOverallMsgReceiveEx(topic, e.ApplicationMessage.Payload, mqttEncryptKey, tuyaEncryptKey) == true)
- {
- return;
- }
+ Stan.HdlCloudReceiveLogic.Current.CloudOverallMsgReceiveEx(topic, e.ApplicationMessage.Payload, DB_ResidenceData.Instance.HomeGateway.aesKey, tuyaEncryptKey);
if (topic == $"/BusGateWayToClient/{UserInfo.Current.ID}" + PushNotifySqueeze)
{
@@ -349,7 +352,8 @@
}
#region 鏁版嵁鏇存柊鎺ㄩ�佷富棰�
//appHomeRefresh锛氫綇瀹呮暟鎹埛鏂伴�氱煡
- else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appHomeRefresh/up")
+ else if (topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appHomeRefresh/up"
+ || topic == $"/user/{DB_ResidenceData.Instance.CurrentRegion.id}/app/thing/event/appDeviceRefresh/up")
{
MainPage.Log("浣忓畢鏁版嵁鍒锋柊閫氱煡");
new HttpServerRequest().GetHomePager();
@@ -428,10 +432,7 @@
{
var pm = new HttpServerRequest();
pm.GetHomeGatewayList();
- MainPage.Log($"缃戝叧瀵嗛挜鍙樻洿");
- MainPage.Log($"鏃у瘑閽ワ細{mqttEncryptKey}");
- mqttEncryptKey = MqttInfoConfig.Current.HomeGatewayInfo.aesKey;
- MainPage.Log($"鏂板瘑閽ワ細{mqttEncryptKey}");
+ MainPage.Log($"缃戝叧瀵嗛挜鍙樻洿.鏂板瘑閽ワ細{DB_ResidenceData.Instance.HomeGateway.aesKey}");
}
#endregion
@@ -450,9 +451,9 @@
//bus鏁版嵁瑙f瀽
var packet = new Packet();
- if (!string.IsNullOrEmpty(mqttEncryptKey))
+ if (!string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.aesKey))
{
- packet.Bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, mqttEncryptKey);
+ packet.Bytes = Securitys.EncryptionService.AesDecryptPayload(e.ApplicationMessage.Payload, DB_ResidenceData.Instance.HomeGateway.aesKey);
}
else
{
@@ -488,6 +489,25 @@
#endregion
//(4)===========寮�濮嬭繛鎺ヨ繃绋�==========
+
+ ////涓�绔彛姣忔閮借鍒锋柊瀵嗛挜
+ //if (DB_ResidenceData.Instance.HomeGateway != null && DB_ResidenceData.Instance.HomeGateway.gatewayType == "BUSUDPGATEWAY") {
+ // var pm = new HttpServerRequest();
+ // var result = pm.GetHomeGatewayList();
+ // if(result == StateCode.SUCCESS)
+ // {
+ // MainPage.Log($"鍒锋柊涓�绔彛瀵嗛挜");
+ // MainPage.Log($"鏃у瘑閽ワ細{mqttEncryptKey}");
+ // mqttEncryptKey = MqttInfoConfig.Current.HomeGatewayInfo.aesKey;
+ // MainPage.Log($"鏂板瘑閽ワ細{mqttEncryptKey}");
+ // }else
+ // {
+ // return;
+ // }
+ //}
+
+
+
//涔嬪墠宸茬粡鑾峰彇鍙傛暟鎴愬姛杩�
if (MqttInfoConfig.Current.IfGetMqttInfoSuccess)
{
@@ -603,7 +623,7 @@
- mqttEncryptKey = MqttInfoConfig.Current.HomeGatewayInfo.aesKey;
+ //mqttEncryptKey = MqttInfoConfig.Current.HomeGatewayInfo.aesKey;
//瑙e瘑瀵嗛挜瑙勫垯锛氬凡鐜版湁鐨勪綇瀹匢D涓哄熀鍑�,浠庡彸杈逛竴涓�鑾峰彇鍊�,鏈�鍚庡鏋滀笉澶�16浣�,鍒欏線鍙宠ˉ闆�
string aesKey = string.Empty;
for (int i = DB_ResidenceData.Instance.CurrentRegion.id.Length - 1; i >= 0; i--)
@@ -621,8 +641,6 @@
.WithCleanSession()
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V311)
.WithCommunicationTimeout(new TimeSpan(0, 0, 10))
- //.WithCommunicationTimeout (new TimeSpan (0, 0, 5))
- //.WithCommunicationTimeout (new TimeSpan (0, 1, 0))
.Build();
await DisConnectRemoteMqttClient("StartRemoteMqtt");
@@ -710,6 +728,7 @@
case "18316672920":
case "15971583093":
case "15626203746":
+ case "551775569@qq.com":
return;
}
@@ -778,9 +797,9 @@
{
case 0:
topicName = $"/ClientToBusGateWay/{MqttInfoConfig.Current.HomeGatewayInfo.gatewayId}/Common/ON";
- if (!string.IsNullOrEmpty(mqttEncryptKey))
+ if (!string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.aesKey))
{
- message = Securitys.EncryptionService.AesEncryptPayload(message, mqttEncryptKey);
+ message = Securitys.EncryptionService.AesEncryptPayload(message, DB_ResidenceData.Instance.HomeGateway.aesKey);
}
await RemoteMqttClient.PublishAsync(new MqttApplicationMessage { Topic = topicName, Payload = message, Retain = false, QualityOfServiceLevel = MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce });
break;
--
Gitblit v1.8.0