gxc
2019-11-15 05ce435c3b58e53eeab04c672affdeeab75f3036
ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
@@ -221,6 +221,7 @@
        /// <para>第一个参数:如果为 DDevice/IsGetEpointInfo:有新设备加入zigbee网络反馈</para>设备请求APP获取升级数据
        /// <para>第一个参数:如果为 Device/DeviceJoinZbNet:获取新设备所有端点信息是否成功反馈</para>
        /// <para>第一个参数:如果为 DeviceRequestAcUpdateData: 设备请求空调发升级数据</para>
        /// "已经通知");//已经通知");
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public Action<string, object> ReportAction;
@@ -3316,10 +3317,7 @@
                        DefaultCommunicationTimeout = new TimeSpan(0, 0, 100),//设置超时时间
                    };
                    //远程通讯连接,连接云端服务器 
                    if (RemoteMqttClient != null)
                    {
                        await RemoteMqttClient.ConnectAsync(connectCloudMqttClientOptions);
                    }
                    await RemoteMqttClient.ConnectAsync(connectCloudMqttClientOptions);
                }
                catch (Exception ex)
@@ -3387,6 +3385,13 @@
        /// </summary>
        async System.Threading.Tasks.Task SendRemoteMsg(string topicName, byte[] message, MQTTnet.Core.Protocol.MqttQualityOfServiceLevel qosLevel = MQTTnet.Core.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, bool retain = false)
        {
            //#region MD5加密 token
            //var result = System.Text.Encoding.UTF8.GetBytes(Shared.Common.Config.Instance.Password);
            //var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
            //var output = md5.ComputeHash(result);
            //var md5Password = BitConverter.ToString(output).Replace("-", "").ToUpper();
            //#endregion
            //(1)生成[用户名:密码]
            var userNameAndPwdStr = string.Concat(Shared.Common.Config.Instance.Guid, RemoteOperatorConsts.CAP_NUMBER, Shared.Common.Config.Instance.MD5PWD);
            DebugPrintLog($"userNameAndPwdStr:{userNameAndPwdStr} ");
@@ -3397,10 +3402,11 @@
            //(3)将(2)继续生成格式[Base64(用户名:密码):Timestamp]
            var userNameAndPwdStrBaseSexFourAndTimestamp = string.Concat(userNameAndPwdStrBaseSexFour, RemoteOperatorConsts.CAP_NUMBER, CurrentTimeStamp.ToString());
            //[Zigbee.Buspro]App/id(帐号Id)/Base64(DES[Base64(用户名:密码):Timestamp ]/网关唯一Id/转发给网关的主题/XX/XX
            ///[Zigbee.Buspro]App/id(帐号Id)/Base64(DES[Base64(用户名:密码):Timestamp ]/网关唯一Id/转发给网关的主题/XX/XX
            //(4)生成上报主题,主题模式需要为  /ZigbeeApp/id(主子调试帐号Id)/Base64(DES[Base64(用户名:密码):Timestamp ]/网关唯一Id/topicName "000204022022"   GateWayId  000204022022
            var reportTopic = string.Format("/{0}/{1}/{2}/{3}/{4}", RemoteOperatorConsts.ZIGBEE_APP_STARTS_WITH, Shared.Common.Config.Instance.Guid, userNameAndPwdStrBaseSexFourAndTimestamp, this.getGatewayBaseInfo?.gwID, topicName);
            var aa = System.Text.Encoding.UTF8.GetString(message);
            DebugPrintLog($"AAAA发送到云端主题明文:{reportTopic}___BBBBB发送到云端内容明文:{aa}");
            string topicEncStr = reportTopic;
            //文件流不用加密
@@ -3408,6 +3414,7 @@
            topicEncStr = topicEncStr.Replace("/", "[[$-MQTT_TILT_SYMBOL_REPLACE-$]]").Replace("+", "[[$-MQTT_PLUS_SYMBOL_REPLACE-$]]");
            message = System.Text.Encoding.UTF8.GetBytes(SecuritySet.AesEncrypt(message, Shared.Common.Config.Instance.MqttKey));
            var bb = System.Text.Encoding.UTF8.GetString(message);
            DebugPrintLog($"CCCC发送到云端主题秘文:{topicEncStr}___DDDD发送到云端内容秘文:{bb}");
            //(6)构建Mqtt需要发布的数据包,发布给云端的MqttBroker
            await RemoteMqttClient.PublishAsync(new MQTTnet.Core.MqttApplicationMessage(topicEncStr, message, qosLevel, retain));
@@ -3912,6 +3919,54 @@
                    UpdateDeviceInfo(tempDevice, "DeviceStatusReport");
                }
                #endregion
                #region 门锁操作事件通知
                else if (topic == gatewayID + "/" + "DoorLock/DoorLockOperatingEventNotificationCommand")
                {
                    var deviceID = jobject.Value<int>("Device_ID");
                    switch ((DeviceType)(deviceID))
                    {
                        case DeviceType.DoorLock:
                            var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
                            var OperatingEventNotificationDatad = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockOperatingEventNotificationCommand>(jobject["Data"].ToString());
                            if (OperatingEventNotificationDatad != null)
                            {
                                doorLock.doorLockOperatingEventNotificationCommand = OperatingEventNotificationDatad;
                            }
                            if (gwa.ReportAction != null)
                            {
                                DebugPrintLog("DoorLockProgrammingEventNotificationCommand已经通知");
                                gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock);
                            }
                            UpdateDeviceStatus(doorLock);
                            UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand");
                            break;
                    }
                }
                #endregion
                #region 门锁编程事件通知
                else if (topic == gatewayID + "/" + "DoorLock/DoorLockProgrammingEventNotificationCommand")
                {
                    var deviceID = jobject.Value<int>("Device_ID");
                    switch ((DeviceType)(deviceID))
                    {
                        case DeviceType.DoorLock:
                            var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
                            var ProgrammingEventNotificationData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockProgrammingEventNotificationCommand>(jobject["Data"].ToString());
                            if (ProgrammingEventNotificationData != null)
                            {
                                doorLock.doorLockProgrammingEventNotificationCommand = ProgrammingEventNotificationData;
                            }
                            if (gwa.ReportAction != null)
                            {
                                DebugPrintLog("DoorLockProgrammingEventNotificationCommand已经通知");
                                gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock);
                            }
                            UpdateDeviceStatus(doorLock);
                            UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand");
                            break;
                    }
                }
                #endregion
                #region IAS安防信息上报
                else if (topic == gatewayID + "/" + "IASInfoReport")
                {