Эх сурвалжийг харах

feat:MQTT收取云端支付信息

Zhenghanjv 3 сар өмнө
parent
commit
1af4d843b9

+ 5 - 1
Edge.Core/Domain/FccOrderInfo/FccOrderInfo.cs

@@ -49,7 +49,7 @@ namespace Edge.Core.Domain.FccOrderInfo
         public String OilName { get; set; }
 
         /// <summary>
-        /// 支付状态
+        /// 支付状态: 0:未支付 1:已支付 2:退全款 3:退余额:4:卡支付
         /// </summary>
         public int PaymentStatus {  get; set; }
 
@@ -78,6 +78,10 @@ namespace Edge.Core.Domain.FccOrderInfo
         /// </summary>
         public decimal? AmountPayable { get; set; }
 
+        /// <summary>
+        /// 退款金额
+        /// </summary>
+        public decimal? RefundAmount { get; set; }
         /// <summary>
         /// 单价
         /// </summary>

+ 42 - 0
Edge.Core/MqttClient/IMqttClientService.cs

@@ -0,0 +1,42 @@
+using MQTTnet.Client;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Edge.Core.MqttClient
+{
+    public interface IMqttClientService
+    {
+        /// <summary>
+        /// 开启 Mqtt
+        /// </summary>
+        /// <param name="topics">要订阅的主题</param>
+        void Start();
+
+        /// <summary>
+        /// 发布主题
+        /// </summary>
+        /// <param name="topic">发布的主题</param>
+        /// <param name="paramsJson">参数 json 串</param>
+        void Public(string topic, string paramsJson);
+
+        /// <summary>
+        /// MQTT 已连接事件
+        /// </summary>
+        event EventHandler<MqttClientConnectedEventArgs> OnConnect;
+
+        /// <summary>
+        /// MQTT 已断开事件
+        /// </summary>
+        event EventHandler<MqttClientDisconnectedEventArgs> OnDisconnect;
+
+        /// <summary>
+        /// MQTT 获取到信息事件
+        /// </summary>
+        event EventHandler<MqttApplicationMessageReceivedEventArgs> OnApplicationMessageReceived;
+
+
+    }
+}

+ 110 - 0
Edge.Core/MqttClient/MqttClientService.cs

@@ -0,0 +1,110 @@
+using Edge.Core.Core.database;
+using MQTTnet;
+using MQTTnet.Client;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Edge.Core.MqttClient
+{
+    public class MqttClientService: IMqttClientService
+    {
+        private static NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
+
+        private string[] topics;//需要订阅的主题
+        private IMqttClient _mqttClient; //mqtt 客户端
+        public MqttClientService() { }
+
+        public event EventHandler<MqttClientConnectedEventArgs> OnConnect;
+        public event EventHandler<MqttClientDisconnectedEventArgs> OnDisconnect;
+        public event EventHandler<MqttApplicationMessageReceivedEventArgs> OnApplicationMessageReceived;
+
+        public void Public(string topic, string paramsJson)
+        {
+            
+        }
+
+        public void Start()
+        {
+            using (var dbContext = new MysqlDbContext())
+            {
+                Domain.FccStationInfo.FccStationInfo? fccStationInfo = dbContext.FccStationInfos.FirstOrDefault();
+                string? mqttService = fccStationInfo?.MqttService;
+                string? buildId = fccStationInfo?.BuildId;
+                if (mqttService == null || buildId == null)
+                {
+                    Logger.Info($"can not get mqttService:{mqttService} and buildId:{buildId}");
+                    return;
+                }
+                string[] hostAndPort = mqttService.Split(":");
+                MqttClientOptions mqttClientOptions = new MqttClientOptionsBuilder()
+                    .WithTcpServer(hostAndPort[0], hostAndPort[1].ToString().ToInt())
+                    .WithClientId(buildId)
+                    .WithCleanSession()
+                    .WithTlsOptions(new MqttClientTlsOptions()
+                    {
+                        UseTls = false
+                    })
+                    .Build();
+
+                _mqttClient = new MqttFactory().CreateMqttClient();
+
+                this.topics = new string[] { $"fromClound/{buildId}" };
+                _mqttClient.ConnectedAsync += mqttConnected;
+                _mqttClient.DisconnectedAsync += mqttDisConnected;
+                _mqttClient.ApplicationMessageReceivedAsync += mqttOnReceive;
+
+                _mqttClient.ConnectAsync(mqttClientOptions);
+            }
+        }
+
+        /// <summary>
+        /// MQTT 已连接事件
+        /// </summary>
+        /// <param name="args"></param>
+        /// <returns></returns>
+        private Task mqttConnected(MqttClientConnectedEventArgs args)
+        {
+            Logger.Info($"mqtt connected");
+
+            topics.ForEach(topic =>
+            {
+                _mqttClient.SubscribeAsync(topic, MQTTnet.Protocol.MqttQualityOfServiceLevel.AtLeastOnce);
+            });
+
+            OnConnect?.Invoke(this, args);
+            return Task.CompletedTask;
+        }
+
+        /// <summary>
+        /// MQTT 断开连接
+        /// </summary>
+        /// <param name="args"></param>
+        /// <returns></returns>
+        private Task mqttDisConnected(MqttClientDisconnectedEventArgs args)
+        {
+            Logger.Info($"mqtt disconnect",JsonConvert.SerializeObject(args));
+
+            Start();
+            OnDisconnect?.Invoke(this, args);
+            return Task.CompletedTask;
+        }
+
+        /// <summary>
+        /// MQTT 获取到数据
+        /// </summary>
+        /// <param name="args"></param>
+        /// <returns></returns>
+        private Task mqttOnReceive(MqttApplicationMessageReceivedEventArgs args)
+        {
+            Logger.Info($"mqtt receive message");
+
+            OnApplicationMessageReceived?.Invoke(this, args);
+            return Task.CompletedTask;
+        }
+
+    }
+}

+ 14 - 1
Edge.Core/Processor/GenericDeviceProcessor.cs

@@ -1,4 +1,5 @@
-using Edge.Core.Parser;
+using Edge.Core.MqttClient;
+using Edge.Core.Parser;
 using Edge.Core.Parser.BinaryParser.MessageEntity;
 using Edge.Core.Processor.Communicator;
 using Edge.Core.Processor.Dispatcher.Attributes;
@@ -147,6 +148,18 @@ namespace Edge.Core.Processor
                           + " From_CommOnDataReceived_To_CommOnDataWriting elapsed " + (this.perfWatch_From_CommOnDataReceived_To_CommOnDataWriting?.ElapsedMilliseconds ?? -1));
                 }
             };
+
+            //------------------------- MQTT ---------------------------------
+            MqttClientService mqttClientService = new MqttClientService();
+            mqttClientService.OnConnect += (s, a) => { };
+            mqttClientService.OnDisconnect += (s, a) => { };
+            mqttClientService.OnApplicationMessageReceived += (s, a) =>
+            {
+                var message = Encoding.UTF8.GetString(a.ApplicationMessage.Payload);
+                handler.OnReceiveMqttMessage(message);
+            };
+            
+            mqttClientService.Start();
         }
 
         //public void Dispose()

+ 19 - 13
Edge.Core/Processor/IDeviceHandler.cs

@@ -34,25 +34,31 @@ namespace Edge.Core.Processor
         Task Test(params object[] parameters) { throw new NotImplementedException("暂不支持测试"); }
 
         /// <summary>
-        /// 发送二维码信息
+        /// 接收到 MQTT 数据
         /// </summary>
-        void SendQRCodeAsync() { }
+        /// <param name="message">数据 json </param>
+        void OnReceiveMqttMessage(string message) { }
 
         /// <summary>
