|
@@ -23,6 +23,11 @@ using Microsoft.EntityFrameworkCore;
|
|
|
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
|
|
|
using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication;
|
|
|
using HengshanPaymentTerminal.Mqtt.Request;
|
|
|
+using HengshanPaymentTerminal.Http;
|
|
|
+using HengshanPaymentTerminal.Http.Request;
|
|
|
+using System.Text.Json;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using HengshanPaymentTerminal.Http.Response;
|
|
|
|
|
|
namespace HengshanPaymentTerminal
|
|
|
{
|
|
@@ -78,6 +83,8 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
private byte frame = 0x00;
|
|
|
private object lockFrame = new object();
|
|
|
+
|
|
|
+ private readonly IHttpClientUtil httpClientUtil;
|
|
|
#endregion
|
|
|
|
|
|
#region Logger
|
|
@@ -118,6 +125,7 @@ namespace HengshanPaymentTerminal
|
|
|
string.Join(";", config.PumpNozzleLogicIds.Select(m => $"{m.PumpId}={m.LogicIds}")),
|
|
|
string.Join(";", config.PumpSiteNozzleNos.Select(m => $"{m.PumpId}={m.SiteNozzleNos}")),
|
|
|
string.Join(";", config.NozzleLogicIds.Select(m => $"{m.NozzleNo}={m.LogicId}")))
|
|
|
+ //clientUtil)
|
|
|
{
|
|
|
|
|
|
}
|
|
@@ -128,6 +136,7 @@ namespace HengshanPaymentTerminal
|
|
|
string pumpNozzles,
|
|
|
string pumpSiteNozzleNos,
|
|
|
string nozzleLogicIds)
|
|
|
+ //IHttpClientUtil clientUtil)
|
|
|
{
|
|
|
this.pumpIds = pumpIds;
|
|
|
this.pumpSubAddresses = pumpSubAddresses;
|
|
@@ -135,6 +144,7 @@ namespace HengshanPaymentTerminal
|
|
|
this.pumpSiteNozzleNos = pumpSiteNozzleNos;
|
|
|
this.nozzleLogicIds = nozzleLogicIds;
|
|
|
this.MysqlDbContext = new MysqlDbContext();
|
|
|
+ this.httpClientUtil = new HttpClientUtils();
|
|
|
|
|
|
GetInfo();
|
|
|
AssociatedPumpIds = GetPumpIdList(pumpIds);
|
|
@@ -431,8 +441,9 @@ namespace HengshanPaymentTerminal
|
|
|
{
|
|
|
//添加或修改数据库订单
|
|
|
OrderFromMachine orderFromMachine = (OrderFromMachine)context.Incoming.Message;
|
|
|
- int row = UpLoadOrder(orderFromMachine);
|
|
|
- logger.Info($"receive order from machine,database had ${row} count change");
|
|
|
+ FccOrderInfo fccOrderInfo = UpLoadOrder(orderFromMachine);
|
|
|
+ logger.Info($"receive order from machine,database had change");
|
|
|
+ CreateTransaction(fccOrderInfo);
|
|
|
break;
|
|
|
}
|
|
|
//普通应答
|
|
@@ -720,7 +731,7 @@ namespace HengshanPaymentTerminal
|
|
|
byte[] commandAndNozzle = { 0x19, (byte)orderInfo.NozzleNum };
|
|
|
byte[] ttcBytes = NumberToByteArrayWithPadding(orderInfo.Ttc, 4);
|
|
|
|
|
|
- byte[] amountPayableBytes = FormatDecimal(orderInfo.AmountPayable);
|
|
|
+ byte[] amountPayableBytes = FormatDecimal(orderInfo.AmountPayable ?? orderInfo.Amount);
|
|
|
list.AddRange(commandAndNozzle); //添加命令字和枪号
|
|
|
list.AddRange(ttcBytes); //添加流水号
|
|
|
list.Add(0x21); //由fcc推送实付金额表示该订单是二维码小程序支付的
|
|
@@ -824,28 +835,60 @@ namespace HengshanPaymentTerminal
|
|
|
/// </summary>
|
|
|
/// <param name="order">接收到油机的订单信息</param>
|
|
|
/// <returns></returns>
|
|
|
- public int UpLoadOrder(CommonMessage order)
|
|
|
+ public FccOrderInfo UpLoadOrder(OrderFromMachine order)
|
|
|
{
|
|
|
//接收到油机发送过来的订单信息
|
|
|
- if(order is OrderFromMachine)
|
|
|
+ OrderFromMachine orderFromMachine = (OrderFromMachine)order;
|
|
|
+ FccOrderInfo orderByMessage = orderFromMachine.ToComponent();
|
|
|
+
|
|
|
+ /** 根据枪号+流水号+授权时间来确定订单,因为冷启动后流水号会从头开始计算
|
|
|
+ * 后支付时直接将数据库直接插入
|
|
|
+ * 预支付时由于是云端先创建订单,发起授权响应成功后会插入数据库,响应成功时会回复授权时间,枪号,流水号
|
|
|
+ */
|
|
|
+ FccOrderInfo? fccOrderInfo = MysqlDbContext.fccOrderInfos
|
|
|
+ .Where(order =>
|
|
|
+ order.NozzleNum == orderFromMachine.nozzleNum && order.Ttc == orderFromMachine.ttc
|
|
|
+ && order.AuthorizationTime == orderFromMachine.dispenserTime)
|
|
|
+ .FirstOrDefault();
|
|
|
+ if (fccOrderInfo == null)
|
|
|
{
|
|
|
- OrderFromMachine orderFromMachine = (OrderFromMachine)order;
|
|
|
- FccOrderInfo orderByMessage = orderFromMachine.ToComponent();
|
|
|
- FccOrderInfo? fccOrderInfo = MysqlDbContext.fccOrderInfos.FirstOrDefault(fccOrder =>
|
|
|
- fccOrder.NozzleNum == orderFromMachine.nozzleNum && fccOrder.Ttc == orderFromMachine.ttc);
|
|
|
- if (fccOrderInfo == null)
|
|
|
- {
|
|
|
- logger.Info($"receive order from machine,find order from database is null");
|
|
|
- MysqlDbContext.fccOrderInfos.Add(orderByMessage);
|
|
|
- }
|
|
|
- else
|
|
|
+ logger.Info($"receive order from machine,find order from database is null");
|
|
|
+ MysqlDbContext.fccOrderInfos.Add(orderByMessage);
|
|
|
+ MysqlDbContext.SaveChanges();
|
|
|
+ return orderByMessage;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ logger.Info($"receive order from machine,padding data right now");
|
|
|
+ orderFromMachine.PaddingAuthorizationOrderData(fccOrderInfo);
|
|
|
+ MysqlDbContext.SaveChanges();
|
|
|
+ return fccOrderInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private async void CreateTransaction(FccOrderInfo fccOrderInfo)
|
|
|
+ {
|
|
|
+
|
|
|
+ CreateTransaction createTransaction = new CreateTransaction(fccOrderInfo,stationInfo.SecretId);
|
|
|
+ logger.Info($"create transaction,type is {createTransaction.type}");
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.CreateTransaction(JsonConvert.SerializeObject(createTransaction));
|
|
|
+ Response<long>? response = JsonConvert.DeserializeObject<Response<long>>(await httpResponseMessage.Content.ReadAsStringAsync());
|
|
|
+ logger.Info($"reveice create transaction response:{JsonConvert.SerializeObject(response)}");
|
|
|
+ // 后支付填充云端id
|
|
|
+ if(response != null && createTransaction.type == 2)
|
|
|
+ {
|
|
|
+ FccOrderInfo? currentOrder = MysqlDbContext.fccOrderInfos
|
|
|
+ .Where(order =>
|
|
|
+ order.NozzleNum == fccOrderInfo.NozzleNum && order.Ttc == fccOrderInfo.Ttc
|
|
|
+ && order.AuthorizationTime == fccOrderInfo.AuthorizationTime)
|
|
|
+ .FirstOrDefault();
|
|
|
+ if(currentOrder != null)
|
|
|
{
|
|
|
- logger.Info($"receive order from machine,padding data right now");
|
|
|
- orderFromMachine.PaddingAuthorizationOrderData(fccOrderInfo);
|
|
|
+ currentOrder.CloundOrderId = response.data;
|
|
|
+ MysqlDbContext.SaveChanges();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- return MysqlDbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|