-        /// 发送实付金额给油机
+        /// 发送二维码信息
         /// </summary>
-        /// <param name="orderInfo"></param>
-        void SendActuallyPaid(FccOrderInfo orderInfo) { }
+        void SendQRCodeAsync() { }
 
-        /// <summary>
-        /// 设置tcp连接客户端,所连接的服务端端口
-        /// </summary>
-        void SetTcpClient(TcpClient? client,int? serverPort) { }
+        ///// <summary>
+        ///// 发送实付金额给油机
+        ///// </summary>
+        ///// <param name="orderInfo"></param>
+        //void SendActuallyPaid(FccOrderInfo orderInfo) { }
 
-        /// <summary>
-        /// 当与客户端断开链接
-        /// </summary>
-        void OnTcpDisconnect() { }
+        ///// <summary>
+        ///// 设置tcp连接客户端,所连接的服务端端口
+        ///// </summary>
+        //void SetTcpClient(TcpClient? client,int? serverPort) { }
+
+        ///// <summary>
+        ///// 当与客户端断开链接
+        ///// </summary>
+        //void OnTcpDisconnect() { }
     }
 
     public abstract class TestableActivePollingDeviceHandler<TRaw, TMessage> : IDeviceHandler<TRaw, TMessage> where TMessage : MessageBase

+ 5 - 0
Edge.Core/Processor/Outgoing/Outgoing.cs

@@ -112,6 +112,11 @@ namespace Edge.Core.Processor
 
         public virtual async Task<WriteRepsonse> WriteAsyncAndCheckIsConnect(TMessage request, Func<TMessage, TMessage, bool> responseCapture, int timeout)
         {
+            if(isConnectTask == null) return new WriteRepsonse()
+            {
+                ResponseType = WriteResponseType.DISCONNECT,
+                Data = false,
+            };
             Task<TMessage> sendTask = WriteAsync(request, responseCapture, timeout);
             Task responseTask = await Task.WhenAny(sendTask, isConnectTask.Task);
             var type = WriteResponseType.TIME_OUT;

+ 240 - 59
HengshanPaymentTerminal/HengshanPayTermHandler.cs

@@ -30,6 +30,9 @@ using Newtonsoft.Json;
 using HengshanPaymentTerminal.Http.Response;
 using HengshanPaymentTerminal.MessageEntity.Outgoing;
 using Microsoft.IdentityModel.Tokens;
+using Org.BouncyCastle.Asn1.Ocsp;
+using Newtonsoft.Json.Linq;
+using System.Net;
 
 namespace HengshanPaymentTerminal
 {
@@ -708,6 +711,48 @@ namespace HengshanPaymentTerminal
             nozzleInfoList = MysqlDbContext.NozzleInfos.ToList().Select(n => new DetailsNozzleInfoOutput(n)).ToList();
         }
 
+        /// <summary>
+        /// 接收到MQTT
+        /// </summary>
+        /// <param name="message"></param>
+        public async void OnReceiveMqttMessage(string message)
+        {
+            MqttRequest? mqttRequest = JsonConvert.DeserializeObject<MqttRequest>(message);
+            if (mqttRequest == null)
+            {
+                logger.Error($"mqtt message turn on object fail,message:{message}");
+                return;
+            }
+            switch (mqttRequest.type)
+            {
+                case MQTT_TYPE.AUTHORIZATION:
+                    {
+                        
+                        MqttAuthorizationRequest? mqttAuthorizationRequest = JsonConvert.DeserializeObject<MqttAuthorizationRequest>(mqttRequest.data);
+                        await SendAuthorizationAsync(mqttAuthorizationRequest);
+                        break;
+                    }
+                case MQTT_TYPE.UNAUTHORIZATION:
+                    {
+                        MqttUnAhorizationRequest? mqttUnAhorizationRequest = JsonConvert.DeserializeObject<MqttUnAhorizationRequest>(mqttRequest.data);
+                        await SendUnAuthorizartion(mqttUnAhorizationRequest);
+                        break;
+                    }
+                case MQTT_TYPE.PAID:
+                    {
+                        MqttPaidRequest? mqttPaidRequest = JsonConvert.DeserializeObject<MqttPaidRequest>(mqttRequest.data);
+                        await SendActuallyPaid(mqttPaidRequest);
+                        break;
+                    }
+                case MQTT_TYPE.REFUND:
+                    {
+                        MqttRefundRequest? mqttRefundRequest = JsonConvert.DeserializeObject<MqttRefundRequest>(mqttRequest.data);
+                        await OnRecieveOrderRefund(mqttRefundRequest);
+                        break;
+                    }
+            }
+        }
+
         /// <summary>
         /// 发送二维码信息给油机
         /// </summary>
@@ -773,53 +818,68 @@ namespace HengshanPaymentTerminal
         /// 发送实付金额给油机
         /// </summary>
         /// <param name="orderInfo"></param>
-        public async void SendActuallyPaid(FccOrderInfo orderInfo) 
+        public async Task SendActuallyPaid(MqttPaidRequest? request) 
         {
-            //List<Byte> list = new List<Byte>();
-            //byte[] commandAndNozzle = { 0x19, (byte)orderInfo.NozzleNum };
-            //byte[] ttcBytes = NumberToByteArrayWithPadding(orderInfo.Ttc, 4);
-
-            //byte[] amountPayableBytes = FormatDecimal(orderInfo.AmountPayable ?? orderInfo.Amount);
-            //list.AddRange(commandAndNozzle);    //添加命令字和枪号
-            //list.AddRange(ttcBytes);            //添加流水号
-            //list.Add(0x21);                     //由fcc推送实付金额表示该订单是二维码小程序支付的
-            //list.AddRange(amountPayableBytes);  //添加实付金额
-            ////添加3位交易金额1,3位交易金额2,2位优惠规则代码,10位卡应用号,4位消息鉴别码
-            //list.AddRange(new byte[] { 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00 });
-            //byte[] sendBytes = content2data(list.ToArray(), null);
-
-
-            SendActuallyPaid sendActuallyPaid = new SendActuallyPaid(orderInfo.NozzleNum, orderInfo.Ttc, orderInfo.AmountPayable ?? orderInfo.Amount, getFrame(null));
-            byte[] commandAndNozzle = { sendActuallyPaid.Handle, (byte)sendActuallyPaid.NozzleNum };
-            await SendMessageToMaichine("发送实付金额", (request, response) =>
+            if (request == null)
             {
-                if (response.Handle == (byte)CommonMessage.Command.SEND_NEED_AMOUNT)
-                {
-                    CommonAnswerBack commonAnswerBack = (CommonAnswerBack)response;
-                    return commonAnswerBack.Command == (byte)CommonMessage.Command.SEND_NEED_AMOUNT && commonAnswerBack.NozzleNum == sendActuallyPaid.NozzleNum;
-                }
-                return false;
-            }, sendActuallyPaid);
+                logger.Error($"mqtt get paid request is null");
+                return;
+            }
+
+            //通知云端当前已收到消息
+            OnGetPaidInfo onGetPaidInfo = new OnGetPaidInfo()
+            {
+                Id = request.Id,
+                Result = 1
+            };
+            await httpClientUtil.SendRecievePaidNotice(JsonConvert.SerializeObject(onGetPaidInfo));
+
+            FccOrderInfo? fccOrderInfo = MysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
+            if (fccOrderInfo == null)
+            {
+                logger.Error($"[mqtt paid order notice]:can not find order by clounid:{request.Id}");
+                return;
+            }
+            fccOrderInfo.AmountPayable = request.ActualPaymentAmount;
+            fccOrderInfo.PaymentStatus = 1;
+            MysqlDbContext.SaveChanges();
+
+            //SendActuallyPaid sendActuallyPaid = new SendActuallyPaid(orderInfo.NozzleNum, orderInfo.Ttc, orderInfo.AmountPayable ?? orderInfo.Amount, getFrame(null));
+            //byte[] commandAndNozzle = { sendActuallyPaid.Handle, (byte)sendActuallyPaid.NozzleNum };
+            //await SendMessageToMaichine("发送实付金额", (request, response) =>
+            //{
+            //    if (response.Handle == (byte)CommonMessage.Command.SEND_NEED_AMOUNT)
+            //    {
+            //        CommonAnswerBack commonAnswerBack = (CommonAnswerBack)response;
+            //        return commonAnswerBack.Command == (byte)CommonMessage.Command.SEND_NEED_AMOUNT && commonAnswerBack.NozzleNum == sendActuallyPaid.NozzleNum;
+            //    }
+            //    return false;
+            //}, sendActuallyPaid);
             //await SendMessageToMaichine("发送实付金额", BitConverter.ToString(commandAndNozzle).Replace("-", ""), sendActuallyPaid);
         }
 
-        public async Task<CommonMessage> SendAuthorization(MqttAuthorizationRequest request)
+        /// <summary>
+        /// 发送授权请求给油机
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task SendAuthorizationAsync(MqttAuthorizationRequest? request)
         {
-            //List<Byte> list = new List<Byte>();
-            //byte[] commandAndNozzle = { 0x65, (byte)request.NozzleNum };
-            //byte[] authorizationTimeBytes = ConvertDateTimeToByteArray(request.AuthorizationTime);
-            ////将小数点后移两位,因为油机只支持两位小数点,这边传过去的3位字节转为int后取后两位为十分位和百分位
-            //int value = (int)request.Value * 100;
-            //byte[] valueBytes = NumberToByteArrayWithPadding(value, 3);
-            //list.AddRange(commandAndNozzle);
-            //list.AddRange(authorizationTimeBytes);
-            //list.Add((byte)request.AuthorizationType);
-            //list.AddRange(valueBytes);
-            //byte[] sendBytes = content2data(list.ToArray(), null);
-
-            SendAuthorization sendAuthorization = new SendAuthorization(request.NozzleNum, request.AuthorizationTime, request.AuthorizationType,request.Value, getFrame(null));
+            if(request == null)
+            {
+                logger.Error($"mqtt authorization request is null");
+                return;
+            }
+
+            //添加订单到数据库
+            DateTime authorizationTime = request.AuthorizationTime ?? DateTime.Now;
+            FccOrderInfo fccOrderInfo = request.ToComponent(authorizationTime);
+            MysqlDbContext.FccOrderInfos.Add(fccOrderInfo);
+
+            //发送授权申请到油机
+            SendAuthorization sendAuthorization = new SendAuthorization((int)request.NozzleId, authorizationTime, 1,request.OriginalAmount, getFrame(null));
             byte[] commandAndNozzle = { sendAuthorization.Handle, (byte)sendAuthorization.NozzleNum };
-            return await SendMessageToMaichine("发送授权请求", (request, response) =>
+            CommonMessage commonMessage = await SendMessageToMaichine("发送授权请求", (request, response) =>
             {
                 if (response.Handle == (byte)CommonMessage.Command.ACCREDIT)
                 {
@@ -828,34 +888,155 @@ namespace HengshanPaymentTerminal
                 }
                 return false;
             }, sendAuthorization);
-            //return await SendMessageToMaichine("发送授权请求", BitConverter.ToString(commandAndNozzle).Replace("-", ""), sendAuthorization);
+
+            //发送授权结果给云端
+            string authorizationResultJson = string.Empty;
+            SendAuthorizationResult sendAuthorizationResult = new SendAuthorizationResult();
+            sendAuthorizationResult.NozzleId = request.NozzleId;
+
+            if (commonMessage.IsError)
+            {
+                ErrorMessage errorMessage = (ErrorMessage)commonMessage;
+                switch (errorMessage.TheErrorType)
+                {
+                    case CommonMessage.ErrorType.DISCONNECT:
+                        sendAuthorizationResult.OilMachineStatus = OilMachineStatus.Disconnected;
+                        break;
+                    case CommonMessage.ErrorType.TIMEOUT:
+                        sendAuthorizationResult.OilMachineStatus = OilMachineStatus.AuthorizationTimeout;
+                        break;
+                }
+            }
+            else
+            {
+                AuthorizationResponse authorization = (AuthorizationResponse)commonMessage;
+                if (authorization.Result == 0)
+                {
+                    sendAuthorizationResult.OilMachineStatus = OilMachineStatus.Failed;
+                }
+                else
+                {
+                    sendAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
+                    sendAuthorizationResult.TransactionNumber = authorization.Ttc.ToString();
+                    fccOrderInfo.Ttc = authorization.Result;
+                }
+            }
+            HttpResponseMessage httpResponseMessage = await httpClientUtil.SendAuthorizationResult(JsonConvert.SerializeObject(sendAuthorizationResult));
+            logger.Info($"send authorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content)}");
+
+            //更新订单
+            MysqlDbContext.SaveChanges();
         }
 
-        public async Task<CommonMessage> SendUnAuthorizartion(MqttUnAhorizationRequest request)
+        /// <summary>
+        /// 发送取消授权请求给油机
+        /// </summary>
+        /// <param name="request"></param>
+        public async Task SendUnAuthorizartion(MqttUnAhorizationRequest? request)
         {
-            //List<Byte> list = new List<Byte>();
-            //byte[] commandAndNozzle = { 0x66, (byte)request.NozzleNum };
-            //byte[] authorizationTimeBytes = ConvertDateTimeToByteArray(request.AuthorizationTime);
+            if (request == null)
+            {
+                logger.Error($"mqtt unauthorization request is null");
+                return;
+            }
 
-            //byte[] ttcBytes = NumberToByteArrayWithPadding(request.Ttc, 4);
-            //list.AddRange(commandAndNozzle);
-            //list.AddRange(authorizationTimeBytes);
-            //list.AddRange(ttcBytes);
-            //byte[] sendBytes = content2data(list.ToArray(), null);
+            //从请求信息中获取流水号与授权时间,没有就到数据库查找
+            int ttc = 0;
+            DateTime authorizationTime = request.AuthorizationTime ?? DateTime.Now;
+            bool ttsIntResult = int.TryParse(request.TransactionNumber, out ttc);
+            if (request.AuthorizationTime == null || !ttsIntResult)
+            {
+                FccOrderInfo? fccOrderInfo = MysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
+                if(fccOrderInfo != null)
+                {
+                    ttc = fccOrderInfo.Ttc;
+                    authorizationTime = fccOrderInfo.AuthorizationTime;
+                }
+            }
 
-            SendUnAuthorization sendUnAuthorization = new SendUnAuthorization(request.NozzleNum, request.AuthorizationTime, request.Ttc, getFrame(null));
-            byte[] commandAndNozzle = { sendUnAuthorization.Handle, (byte)sendUnAuthorization.NozzleNum };
+            SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
+            sendUnAuthorizationResult.NozzleId = request.NozzleId;
+            sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
 
-            return await SendMessageToMaichine("发送取消授权请求", (request, response) =>
+            if (ttc != 0)
             {
-                if (response.Handle == (byte)CommonMessage.Command.CANCEL_ACCREDIT)
+                SendUnAuthorization sendUnAuthorization = new SendUnAuthorization((int)request.NozzleId, authorizationTime, ttc, getFrame(null));
+                byte[] commandAndNozzle = { sendUnAuthorization.Handle, (byte)sendUnAuthorization.NozzleNum };
+
+                CommonMessage commonMessage = await SendMessageToMaichine("发送取消授权请求", (request, response) =>
+                {
+                    if (response.Handle == (byte)CommonMessage.Command.CANCEL_ACCREDIT)
+                    {
+                        UnAhorizationResponse unauthorization = (UnAhorizationResponse)response;
+                        return unauthorization.NozzleNum == sendUnAuthorization.NozzleNum;
+                    }
+                    return false;
+                }, sendUnAuthorization);
+                if (commonMessage.IsError)
                 {
-                    UnAhorizationResponse unauthorization = (UnAhorizationResponse)response;
-                    return unauthorization.NozzleNum == sendUnAuthorization.NozzleNum;
+                    ErrorMessage errorMessage = (ErrorMessage)commonMessage;
+                    switch (errorMessage.TheErrorType)
+                    {
+                        case CommonMessage.ErrorType.DISCONNECT:
+                            sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Disconnected;
+                            break;
+                        case CommonMessage.ErrorType.TIMEOUT:
+                            sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.AuthorizationTimeout;
+                            break;
+                    }
                 }
-                return false;
-            }, sendUnAuthorization);
-            //return await SendMessageToMaichine("发送取消授权请求", BitConverter.ToString(commandAndNozzle).Replace("-", ""), sendUnAuthorization);
+                else
+                {
+                    UnAhorizationResponse unAuthorization = (UnAhorizationResponse)commonMessage;
+                    if (unAuthorization.Result == 0)
+                    {
+                        sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Failed;
+                    }
+                    else
+                    {
+                        sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
+                    }
+                }
+            }
+            else
+            {
+                sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.TransactionNumberNotFound;
+            }
+
+            HttpResponseMessage httpResponseMessage = await httpClientUtil.SendUnAuthorizationResult(JsonConvert.SerializeObject(sendUnAuthorizationResult));
+            logger.Info($"send Unauthorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content)}");
+        }
+
+        /// <summary>
+        /// 接收到云端发送订单退款信息
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        private async Task OnRecieveOrderRefund(MqttRefundRequest? request)
+        {
+            if (request == null)
+            {
+                logger.Error($"mqtt OnRecieveOrderRefund request is null");
+                return;
+            }
+            //通知云端当前已收到消息
+            OnGetRefundInfo onGetRefundInfo = new OnGetRefundInfo()
+            {
+                Id = request.Id,
+                Result = 1
+            };
+            await httpClientUtil.SendRecieveRefundNotice(JsonConvert.SerializeObject(onGetRefundInfo));
+
+            FccOrderInfo? fccOrderInfo = MysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
+            if (fccOrderInfo == null)
+            {
+                logger.Error($"[mqtt refund order notice]:can not find order by clounid:{request.Id}");
+                return;
+            }
+            fccOrderInfo.AmountPayable = request.ActualPaymentAmount;
+            fccOrderInfo.PaymentStatus = 2;
+            MysqlDbContext.SaveChanges();
+
         }
 
         //public void SetTcpClient(TcpClient? tcpClient, int? serverPort)

+ 83 - 237
HengshanPaymentTerminal/Http/HttpClientUtils.cs

@@ -13,6 +13,14 @@ using Newtonsoft.Json;
 
 namespace HengshanPaymentTerminal.Http
 {
+    public enum SEND_MOTHOD
+    {
+        GET,
+        POST,
+        PUT,
+        DELETE,
+    }
+
     public class HttpClientUtils:IHttpClientUtil
     {
         static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
@@ -33,18 +41,22 @@ namespace HengshanPaymentTerminal.Http
             _httpClientService = new HttpClientService(httpClientFactory);
         }
 
-
-        /// <summary>
-        /// 发送油品信息给云端
-        /// </summary>
-        /// <param name="requestJson"></param>
-        /// <returns></returns>
-        public async Task<HttpResponseMessage> SendOilInfo(string requestJson)
+        public async Task<HttpResponseMessage> SendRquest(string api,string requestJson,SEND_MOTHOD mothod)
         {
             try
             {
                 var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
-                return await _httpClientService.PostAsync("api/nozzle/uploadProduct", requesStr);
+                switch(mothod)
+                {
+                    case SEND_MOTHOD.POST:
+                        return await _httpClientService.PostAsync(api, requesStr);
+                    case SEND_MOTHOD.PUT:
+                        return await _httpClientService.PutAsync(api, requesStr);
+                    case SEND_MOTHOD.DELETE:
+                        return await _httpClientService.DeleteAsync(api, requesStr);
+                }
+
+                throw new Exception("未定义的请求方式");
             }
             catch (Exception ex)
             {
@@ -66,6 +78,16 @@ namespace HengshanPaymentTerminal.Http
             }
         }
 
+        /// <summary>
+        /// 发送油品信息给云端
+        /// </summary>
+        /// <param name="requestJson"></param>
+        /// <returns></returns>
+        public async Task<HttpResponseMessage> SendOilInfo(string requestJson)
+        {
+            return await SendRquest("api/nozzle/uploadProduct", requestJson,SEND_MOTHOD.POST);
+        }
+
         /// <summary>
         /// 更新油品信息给云端
         /// </summary>
@@ -73,29 +95,7 @@ namespace HengshanPaymentTerminal.Http
         /// <returns></returns>
         public async Task<HttpResponseMessage> UpdateOilInfo(string requestJson)
         {
-            try
-            {
-                var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
-                return await _httpClientService.PutAsync("api/nozzle/UpdateProduct", requesStr);
-            }
-            catch (Exception ex)
-            {
-                logger.Error(ex.Message);
-                // 创建自定义错误对象
-                var error = new
-                {
-                    Message = "发生错误",
-                    Error = ex.Message,
-                    StackTrace = ex.StackTrace
-                };
-
-                // 返回 500 Internal Server Error 和 JSON 内容
-                return new HttpResponseMessage(HttpStatusCode.InternalServerError)
-                {
-                    Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
-                };
-
-            }
+            return await SendRquest("api/nozzle/UpdateProduct", requestJson, SEND_MOTHOD.PUT);
         }
 
         /// <summary>
@@ -105,29 +105,7 @@ namespace HengshanPaymentTerminal.Http
         /// <returns></returns>
         public async Task<HttpResponseMessage> DeleteOilInfo(string requestJson)
         {
-            try
-            {
-                var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
-                return await _httpClientService.DeleteAsync("api/nozzle/DeleteProduct", requesStr);
-            }
-            catch (Exception ex)
-            {
-                logger.Error(ex.Message);
-                // 创建自定义错误对象
-                var error = new
-                {
-                    Message = "发生错误",
-                    Error = ex.Message,
-                    StackTrace = ex.StackTrace
-                };
-
-                // 返回 500 Internal Server Error 和 JSON 内容
-                return new HttpResponseMessage(HttpStatusCode.InternalServerError)
-                {
-                    Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
-                };
-
-            }
+            return await SendRquest("api/nozzle/DeleteProduct", requestJson, SEND_MOTHOD.DELETE);
         }
 
         /// <summary>
@@ -137,29 +115,7 @@ namespace HengshanPaymentTerminal.Http
         /// <returns></returns>
         public async Task<HttpResponseMessage> SendTankInfo(string requestJson)
         {
-            try
-            {
-                var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
-                return await _httpClientService.PostAsync("api/nozzle/uploadTanks", requesStr);
-            }
-            catch (Exception ex)
-            {
-                logger.Error(ex.Message);
-                // 创建自定义错误对象
-                var error = new
-                {
-                    Message = "发生错误",
-                    Error = ex.Message,
-                    StackTrace = ex.StackTrace
-                };
-
-                // 返回 500 Internal Server Error 和 JSON 内容
-                return new HttpResponseMessage(HttpStatusCode.InternalServerError)
-                {
-                    Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
-                };
-
-            }
+            return await SendRquest("api/nozzle/uploadTanks", requestJson, SEND_MOTHOD.POST);
         }
 
         /// <summary>
@@ -169,29 +125,7 @@ namespace HengshanPaymentTerminal.Http
         /// <returns></returns>
         public async Task<HttpResponseMessage> UpdateTankInfo(string requestJson)
         {
-            try
-            {
-                var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
-                return await _httpClientService.PutAsync("api/nozzle/UpdateTanks", requesStr); ;
-            }
-            catch (Exception ex)
-            {
-                logger.Error(ex.Message);
-                // 创建自定义错误对象
-                var error = new
-                {
-                    Message = "发生错误",
-                    Error = ex.Message,
-                    StackTrace = ex.StackTrace
-                };
-
-                // 返回 500 Internal Server Error 和 JSON 内容
-                return new HttpResponseMessage(HttpStatusCode.InternalServerError)
-                {
-                    Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
-                };
-
-            }
+            return await SendRquest("api/nozzle/UpdateTanks", requestJson, SEND_MOTHOD.PUT);
         }
 
         /// <summary>
@@ -201,29 +135,7 @@ namespace HengshanPaymentTerminal.Http
         /// <returns></returns>
         public async Task<HttpResponseMessage> DeleteTankInfo(string requestJson)
         {
-            try
-            {
-                var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
-                return await _httpClientService.DeleteAsync("api/nozzle/DeleteTanks", requesStr);
-            }
-            catch (Exception ex)
-            {
-                logger.Error(ex.Message);
-                // 创建自定义错误对象
-                var error = new
-                {
-                    Message = "发生错误",
-                    Error = ex.Message,
-                    StackTrace = ex.StackTrace
-                };
-
-                // 返回 500 Internal Server Error 和 JSON 内容
-                return new HttpResponseMessage(HttpStatusCode.InternalServerError)
-                {
-                    Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
-                };
-
-            }
+            return await SendRquest("api/nozzle/DeleteTanks", requestJson, SEND_MOTHOD.DELETE);
         }
 
         /// <summary>
@@ -233,29 +145,7 @@ namespace HengshanPaymentTerminal.Http
         /// <returns></returns>
         public async Task<HttpResponseMessage> SendNozzleInfo(string requestJson)
         {
-            try
-            {
-                var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
-                return await _httpClientService.PostAsync("api/nozzle/uploadNozzle", requesStr);
-            }
-            catch (Exception ex)
-            {
-                logger.Error(ex.Message);
-                // 创建自定义错误对象
-                var error = new
-                {
-                    Message = "发生错误",
-                    Error = ex.Message,
-                    StackTrace = ex.StackTrace
-                };
-
-                // 返回 500 Internal Server Error 和 JSON 内容
-                return new HttpResponseMessage(HttpStatusCode.InternalServerError)
-                {
-                    Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
-                };
-
-            }
+            return await SendRquest("api/nozzle/uploadNozzle", requestJson, SEND_MOTHOD.POST);
         }
 
         /// <summary>
@@ -265,29 +155,7 @@ namespace HengshanPaymentTerminal.Http
         /// <returns></returns>
         public async Task<HttpResponseMessage> UpdateNozzleInfo(string requestJson)
         {
-            try
-            {
-                var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
-                return await _httpClientService.PutAsync("api/nozzle/UpdateNozzle ", requesStr);
-            }
-            catch (Exception ex)
-            {
-                logger.Error(ex.Message);
-                // 创建自定义错误对象
-                var error = new
-                {
-                    Message = "发生错误",
-                    Error = ex.Message,
-                    StackTrace = ex.StackTrace
-                };
-
-                // 返回 500 Internal Server Error 和 JSON 内容
-                return new HttpResponseMessage(HttpStatusCode.InternalServerError)
-                {
-                    Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
-                };
-
-            }
+            return await SendRquest("api/nozzle/UpdateNozzle", requestJson, SEND_MOTHOD.PUT);
         }
 
         /// <summary>
@@ -297,29 +165,7 @@ namespace HengshanPaymentTerminal.Http
         /// <returns></returns>
         public async Task<HttpResponseMessage> DeleteNozzleInfo(string requestJson)
         {
-            try
-            {
-                var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
-                return await _httpClientService.DeleteAsync("api/nozzle/DeleteNozzle", requesStr);
-            }
-            catch (Exception ex)
-            {
-                logger.Error(ex.Message);
-                // 创建自定义错误对象
-                var error = new
-                {
-                    Message = "发生错误",
-                    Error = ex.Message,
-                    StackTrace = ex.StackTrace
-                };
-
-                // 返回 500 Internal Server Error 和 JSON 内容
-                return new HttpResponseMessage(HttpStatusCode.InternalServerError)
-                {
-                    Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
-                };
-
-            }
+            return await SendRquest("api/nozzle/DeleteNozzle", requestJson, SEND_MOTHOD.DELETE);
         }
 
 
@@ -331,58 +177,58 @@ namespace HengshanPaymentTerminal.Http
         /// <returns></returns>
         public async Task<HttpResponseMessage> SendNozzleStatu(string requestJson)
         {
-            try
-            {
-                var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
-                return await _httpClientService.PutAsync("api/nozzle/updateNozzleStatus", requesStr);
-            }
-            catch (Exception ex)
-            {
-                logger.Error(ex.Message);
-                // 创建自定义错误对象
-                var error = new
-                {
-                    Message = "发生错误",
-                    Error = ex.Message,
-                    StackTrace = ex.StackTrace
-                };
-
-                // 返回 500 Internal Server Error 和 JSON 内容
-                return new HttpResponseMessage(HttpStatusCode.InternalServerError)
-                {
-                    Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
-                };
-
-            }
+            return await SendRquest("api/nozzle/updateNozzleStatus", requestJson, SEND_MOTHOD.PUT);
         }
 
+        /// <summary>
+        /// 创建订单
+        /// </summary>
+        /// <param name="requestJson"></param>
+        /// <returns></returns>
         public async Task<HttpResponseMessage> CreateTransaction(string requestJson)
         {
-            try
-            {
-                var requesStr = new StringContent(requestJson, Encoding.UTF8, "application/json");
-                return await _httpClientService.PostAsync("api/Transactions/CreateTransactions", requesStr);
-            }
-            catch (Exception ex)
-            {
-                logger.Error(ex.Message);
-                // 创建自定义错误对象
-                var error = new
-                {
-                    Message = "发生错误",
-                    Error = ex.Message,
-                    StackTrace = ex.StackTrace
-                };
+            return await SendRquest("api/Transactions/CreateTransactions", requestJson, SEND_MOTHOD.POST);
+        }
 
-                // 返回 500 Internal Server Error 和 JSON 内容
-                return new HttpResponseMessage(HttpStatusCode.InternalServerError)
-                {
-                    Content = new StringContent(JsonConvert.SerializeObject(error), Encoding.UTF8, "application/json")
-                };
+        /// <summary>
+        /// 发送授权结果
+        /// </summary>
+        /// <param name="requestJson"></param>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public async Task<HttpResponseMessage> SendAuthorizationResult(string requestJson)
+        {
+            return await SendRquest("api/Nozzle/UpdateNozzleAuthorization", requestJson, SEND_MOTHOD.PUT);
+        }
 
-            }
+        /// <summary>
+        /// 发送取消授权结果
+        /// </summary>
+        /// <param name="requestJson"></param>
+        /// <returns></returns>
+        public async Task<HttpResponseMessage> SendUnAuthorizationResult(string requestJson)
+        {
+            return await SendRquest("api/Nozzle/UpdateCancelNozzleAuthorization", requestJson, SEND_MOTHOD.PUT);
+        }
+
+        /// <summary>
+        /// 发送当前已收到云端发送的订单支付信息
+        /// </summary>
+        /// <param name="requestJson"></param>
+        /// <returns></returns>
+        public async Task<HttpResponseMessage> SendRecievePaidNotice(string requestJson)
+        {
+            return await SendRquest("", requestJson, SEND_MOTHOD.POST);
         }
 
-        
+        /// <summary>
+        /// 发送当前已收到云端发送的订单退款信息
+        /// </summary>
+        /// <param name="requestJson"></param>
+        /// <returns></returns>
+        public async Task<HttpResponseMessage> SendRecieveRefundNotice(string requestJson)
+        {
+            return await SendRquest("", requestJson, SEND_MOTHOD.POST);
+        }
     }
 }

+ 28 - 0
HengshanPaymentTerminal/Http/IHttpClientUtil.cs

@@ -84,5 +84,33 @@ namespace HengshanPaymentTerminal.Http
         /// <param name="requestJson"></param>
         /// <returns></returns>
         Task<HttpResponseMessage> SendNozzleStatu(string requestJson);
+
+        /// <summary>
+        /// 发送授权结果到云端
+        /// </summary>
+        /// <param name="requestJson"></param>
+        /// <returns></returns>
+        Task<HttpResponseMessage> SendAuthorizationResult(string requestJson);
+
+        /// <summary>
+        /// 发送取消授权结果到云端
+        /// </summary>
+        /// <param name="requestJson"></param>
+        /// <returns></returns>
+        Task<HttpResponseMessage> SendUnAuthorizationResult(string requestJson);
+
+        /// <summary>
+        /// 发送当前已收到云端发送订单支付信息
+        /// </summary>
+        /// <param name="requestJson"></param>
+        /// <returns></returns>
+        Task<HttpResponseMessage> SendRecievePaidNotice(string requestJson);
+
+        /// <summary>
+        /// 发送当前已收到云端发送订单退款信息
+        /// </summary>
+        /// <param name="requestJson"></param>
+        /// <returns></returns>
+        Task<HttpResponseMessage> SendRecieveRefundNotice(string requestJson);
     }
 }

+ 103 - 0
HengshanPaymentTerminal/Http/Request/HttpRequest.cs

@@ -472,6 +472,109 @@ namespace HengshanPaymentTerminal.Http.Request
         public int Status { get; set; }
     }
 
+    /// <summary>
+    /// 发送授权结果
+    /// </summary>
+    public class SendAuthorizationResult : HttpRequest
+    {
+        /// <summary>
+        /// 枪号
+        /// </summary>
+        public long NozzleId { get; set; }
+
+        /// <summary>
+        /// 流水号
+        /// </summary>
+        public string TransactionNumber { get; set; } = string.Empty;
+
+        /// <summary>
+        /// 结果 1:FCC 与油机断开连接;2:FCC 发送信息到油机,但超时未回复;3:授权失败;4:授权成功
+        /// </summary>
+        public OilMachineStatus OilMachineStatus { get; set; }
+    }
+
+    /// <summary>
+    /// 发送取消授权结果
+    /// </summary>
+    public class SendUnAuthorizationResult : HttpRequest
+    {
+        /// <summary>
+        /// 枪号
+        /// </summary>
+        public long NozzleId { get; set; }
+
+        /// <summary>
+        /// 流水号
+        /// </summary>
+        public string TransactionNumber { get; set; } = string.Empty;
+
+        /// <summary>
+        /// 结果 1:FCC 与油机断开连接;2:FCC 发送信息到油机,但超时未回复;3:授权失败;4:授权成功;5:未找到流水号
+        /// </summary>
+        public OilMachineStatus OilMachineStatus { get; set; }
+    }
+
+    public enum OilMachineStatus
+    {
+        /// <summary>
+        /// FCC与油机断开连接。
+        /// </summary>
+        Disconnected = 1,
+
+        /// <summary>
+        /// FCC向油机发送授权,油机超时未回复。
+        /// </summary>
+        AuthorizationTimeout = 2,
+
+        /// <summary>
+        /// 操作失败。
+        /// </summary>
+        Failed = 3,
+
+        /// <summary>
+        /// 操作成功。
+        /// </summary>
+        Success = 4,
+        /// <summary>
+        /// 未找到交易流水号。
+        /// </summary>
+        TransactionNumberNotFound = 5
+    }
+
+    /// <summary>
+    /// 云端发送订单完成信息后回复
+    /// </summary>
+    public class OnGetPaidInfo : HttpRequest
+    {
+
+        /// <summary>
+        /// 订单id
+        /// </summary>
+        public long Id { get; set; }
+
+        /// <summary>
+        /// 结果
+        /// </summary>
+        public int Result { get; set; }
+    }
+
+    /// <summary>
+    /// 云端发送订单退款后回复
+    /// </summary>
+    public class OnGetRefundInfo : HttpRequest
+    {
+
+        /// <summary>
+        /// 订单id
+        /// </summary>
+        public long Id { get; set; }
+
+        /// <summary>
+        /// 结果
+        /// </summary>
+        public int Result { get; set; }
+    }
+
     /// <summary>
     /// 定义DateTime转json格式
     /// </summary>

+ 0 - 53
HengshanPaymentTerminal/Mqtt/Request/MqttAuthorizationRequest.cs

@@ -1,53 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace HengshanPaymentTerminal.Mqtt.Request
-{
-    /// <summary>
-    /// 云端 Mqtt 发送授权请求数据对象
-    /// </summary>
-    public class MqttAuthorizationRequest
-    {
-        /// <summary>
-        /// 枪号
-        /// </summary>
-        public int NozzleNum { get; set; }
-
-        /// <summary>
-        /// 授权时间
-        /// </summary>
-        public DateTime AuthorizationTime { get; set; }
-
-        /// <summary>
-        /// 定量类型 01:定金额;02:定升数
-        /// </summary>
-        public int AuthorizationType { get; set; }
-
-        /// <summary>
-        /// 定量值
-        /// </summary>
-        public decimal Value { get; set; }
-    }
-
-    public class MqttUnAhorizationRequest
-    {
-        /// <summary>
-        /// 枪号
-        /// </summary>
-        public int NozzleNum { get; set; }
-
-        /// <summary>
-        /// 授权时间
-        /// </summary>
-        public DateTime AuthorizationTime { get; set; }
-
-        /// <summary>
-        /// 交易流水号
-        /// </summary>
-        public int Ttc {  get; set; }
-
-    }
-}

+ 642 - 0
HengshanPaymentTerminal/Mqtt/Request/MqttRequest.cs

@@ -0,0 +1,642 @@
+using Edge.Core.Domain.FccOrderInfo;
+using HengshanPaymentTerminal.Http.Response;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+
+namespace HengshanPaymentTerminal.Mqtt.Request
+{
+    /// <summary>
+    /// 云端 MQTT 数据对象
+    /// </summary>
+    public class MqttRequest
+    {
+        /// <summary>
+        /// 类型
+        /// </summary>
+        public MQTT_TYPE type { get; set; }
+
+        /// <summary>
+        /// 数据
+        /// </summary>
+        public string data { get; set; }
+
+    }
+
+    /// <summary>
+    /// 标识 MQTT 数据类型
+    /// </summary>
+    public enum MQTT_TYPE
+    {
+        /// <summary>
+        /// 授权
+        /// </summary>
+        AUTHORIZATION = 1,
+
+        /// <summary>
+        /// 取消授权
+        /// </summary>
+        UNAUTHORIZATION = 2,
+
+        /// <summary>
+        /// 已支付发送订单信息
+        /// </summary>
+        PAID = 3,
+
+        /// <summary>
+        /// 退款发送订单信息
+        /// </summary>
+        REFUND = 4
+    }
+
+    /// <summary>
+    /// 云端 Mqtt 发送授权请求数据对象
+    /// </summary>
+    public class MqttAuthorizationRequest
+    {
+        /// <summary>
+        /// 订单唯一标识符
+        /// </summary>
+        public long Id { get; set; }
+
+        /// <summary>
+        /// 油站唯一标识符
+        /// </summary>
+        public Guid Buid { get; set; }
+
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        public long MiniProgramID { get; set; }
+
+        /// <summary>
+        /// 枪号
+        /// </summary>
+        public long NozzleId { get; set; }
+
+        /// <summary>
+        /// 油品ID
+        /// </summary>
+        public long ProductId { get; set; }
+
+        /// <summary>
+        /// 实际支付金额
+        /// </summary>
+        public decimal? ActualPaymentAmount { get; set; }
+
+        /// <summary>
+        /// 授权时间
+        /// </summary>
+        public DateTime? AuthorizationTime { get; set; }
+
+        /// <summary>
+        /// 创建人
+        /// </summary>
+        public string? CreateBy { get; set; }
+
+        /// <summary>
+        /// 订单创建时间
+        /// </summary>
+        public DateTime? CreateTime { get; set; }
+
+        /// <summary>
+        /// 挂枪时间
+        /// </summary>
+        public DateTime? FuelItemTransactionEndTime { get; set; }
+
+        /// <summary>
+        /// 是否删除
+        /// </summary>
+        public sbyte? IsDeleted { get; set; } = 0;
+
+        /// <summary>
+        /// 订单状态
+        /// </summary>
+        public transactionsORDERSTATUS OrderStatus { get; set; }
+
+        /// <summary>
+        /// 订单类型
+        /// </summary>
+        public transactionsORDERTYPE OrderType { get; set; }
+
+        /// <summary>
+        /// 原金额
+        /// </summary>
+        public decimal OriginalAmount { get; set; }
+
+        /// <summary>
+        /// 支付方式
+        /// </summary>
+        public long? PaymentMethod { get; set; }
+
+        /// <summary>
+        /// 油品名称
+        /// </summary>
+        public string ProductName { get; set; }
+
+        /// <summary>
+        /// 原升数
+        /// </summary>
+        public decimal Qty { get; set; }
+
+        /// <summary>
+        /// 实际加油升数
+        /// </summary>
+        public decimal? OriginalQty { get; set; }
+
+        /// <summary>
+        /// 退款金额
+        /// </summary>
+        public decimal? RefundAmount { get; set; }
+
+        /// <summary>
+        /// 订单流水号
+        /// </summary>
+        public string TransactionNumber { get; set; }
+
+        /// <summary>
+        /// 交易时间
+        /// </summary>
+        public DateTime? TransactionTime { get; set; }
+
+        /// <summary>
+        /// 加密字符串,用于验证金额是否篡改
+        /// </summary>
+        public string secret { get; set; }
+
+        /// <summary>
+        /// 支付返回结果
+        /// </summary>
+        public string RawResult { get; set; }
+
+        /// <summary>
+        /// 错误信息
+        /// </summary>
+        public string ErrorDetail { get; set; }
+
+        /// <summary>
+        /// 支付结果代码
+        /// </summary>
+        public string ResultCode { get; set; }
+
+        /// <summary>
+        /// 是否授权
+        /// </summary>
+        public AuthorizationStatus authorizationStatus { get; set; }
+
+        /// <summary>
+        /// 单价
+        /// </summary>
+        public decimal Price { get; set; }
+
+        public FccOrderInfo ToComponent(DateTime authorizationTime)
+        {
+            return new FccOrderInfo()
+            {
+                AuthorizationTime = authorizationTime,
+                PaymentTime = TransactionTime,
+                NozzleNum = (int)NozzleId,
+                OilName = ProductName,
+                PaymentStatus = 1,
+                PayType = (int?)PaymentMethod,
+                CloundOrderId = Id,
+                Amount = OriginalAmount,
+                Volume = Qty,
+                AmountPayable = ActualPaymentAmount,
+                UploadState = 1,
+                IsDelete = 0,
+                Price = this.Price
+                
+            };
+        }
+
+    }
+
+    /// <summary>
+    /// 云端发送取消授权数据对象
+    /// </summary>
+    public class MqttUnAhorizationRequest
+    {
+        /// <summary>
+        /// 订单唯一标识符
+        /// </summary>
+        public long Id { get; set; }
+
+        /// <summary>
+        /// 油站唯一标识符
+        /// </summary>
+        public Guid Buid { get; set; }
+
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        public long MiniProgramID { get; set; }
+
+        /// <summary>
+        /// 枪号
+        /// </summary>
+        public long NozzleId { get; set; }
+
+        /// <summary>
+        /// 油品ID
+        /// </summary>
+        public long ProductId { get; set; }
+
+        /// <summary>
+        /// 实际支付金额
+        /// </summary>
+        public decimal? ActualPaymentAmount { get; set; }
+
+        /// <summary>
+        /// 授权时间
+        /// </summary>
+        public DateTime? AuthorizationTime { get; set; }
+
+        /// <summary>
+        /// 创建人
+        /// </summary>
+        public string? CreateBy { get; set; }
+
+        /// <summary>
+        /// 订单创建时间
+        /// </summary>
+        public DateTime? CreateTime { get; set; }
+
+        /// <summary>
+        /// 挂枪时间
+        /// </summary>
+        public DateTime? FuelItemTransactionEndTime { get; set; }
+
+        /// <summary>
+        /// 是否删除
+        /// </summary>
+        public sbyte? IsDeleted { get; set; } = 0;
+
+        /// <summary>
+        /// 订单状态
+        /// </summary>
+        public transactionsORDERSTATUS OrderStatus { get; set; }
+
+        /// <summary>
+        /// 订单类型
+        /// </summary>
+        public transactionsORDERTYPE OrderType { get; set; }
+
+        /// <summary>
+        /// 原金额
+        /// </summary>
+        public decimal OriginalAmount { get; set; }
+
+        /// <summary>
+        /// 支付方式
+        /// </summary>
+        public long? PaymentMethod { get; set; }
+
+        /// <summary>
+        /// 油品名称
+        /// </summary>
+        public string ProductName { get; set; }
+
+        /// <summary>
+        /// 原升数
+        /// </summary>
+        public decimal Qty { get; set; }
+
+        /// <summary>
+        /// 实际加油升数
+        /// </summary>
+        public decimal? OriginalQty { get; set; }
+
+        /// <summary>
+        /// 退款金额
+        /// </summary>
+        public decimal? RefundAmount { get; set; }
+
+        /// <summary>
+        /// 订单流水号
+        /// </summary>
+        public string TransactionNumber { get; set; }
+
+        /// <summary>
+        /// 交易时间
+        /// </summary>
+        public DateTime? TransactionTime { get; set; }
+
+        /// <summary>
+        /// 加密字符串,用于验证金额是否篡改
+        /// </summary>
+        public string secret { get; set; }
+
+        /// <summary>
+        /// 支付返回结果
+        /// </summary>
+        public string RawResult { get; set; }
+
+        /// <summary>
+        /// 错误信息
+        /// </summary>
+        public string ErrorDetail { get; set; }
+
+        /// <summary>
+        /// 支付结果代码
+        /// </summary>
+        public string ResultCode { get; set; }
+
+        /// <summary>
+        /// 是否授权
+        /// </summary>
+        public AuthorizationStatus authorizationStatus { get; set; }
+
+        /// <summary>
+        /// 单价
+        /// </summary>
+        public decimal? Price { get; set; }
+
+    }
+
+    /// <summary>
+    /// 云端发送订单已支付数据对象
+    /// </summary>
+    public class MqttPaidRequest : MqttRequest
+    {
+        /// <summary>
+        /// 订单唯一标识符
+        /// </summary>
+        public long Id { get; set; }
+
+        /// <summary>
+        /// 油站唯一标识符
+        /// </summary>
+        public Guid Buid { get; set; }
+
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        public long MiniProgramID { get; set; }
+
+        /// <summary>
+        /// 枪号
+        /// </summary>
+        public long NozzleId { get; set; }
+
+        /// <summary>
+        /// 油品ID
+        /// </summary>
+        public long ProductId { get; set; }
+
+        /// <summary>
+        /// 实际支付金额
+        /// </summary>
+        public decimal? ActualPaymentAmount { get; set; }
+
+        /// <summary>
+        /// 授权时间
+        /// </summary>
+        public DateTime? AuthorizationTime { get; set; }
+
+        /// <summary>
+        /// 创建人
+        /// </summary>
+        public string? CreateBy { get; set; }
+
+        /// <summary>
+        /// 订单创建时间
+        /// </summary>
+        public DateTime? CreateTime { get; set; }
+
+        /// <summary>
+        /// 挂枪时间
+        /// </summary>
+        public DateTime? FuelItemTransactionEndTime { get; set; }
+
+        /// <summary>
+        /// 是否删除
+        /// </summary>
+        public sbyte? IsDeleted { get; set; } = 0;
+
+        /// <summary>
+        /// 订单状态
+        /// </summary>
+        public transactionsORDERSTATUS OrderStatus { get; set; }
+
+        /// <summary>
+        /// 订单类型
+        /// </summary>
+        public transactionsORDERTYPE OrderType { get; set; }
+
+        /// <summary>
+        /// 原金额
+        /// </summary>
+        public decimal OriginalAmount { get; set; }
+
+        /// <summary>
+        /// 支付方式
+        /// </summary>
+        public long? PaymentMethod { get; set; }
+
+        /// <summary>
+        /// 油品名称
+        /// </summary>
+        public string ProductName { get; set; }
+
+        /// <summary>
+        /// 原升数
+        /// </summary>
+        public decimal Qty { get; set; }
+
+        /// <summary>
+        /// 实际加油升数
+        /// </summary>
+        public decimal? OriginalQty { get; set; }
+
+        /// <summary>
+        /// 退款金额
+        /// </summary>
+        public decimal? RefundAmount { get; set; }
+
+        /// <summary>
+        /// 订单流水号
+        /// </summary>
+        public string TransactionNumber { get; set; }
+
+        /// <summary>
+        /// 交易时间
+        /// </summary>
+        public DateTime? TransactionTime { get; set; }
+
+        /// <summary>
+        /// 加密字符串,用于验证金额是否篡改
+        /// </summary>
+        public string secret { get; set; }
+
+        /// <summary>
+        /// 支付返回结果
+        /// </summary>
+        public string RawResult { get; set; }
+
+        /// <summary>
+        /// 错误信息
+        /// </summary>
+        public string ErrorDetail { get; set; }
+
+        /// <summary>
+        /// 支付结果代码
+        /// </summary>
+        public string ResultCode { get; set; }
+
+        /// <summary>
+        /// 是否授权
+        /// </summary>
+        public AuthorizationStatus authorizationStatus { get; set; }
+
+        /// <summary>
+        /// 单价
+        /// </summary>
+        public decimal? Price { get; set; }
+    }
+
+    /// <summary>
+    /// 云端发送订单退款数据对象
+    /// </summary>
+    public class MqttRefundRequest : MqttRequest
+    {
+        /// <summary>
+        /// 订单唯一标识符
+        /// </summary>
+        public long Id { get; set; }
+
+        /// <summary>
+        /// 油站唯一标识符
+        /// </summary>
+        public Guid Buid { get; set; }
+
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        public long MiniProgramID { get; set; }
+
+        /// <summary>
+        /// 枪号
+        /// </summary>
+        public long NozzleId { get; set; }
+
+        /// <summary>
+        /// 油品ID
+        /// </summary>
+        public long ProductId { get; set; }
+
+        /// <summary>
+        /// 实际支付金额
+        /// </summary>
+        public decimal? ActualPaymentAmount { get; set; }
+
+        /// <summary>
+        /// 授权时间
+        /// </summary>
+        public DateTime? AuthorizationTime { get; set; }
+
+        /// <summary>
+        /// 创建人
+        /// </summary>
+        public string? CreateBy { get; set; }
+
+        /// <summary>
+        /// 订单创建时间
+        /// </summary>
+        public DateTime? CreateTime { get; set; }
+
+        /// <summary>
+        /// 挂枪时间
+        /// </summary>
+        public DateTime? FuelItemTransactionEndTime { get; set; }
+
+        /// <summary>
+        /// 是否删除
+        /// </summary>
+        public sbyte? IsDeleted { get; set; } = 0;
+
+        /// <summary>
+        /// 订单状态
+        /// </summary>
+        public transactionsORDERSTATUS OrderStatus { get; set; }
+
+        /// <summary>
+        /// 订单类型
+        /// </summary>
+        public transactionsORDERTYPE OrderType { get; set; }
+
+        /// <summary>
+        /// 原金额
+        /// </summary>
+        public decimal OriginalAmount { get; set; }
+
+        /// <summary>
+        /// 支付方式
+        /// </summary>
+        public long? PaymentMethod { get; set; }
+
+        /// <summary>
+        /// 油品名称
+        /// </summary>
+        public string ProductName { get; set; }
+
+        /// <summary>
+        /// 原升数
+        /// </summary>
+        public decimal Qty { get; set; }
+
+        /// <summary>
+        /// 实际加油升数
+        /// </summary>
+        public decimal? OriginalQty { get; set; }
+
+        /// <summary>
+        /// 退款金额
+        /// </summary>
+        public decimal? RefundAmount { get; set; }
+
+        /// <summary>
+        /// 订单流水号
+        /// </summary>
+        public string TransactionNumber { get; set; }
+
+        /// <summary>
+        /// 交易时间
+        /// </summary>
+        public DateTime? TransactionTime { get; set; }
+
+        /// <summary>
+        /// 加密字符串,用于验证金额是否篡改
+        /// </summary>
+        public string secret { get; set; }
+
+        /// <summary>
+        /// 支付返回结果
+        /// </summary>
+        public string RawResult { get; set; }
+
+        /// <summary>
+        /// 错误信息
+        /// </summary>
+        public string ErrorDetail { get; set; }
+
+        /// <summary>
+        /// 支付结果代码
+        /// </summary>
+        public string ResultCode { get; set; }
+
+        /// <summary>
+        /// 是否授权
+        /// </summary>
+        public AuthorizationStatus authorizationStatus { get; set; }
+
+        /// <summary>
+        /// 单价
+        /// </summary>
+        public decimal? Price { get; set; }
+    }
+}