|
@@ -33,6 +33,9 @@ using Microsoft.IdentityModel.Tokens;
|
|
using Org.BouncyCastle.Asn1.Ocsp;
|
|
using Org.BouncyCastle.Asn1.Ocsp;
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Net;
|
|
using System.Net;
|
|
|
|
+using Edge.Core.Domain.FccOrderInfo.Output;
|
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
|
+using System.Timers;
|
|
|
|
|
|
namespace HengshanPaymentTerminal
|
|
namespace HengshanPaymentTerminal
|
|
{
|
|
{
|
|
@@ -82,6 +85,13 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
public Dictionary<long,string> stationPayment = new Dictionary<long,string>();
|
|
public Dictionary<long,string> stationPayment = new Dictionary<long,string>();
|
|
|
|
|
|
|
|
+ //记录油枪泵码
|
|
|
|
+ public ConcurrentDictionary<int,string> nozzlePumpCode = new ConcurrentDictionary<int, string>();
|
|
|
|
+
|
|
|
|
+ public string buildID = "";
|
|
|
|
+
|
|
|
|
+ public bool isSendHeart = true;
|
|
|
|
+
|
|
public List<DetailsNozzleInfoOutput> nozzleInfoList { get; private set; }
|
|
public List<DetailsNozzleInfoOutput> nozzleInfoList { get; private set; }
|
|
|
|
|
|
public TcpClient? client { get; set; }
|
|
public TcpClient? client { get; set; }
|
|
@@ -442,16 +452,28 @@ namespace HengshanPaymentTerminal
|
|
//this.MysqlDbContext = new MysqlDbContext();
|
|
//this.MysqlDbContext = new MysqlDbContext();
|
|
this.httpClientUtil = new HttpClientUtils();
|
|
this.httpClientUtil = new HttpClientUtils();
|
|
|
|
|
|
|
|
+
|
|
this.serverPort = CommIdentity.Replace("*:", "").ToInt();
|
|
this.serverPort = CommIdentity.Replace("*:", "").ToInt();
|
|
GetInfo();
|
|
GetInfo();
|
|
|
|
+
|
|
|
|
+ if(stationInfo.CheckOrderInterval > 0)
|
|
|
|
+ {
|
|
|
|
+ //开启定时任务,每分钟执行一次,检查xx分钟未取消授权的订单,并发起取消授权。xx可配置
|
|
|
|
+ System.Timers.Timer timer = new System.Timers.Timer(60000);
|
|
|
|
+ timer.Elapsed += (sender, eventArgs) =>
|
|
|
|
+ {
|
|
|
|
+ Task.Run(() => SendUnAuthorizationTimerAsync());
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
public string CommIdentity { get; private set; }
|
|
public string CommIdentity { get; private set; }
|
|
|
|
|
|
public async Task Process(IContext<byte[], CommonMessage> context)
|
|
public async Task Process(IContext<byte[], CommonMessage> context)
|
|
{
|
|
{
|
|
-
|
|
|
|
- switch(context.Incoming.Message.Handle)
|
|
|
|
|
|
+ logger.Info($"获取到信息:{JsonConvert.SerializeObject(context.Incoming.Message)}");
|
|
|
|
+ switch (context.Incoming.Message.Handle)
|
|
{
|
|
{
|
|
//心跳,带油枪状态信息
|
|
//心跳,带油枪状态信息
|
|
case 0x10:
|
|
case 0x10:
|
|
@@ -465,7 +487,18 @@ namespace HengshanPaymentTerminal
|
|
case 0x18:
|
|
case 0x18:
|
|
{
|
|
{
|
|
//添加或修改数据库订单
|
|
//添加或修改数据库订单
|
|
|
|
+ logger.Info($"订单信息");
|
|
OrderFromMachine orderFromMachine = (OrderFromMachine)context.Incoming.Message;
|
|
OrderFromMachine orderFromMachine = (OrderFromMachine)context.Incoming.Message;
|
|
|
|
+ if(nozzlePumpCode.TryGetValue(orderFromMachine.nozzleNum, out string pumpCodeAndTTC))
|
|
|
|
+ {
|
|
|
|
+ if($"{orderFromMachine.pumpCode}_{orderFromMachine.ttc}".Equals(pumpCodeAndTTC))
|
|
|
|
+ {
|
|
|
|
+ logger.Info($"收到油机订单,泵码与流水号一致,为重复发送");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ logger.Info($"收到油机订单,泵码与流水号不一致,更新信息");
|
|
|
|
+ nozzlePumpCode[orderFromMachine.nozzleNum] = $"{orderFromMachine.pumpCode}_{orderFromMachine.ttc}";
|
|
FccOrderInfo fccOrderInfo = UpLoadOrder(orderFromMachine);
|
|
FccOrderInfo fccOrderInfo = UpLoadOrder(orderFromMachine);
|
|
logger.Info($"receive order from machine,database had change");
|
|
logger.Info($"receive order from machine,database had change");
|
|
CreateOrRedeemTransaction(fccOrderInfo);
|
|
CreateOrRedeemTransaction(fccOrderInfo);
|
|
@@ -527,9 +560,9 @@ namespace HengshanPaymentTerminal
|
|
*/
|
|
*/
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
//油机的应答不用回复
|
|
//油机的应答不用回复
|
|
- if(context.Incoming.Message.Handle != 0x55) context.Outgoing.Write(context.Incoming.Message);
|
|
|
|
|
|
+ if (context.Incoming.Message.Handle != 0x55 && isSendHeart) context.Outgoing.Write(context.Incoming.Message);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -713,6 +746,7 @@ namespace HengshanPaymentTerminal
|
|
if(fccStationInfo != null)
|
|
if(fccStationInfo != null)
|
|
{
|
|
{
|
|
stationInfo = new StationInfo(fccStationInfo);
|
|
stationInfo = new StationInfo(fccStationInfo);
|
|
|
|
+ buildID = stationInfo.BuildId;
|
|
string paymentType = stationInfo.PaymentType;
|
|
string paymentType = stationInfo.PaymentType;
|
|
string[] paymentGround = paymentType.Split(",");
|
|
string[] paymentGround = paymentType.Split(",");
|
|
foreach (var item in paymentGround)
|
|
foreach (var item in paymentGround)
|
|
@@ -742,42 +776,63 @@ namespace HengshanPaymentTerminal
|
|
/// 接收到MQTT
|
|
/// 接收到MQTT
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
/// <param name="message"></param>
|
|
- public async void OnReceiveMqttMessage(string message)
|
|
|
|
|
|
+ public async void OnReceiveMqttMessage(string topic,string message)
|
|
{
|
|
{
|
|
|
|
+ logger.Info($"getMqtt topic:{topic},and message is {message}");
|
|
MqttRequest? mqttRequest = JsonConvert.DeserializeObject<MqttRequest>(message);
|
|
MqttRequest? mqttRequest = JsonConvert.DeserializeObject<MqttRequest>(message);
|
|
if (mqttRequest == null)
|
|
if (mqttRequest == null)
|
|
{
|
|
{
|
|
logger.Error($"mqtt message turn on object fail,message:{message}");
|
|
logger.Error($"mqtt message turn on object fail,message:{message}");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- switch (mqttRequest.type)
|
|
|
|
|
|
+ if ($"authorization/{buildID}".Equals(topic))
|
|
{
|
|
{
|
|
- 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, mqttRequest.UserName, mqttRequest.UserPhoneNumber);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- case MQTT_TYPE.REFUND:
|
|
|
|
- {
|
|
|
|
- MqttRefundRequest? mqttRefundRequest = JsonConvert.DeserializeObject<MqttRefundRequest>(mqttRequest.data);
|
|
|
|
- await OnRecieveOrderRefund(mqttRefundRequest);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ MqttAuthorizationRequest? mqttAuthorizationRequest = JsonConvert.DeserializeObject<MqttAuthorizationRequest>(mqttRequest.data);
|
|
|
|
+ await SendAuthorizationAsync(mqttAuthorizationRequest, mqttRequest.UserName, mqttRequest.UserPhoneNumber);
|
|
|
|
+ }
|
|
|
|
+ if($"unAuthorization/{buildID}".Equals(topic))
|
|
|
|
+ {
|
|
|
|
+ MqttUnAhorizationRequest? mqttUnAhorizationRequest = JsonConvert.DeserializeObject<MqttUnAhorizationRequest>(mqttRequest.data);
|
|
|
|
+ await SendUnAuthorizartion(mqttUnAhorizationRequest);
|
|
}
|
|
}
|
|
|
|
+ if ($"paid/{buildID}".Equals (topic))
|
|
|
|
+ {
|
|
|
|
+ MqttPaidRequest? mqttPaidRequest = JsonConvert.DeserializeObject<MqttPaidRequest>(mqttRequest.data);
|
|
|
|
+ await SendActuallyPaid(mqttPaidRequest, mqttRequest.UserName, mqttRequest.UserPhoneNumber);
|
|
|
|
+ }
|
|
|
|
+ if ($"refund/{buildID}".Equals(topic))
|
|
|
|
+ {
|
|
|
|
+ MqttRefundRequest? mqttRefundRequest = JsonConvert.DeserializeObject<MqttRefundRequest>(mqttRequest.data);
|
|
|
|
+ await OnRecieveOrderRefund(mqttRefundRequest);
|
|
|
|
+ }
|
|
|
|
+ //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, mqttRequest.UserName, mqttRequest.UserPhoneNumber);
|
|
|
|
+ // break;
|
|
|
|
+ // }
|
|
|
|
+ // case MQTT_TYPE.REFUND:
|
|
|
|
+ // {
|
|
|
|
+ // MqttRefundRequest? mqttRefundRequest = JsonConvert.DeserializeObject<MqttRefundRequest>(mqttRequest.data);
|
|
|
|
+ // await OnRecieveOrderRefund(mqttRefundRequest);
|
|
|
|
+ // break;
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -860,43 +915,52 @@ namespace HengshanPaymentTerminal
|
|
Id = request.Id,
|
|
Id = request.Id,
|
|
Result = 1
|
|
Result = 1
|
|
};
|
|
};
|
|
- await httpClientUtil.SendRecievePaidNotice(JsonConvert.SerializeObject(onGetPaidInfo));
|
|
|
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.SendRecievePaidNotice(JsonConvert.SerializeObject(onGetPaidInfo));
|
|
|
|
+ logger.Info($"send actuallyPaid result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
|
|
- FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order =>
|
|
|
|
- order.NozzleNum == request.NozzleId
|
|
|
|
- && order.Ttc.ToString() == request.TransactionNumber
|
|
|
|
- && order.PumpCode == request.FuelItemPumpTotalizerVolume);
|
|
|
|
|
|
+ FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
if (fccOrderInfo == null)
|
|
if (fccOrderInfo == null)
|
|
{
|
|
{
|
|
- logger.Error($"[mqtt paid order notice]:can not find order by clounid:{request.Id}");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- fccOrderInfo.CloundOrderId = request.Id;
|
|
|
|
- fccOrderInfo.AmountPayable = request.ActualPaymentAmount;
|
|
|
|
- fccOrderInfo.PaymentTime = request.TransactionTime;
|
|
|
|
- if(request.PaymentMethod != null)
|
|
|
|
|
|
+ //未找到证明为预支付,这里插入订单
|
|
|
|
+ logger.Info($"[mqtt paid order notice]:can not find order by clounid:{request.Id},is perpay");
|
|
|
|
+ string paymentName = "未知类型";
|
|
|
|
+ if (request.PaymentMethod != null)
|
|
|
|
+ {
|
|
|
|
+ paymentName = stationPayment[request.PaymentMethod ?? 0] ?? "未知类型";
|
|
|
|
+ }
|
|
|
|
+ fccOrderInfo = request.ToComponent(userName,phoneNumber, paymentName);
|
|
|
|
+ mysqlDbContext.Add(fccOrderInfo);
|
|
|
|
+ } else
|
|
{
|
|
{
|
|
- fccOrderInfo.PayType = (int)request.PaymentMethod;
|
|
|
|
- fccOrderInfo.PaymentName = stationPayment[request.PaymentMethod ?? 0] ?? "未知类型";
|
|
|
|
|
|
+ logger.Info($"[mqtt paid order notice]:find order,update order right now");
|
|
|
|
+ //后支付,这里更新支付信息
|
|
|
|
+ fccOrderInfo.AmountPayable = request.ActualPaymentAmount;
|
|
|
|
+ fccOrderInfo.VolumePayable = request.OriginalQty;
|
|
|
|
+ fccOrderInfo.PaymentTime = request.TransactionTime;
|
|
|
|
+ if (request.PaymentMethod != null)
|
|
|
|
+ {
|
|
|
|
+ fccOrderInfo.PayType = (int)request.PaymentMethod;
|
|
|
|
+ fccOrderInfo.PaymentName = stationPayment[request.PaymentMethod ?? 0] ?? "未知类型";
|
|
|
|
+ }
|
|
|
|
+ fccOrderInfo.UserName = userName ?? "";
|
|
|
|
+ fccOrderInfo.PhoneNumber = phoneNumber ?? string.Empty;
|
|
|
|
+ fccOrderInfo.PaymentStatus = 1;
|
|
}
|
|
}
|
|
- fccOrderInfo.UserName = userName??"";
|
|
|
|
- fccOrderInfo.PhoneNumber = phoneNumber ?? string.Empty;
|
|
|
|
- fccOrderInfo.PaymentStatus = 1;
|
|
|
|
|
|
+
|
|
|
|
|
|
mysqlDbContext.SaveChanges();
|
|
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);
|
|
|
|
|
|
+ SendActuallyPaid sendActuallyPaid = new SendActuallyPaid(fccOrderInfo.NozzleNum, fccOrderInfo.Ttc, fccOrderInfo.AmountPayable ?? fccOrderInfo.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);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -904,7 +968,7 @@ namespace HengshanPaymentTerminal
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- public async Task SendAuthorizationAsync(MqttAuthorizationRequest? request)
|
|
|
|
|
|
+ public async Task SendAuthorizationAsync(MqttAuthorizationRequest? request, string? userName, string? phoneNumber)
|
|
{
|
|
{
|
|
MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
if(request == null)
|
|
if(request == null)
|
|
@@ -915,11 +979,16 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
//添加订单到数据库
|
|
//添加订单到数据库
|
|
DateTime authorizationTime = request.AuthorizationTime ?? DateTime.Now;
|
|
DateTime authorizationTime = request.AuthorizationTime ?? DateTime.Now;
|
|
- FccOrderInfo fccOrderInfo = request.ToComponent(authorizationTime);
|
|
|
|
- mysqlDbContext.FccOrderInfos.Add(fccOrderInfo);
|
|
|
|
|
|
+ FccOrderInfo? fccOrderInfo = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.CloundOrderId == request.Id);
|
|
|
|
+ if(fccOrderInfo == null)
|
|
|
|
+ {
|
|
|
|
+ logger.Error($"authorization find order by clound id:{request.Id} is null");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ fccOrderInfo.AuthorizationTime = authorizationTime;
|
|
|
|
|
|
//发送授权申请到油机
|
|
//发送授权申请到油机
|
|
- SendAuthorization sendAuthorization = new SendAuthorization((int)request.NozzleId, authorizationTime, 1,request.OriginalAmount, getFrame(null));
|
|
|
|
|
|
+ SendAuthorization sendAuthorization = new SendAuthorization((int)request.NozzleId, authorizationTime, 1, request.OriginalAmount, getFrame(null));
|
|
byte[] commandAndNozzle = { sendAuthorization.Handle, (byte)sendAuthorization.NozzleNum };
|
|
byte[] commandAndNozzle = { sendAuthorization.Handle, (byte)sendAuthorization.NozzleNum };
|
|
CommonMessage commonMessage = await SendMessageToMaichine("发送授权请求", (request, response) =>
|
|
CommonMessage commonMessage = await SendMessageToMaichine("发送授权请求", (request, response) =>
|
|
{
|
|
{
|
|
@@ -930,6 +999,7 @@ namespace HengshanPaymentTerminal
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}, sendAuthorization);
|
|
}, sendAuthorization);
|
|
|
|
+ logger.Info($"获取到授权结果:{JsonConvert.SerializeObject(commonMessage)}");
|
|
|
|
|
|
//发送授权结果给云端
|
|
//发送授权结果给云端
|
|
string authorizationResultJson = string.Empty;
|
|
string authorizationResultJson = string.Empty;
|
|
@@ -952,6 +1022,7 @@ namespace HengshanPaymentTerminal
|
|
else
|
|
else
|
|
{
|
|
{
|
|
AuthorizationResponse authorization = (AuthorizationResponse)commonMessage;
|
|
AuthorizationResponse authorization = (AuthorizationResponse)commonMessage;
|
|
|
|
+
|
|
if (authorization.Result == 0)
|
|
if (authorization.Result == 0)
|
|
{
|
|
{
|
|
sendAuthorizationResult.OilMachineStatus = OilMachineStatus.Failed;
|
|
sendAuthorizationResult.OilMachineStatus = OilMachineStatus.Failed;
|
|
@@ -960,11 +1031,20 @@ namespace HengshanPaymentTerminal
|
|
{
|
|
{
|
|
sendAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
sendAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
sendAuthorizationResult.TransactionNumber = authorization.Ttc.ToString();
|
|
sendAuthorizationResult.TransactionNumber = authorization.Ttc.ToString();
|
|
- fccOrderInfo.Ttc = authorization.Result;
|
|
|
|
|
|
+ fccOrderInfo.Ttc = authorization.Ttc;
|
|
|
|
+ fccOrderInfo.AuthorizationStatus = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ //SendAuthorizationResult sendAuthorizationResult = new SendAuthorizationResult()
|
|
|
|
+ //{
|
|
|
|
+ // NozzleId = request.NozzleId,
|
|
|
|
+ // TransactionNumber = "1",
|
|
|
|
+ // OilMachineStatus = OilMachineStatus.Success
|
|
|
|
+
|
|
|
|
+ //};
|
|
|
|
+ logger.Info($"发送授权结果:{JsonConvert.SerializeObject(sendAuthorizationResult)}");
|
|
HttpResponseMessage httpResponseMessage = await httpClientUtil.SendAuthorizationResult(JsonConvert.SerializeObject(sendAuthorizationResult));
|
|
HttpResponseMessage httpResponseMessage = await httpClientUtil.SendAuthorizationResult(JsonConvert.SerializeObject(sendAuthorizationResult));
|
|
- logger.Info($"send authorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content)}");
|
|
|
|
|
|
+ logger.Info($"send authorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
|
|
//更新订单
|
|
//更新订单
|
|
mysqlDbContext.SaveChanges();
|
|
mysqlDbContext.SaveChanges();
|
|
@@ -983,29 +1063,28 @@ namespace HengshanPaymentTerminal
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- //从请求信息中获取流水号与授权时间,没有就到数据库查找
|
|
|
|
|
|
+ //先从数据库查找,查看是否已取消授权
|
|
int ttc = 0;
|
|
int ttc = 0;
|
|
DateTime authorizationTime = request.AuthorizationTime ?? DateTime.Now;
|
|
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);
|
|
|
|
+ bool isUnauthorization = false;
|
|
|
|
+ if (fccOrderInfo != null)
|
|
{
|
|
{
|
|
- FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
|
|
- if(fccOrderInfo != null)
|
|
|
|
- {
|
|
|
|
- ttc = fccOrderInfo.Ttc;
|
|
|
|
- authorizationTime = fccOrderInfo.AuthorizationTime;
|
|
|
|
- }
|
|
|
|
|
|
+ ttc = fccOrderInfo.Ttc;
|
|
|
|
+ authorizationTime = fccOrderInfo.AuthorizationTime;
|
|
|
|
+ isUnauthorization = fccOrderInfo.AuthorizationStatus == 0;
|
|
}
|
|
}
|
|
|
|
|
|
SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
sendUnAuthorizationResult.NozzleId = request.NozzleId;
|
|
sendUnAuthorizationResult.NozzleId = request.NozzleId;
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
|
|
|
- if (ttc != 0)
|
|
|
|
|
|
+ if (ttc != 0 && !isUnauthorization)
|
|
{
|
|
{
|
|
SendUnAuthorization sendUnAuthorization = new SendUnAuthorization((int)request.NozzleId, authorizationTime, ttc, getFrame(null));
|
|
SendUnAuthorization sendUnAuthorization = new SendUnAuthorization((int)request.NozzleId, authorizationTime, ttc, getFrame(null));
|
|
byte[] commandAndNozzle = { sendUnAuthorization.Handle, (byte)sendUnAuthorization.NozzleNum };
|
|
byte[] commandAndNozzle = { sendUnAuthorization.Handle, (byte)sendUnAuthorization.NozzleNum };
|
|
|
|
|
|
|
|
+ //发送取消授权命令并获取响应
|
|
CommonMessage commonMessage = await SendMessageToMaichine("发送取消授权请求", (request, response) =>
|
|
CommonMessage commonMessage = await SendMessageToMaichine("发送取消授权请求", (request, response) =>
|
|
{
|
|
{
|
|
if (response.Handle == (byte)CommonMessage.Command.CANCEL_ACCREDIT)
|
|
if (response.Handle == (byte)CommonMessage.Command.CANCEL_ACCREDIT)
|
|
@@ -1015,8 +1094,10 @@ namespace HengshanPaymentTerminal
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}, sendUnAuthorization);
|
|
}, sendUnAuthorization);
|
|
|
|
+
|
|
if (commonMessage.IsError)
|
|
if (commonMessage.IsError)
|
|
{
|
|
{
|
|
|
|
+ //响应错误
|
|
ErrorMessage errorMessage = (ErrorMessage)commonMessage;
|
|
ErrorMessage errorMessage = (ErrorMessage)commonMessage;
|
|
switch (errorMessage.TheErrorType)
|
|
switch (errorMessage.TheErrorType)
|
|
{
|
|
{
|
|
@@ -1030,6 +1111,7 @@ namespace HengshanPaymentTerminal
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
|
|
+ //正常响应
|
|
UnAhorizationResponse unAuthorization = (UnAhorizationResponse)commonMessage;
|
|
UnAhorizationResponse unAuthorization = (UnAhorizationResponse)commonMessage;
|
|
if (unAuthorization.Result == 0)
|
|
if (unAuthorization.Result == 0)
|
|
{
|
|
{
|
|
@@ -1038,18 +1120,25 @@ namespace HengshanPaymentTerminal
|
|
else
|
|
else
|
|
{
|
|
{
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
|
+ fccOrderInfo.AuthorizationStatus = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+ else if (!isUnauthorization)
|
|
{
|
|
{
|
|
|
|
+ //若已经未授权
|
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ { //未找到流水号
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.TransactionNumberNotFound;
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.TransactionNumberNotFound;
|
|
}
|
|
}
|
|
|
|
|
|
HttpResponseMessage httpResponseMessage = await httpClientUtil.SendUnAuthorizationResult(JsonConvert.SerializeObject(sendUnAuthorizationResult));
|
|
HttpResponseMessage httpResponseMessage = await httpClientUtil.SendUnAuthorizationResult(JsonConvert.SerializeObject(sendUnAuthorizationResult));
|
|
- logger.Info($"send Unauthorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content)}");
|
|
|
|
|
|
+ logger.Info($"send Unauthorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 接收到云端发送订单退款信息
|
|
/// 接收到云端发送订单退款信息
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -1069,7 +1158,22 @@ namespace HengshanPaymentTerminal
|
|
Id = request.Id,
|
|
Id = request.Id,
|
|
Result = 1
|
|
Result = 1
|
|
};
|
|
};
|
|
- await httpClientUtil.SendRecieveRefundNotice(JsonConvert.SerializeObject(onGetRefundInfo));
|
|
|
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.SendRecieveRefundNotice(JsonConvert.SerializeObject(onGetRefundInfo));
|
|
|
|
+ logger.Info($"send refund result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //通知油机已退款
|
|
|
|
+ SendRefund sendRefund = new SendRefund((int)request.NozzleId, request.TransactionNumber, request.OriginalAmount, request.ActualPaymentAmount ?? 0m, request.RefundAmount ?? 0m, getFrame(null));
|
|
|
|
+ byte[] commandAndNozzle = { sendRefund.Handle, (byte)sendRefund.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 == sendRefund.NozzleNum;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }, sendRefund);
|
|
|
|
|
|
FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
if (fccOrderInfo == null)
|
|
if (fccOrderInfo == null)
|
|
@@ -1078,7 +1182,9 @@ namespace HengshanPaymentTerminal
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
fccOrderInfo.AmountPayable = request.ActualPaymentAmount;
|
|
fccOrderInfo.AmountPayable = request.ActualPaymentAmount;
|
|
- fccOrderInfo.PaymentStatus = 2;
|
|
|
|
|
|
+ fccOrderInfo.RefundAmount = request.RefundAmount;
|
|
|
|
+ fccOrderInfo.PaymentStatus = (int)request.OrderStatus;
|
|
|
|
+ fccOrderInfo.RefundStatus = (int)request.RefundStatus;
|
|
mysqlDbContext.SaveChanges();
|
|
mysqlDbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
}
|
|
@@ -1112,6 +1218,7 @@ namespace HengshanPaymentTerminal
|
|
private async Task<CommonMessage> SendMessageToMaichine(string sendTag, Func<CommonMessage, CommonMessage, bool> responseCapture,CommonMessage sendMessage)
|
|
private async Task<CommonMessage> SendMessageToMaichine(string sendTag, Func<CommonMessage, CommonMessage, bool> responseCapture,CommonMessage sendMessage)
|
|
{
|
|
{
|
|
logger.Info($"send request to machine:{sendTag}");
|
|
logger.Info($"send request to machine:{sendTag}");
|
|
|
|
+ isSendHeart = false;
|
|
int retryCount = 0;
|
|
int retryCount = 0;
|
|
while (retryCount < 3)
|
|
while (retryCount < 3)
|
|
{
|
|
{
|
|
@@ -1141,6 +1248,7 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
}
|
|
}
|
|
Console.WriteLine("");
|
|
Console.WriteLine("");
|
|
|
|
+ isSendHeart = true;
|
|
//返回信息
|
|
//返回信息
|
|
return (CommonMessage)response.Data;
|
|
return (CommonMessage)response.Data;
|
|
}
|
|
}
|
|
@@ -1154,9 +1262,12 @@ namespace HengshanPaymentTerminal
|
|
if (retryCount >= 3)
|
|
if (retryCount >= 3)
|
|
{
|
|
{
|
|
logger.Info($"{sendTag}: is time out add retry 3 time");
|
|
logger.Info($"{sendTag}: is time out add retry 3 time");
|
|
|
|
+ isSendHeart = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ isSendHeart = true;
|
|
return new ErrorMessage()
|
|
return new ErrorMessage()
|
|
{
|
|
{
|
|
IsError = true,
|
|
IsError = true,
|
|
@@ -1165,167 +1276,74 @@ namespace HengshanPaymentTerminal
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
- ///// <summary>
|
|
|
|
- ///// 发送消息到油机,3秒的超时,重试三次
|
|
|
|
- ///// </summary>
|
|
|
|
- ///// <param name="sendTag">发送的消息类型,用于日志记录</param>
|
|
|
|
- ///// <param name="sendKey">发送的消息key,用于存储 TaskCompletionSource</param>
|
|
|
|
- ///// <param name="requestBytes">实际发送消息</param>
|
|
|
|
- ///// <returns></returns>
|
|
|
|
- //private async Task<CommonMessage> SendMessageToMaichine(string sendTag, string sendKey,CommonMessage sendMessage)
|
|
|
|
- //{
|
|
|
|
- // int retryCount = 0;
|
|
|
|
- // while (retryCount < 3)
|
|
|
|
- // {
|
|
|
|
- // try
|
|
|
|
- // {
|
|
|
|
- // var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3));
|
|
|
|
- // bool isAdd = _tcsDictionary.TryAdd(sendKey, new TaskCompletionSource<CommonMessage>());
|
|
|
|
- // logger.Info($"{sendTag}: add request {sendKey} to dic is {isAdd}");
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 取消授权
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ private async Task SendUnAuthorizationTimerAsync()
|
|
|
|
+ {
|
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
|
+ DateTime timeOut = DateTime.Now.AddMonths(stationInfo.CheckOrderInterval);
|
|
|
|
+ FccOrderInfo? fccOrderInfo = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.AuthorizationStatus == 1 && order.AuthorizationTime < timeOut);
|
|
|
|
|
|
- // Write(sendMessage);
|
|
|
|
|
|
+ if (fccOrderInfo == null)
|
|
|
|
+ {
|
|
|
|
+ logger.Info($"当前没有待取消授权的订单");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
|
|
+ sendUnAuthorizationResult.NozzleId = fccOrderInfo.NozzleNum;
|
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
|
|
|
- // TaskCompletionSource<CommonMessage>? value;
|
|
|
|
- // TaskCompletionSource<CommonMessage> tcs;
|
|
|
|
- // if (_tcsDictionary.TryGetValue(sendKey, out value))
|
|
|
|
- // {
|
|
|
|
- // tcs = value;
|
|
|
|
- // }
|
|
|
|
- // else
|
|
|
|
- // {
|
|
|
|
- // tcs = new TaskCompletionSource<CommonMessage>();
|
|
|
|
- // }
|
|
|
|
- // Task checkOutTime = Task.Delay(Timeout.Infinite, cts.Token);
|
|
|
|
- // var response = await Task.WhenAny(tcs.Task, checkOutTime, checkDisConnectTask.Task);
|
|
|
|
- // //超时重试
|
|
|
|
- // if (response == checkOutTime)
|
|
|
|
- // {
|
|
|
|
- // retryCount++;
|
|
|
|
- // logger.Info($"{sendTag}-{sendKey}: time out,retrying... ({retryCount} / 3)");
|
|
|
|
- // continue;
|
|
|
|
- // }
|
|
|
|
- // //CommonMessage response = await tcs.Task.WaitAsync(cts.Token);
|
|
|
|
- // _tcsDictionary.TryRemove(sendKey, out _);
|
|
|
|
|
|
+ SendUnAuthorization sendUnAuthorization = new SendUnAuthorization(fccOrderInfo.NozzleNum, fccOrderInfo.AuthorizationTime, fccOrderInfo.Ttc, getFrame(null));
|
|
|
|
+ byte[] commandAndNozzle = { sendUnAuthorization.Handle, (byte)sendUnAuthorization.NozzleNum };
|
|
|
|
|
|
- // //链接断开不再发送
|
|
|
|
- // if(response == checkDisConnectTask.Task)
|
|
|
|
- // {
|
|
|
|
- // return new ErrorMessage()
|
|
|
|
- // {
|
|
|
|
- // IsError = true,
|
|
|
|
- // TheErrorType = CommonMessage.ErrorType.DISCONNECT,
|
|
|
|
- // ErrorMessage = $"the client is disconnet"
|
|
|
|
- // };
|
|
|
|
- // }
|
|
|
|
|
|
+ //发送取消授权命令并获取响应
|
|
|
|
+ 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);
|
|
|
|
|
|
- // //返回信息
|
|
|
|
- // return await (Task<CommonMessage>)response;
|
|
|
|
- // }
|
|
|
|
- // catch (Exception)
|
|
|
|
- // {
|
|
|
|
- // retryCount++;
|
|
|
|
- // logger.Info($"{sendTag}-{sendKey}: error,retrying... ({retryCount} / 3)");
|
|
|
|
- // }
|
|
|
|
- // finally
|
|
|
|
- // {
|
|
|
|
- // if (retryCount >= 3)
|
|
|
|
- // {
|
|
|
|
- // logger.Info($"{sendTag}-{sendKey}: is time out add retry 3 time");
|
|
|
|
- // _tcsDictionary.TryRemove(sendKey, out _);
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // return new ErrorMessage()
|
|
|
|
- // {
|
|
|
|
- // IsError = true,
|
|
|
|
- // TheErrorType = CommonMessage.ErrorType.TIMEOUT,
|
|
|
|
- // ErrorMessage = $"{sendTag}: can not receive response after 3 retries"
|
|
|
|
- // };
|
|
|
|
- //}
|
|
|
|
|
|
+ if (commonMessage.IsError)
|
|
|
|
+ {
|
|
|
|
+ //响应错误
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ //正常响应
|
|
|
|
+ UnAhorizationResponse unAuthorization = (UnAhorizationResponse)commonMessage;
|
|
|
|
+ if (unAuthorization.Result == 0)
|
|
|
|
+ {
|
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Failed;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
|
+ fccOrderInfo.AuthorizationStatus = 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- ///// <summary>
|
|
|
|
- ///// 发送消息到油机,3秒的超时,重试三次
|
|
|
|
- ///// </summary>
|
|
|
|
- ///// <param name="sendTag">发送的消息类型,用于日志记录</param>
|
|
|
|
- ///// <param name="sendKey">发送的消息key,用于存储 TaskCompletionSource</param>
|
|
|
|
- ///// <param name="requestBytes">实际发送消息</param>
|
|
|
|
- ///// <returns></returns>
|
|
|
|
- ///// <exception cref="TimeoutException"></exception>
|
|
|
|
- //private async Task<CommonMessage> SendRequestToMachine(string sendTag,string sendKey, byte[] requestBytes)
|
|
|
|
- //{
|
|
|
|
- // int retryCount = 0;
|
|
|
|
- // while(retryCount < 3)
|
|
|
|
- // {
|
|
|
|
- // try
|
|
|
|
- // {
|
|
|
|
- // var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3));
|
|
|
|
- // bool isAdd = _tcsDictionary.TryAdd(sendKey, new TaskCompletionSource<CommonMessage>());
|
|
|
|
- // logger.Info($"{sendTag}: add request {sendKey} to dic is {isAdd}");
|
|
|
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
|
|
|
- // if (client != null)
|
|
|
|
- // {
|
|
|
|
- // client?.Client?.Send(requestBytes);
|
|
|
|
- // } else
|
|
|
|
- // {
|
|
|
|
- // return new ErrorMessage()
|
|
|
|
- // {
|
|
|
|
- // IsError = true,
|
|
|
|
- // TheErrorType = CommonMessage.ErrorType.DISCONNECT,
|
|
|
|
- // ErrorMessage = $"the client is disconnet"
|
|
|
|
- // };
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- // logger.Info($"send request to machine:{BitConverter.ToString(requestBytes).Replace("-", " ")}");
|
|
|
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.SendUnAuthorizationResult(JsonConvert.SerializeObject(sendUnAuthorizationResult));
|
|
|
|
+ logger.Info($"定时任务取消授权:send Unauthorization timer result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
|
|
- // TaskCompletionSource<CommonMessage>? value;
|
|
|
|
- // TaskCompletionSource<CommonMessage> tcs;
|
|
|
|
- // if(_tcsDictionary.TryGetValue(sendKey, out value))
|
|
|
|
- // {
|
|
|
|
- // tcs = value;
|
|
|
|
- // } else
|
|
|
|
- // {
|
|
|
|
- // tcs = new TaskCompletionSource<CommonMessage>();
|
|
|
|
- // }
|
|
|
|
- // Task checkOutTime = Task.Delay(Timeout.Infinite, cts.Token);
|
|
|
|
- // var response = await Task.WhenAny(tcs.Task, checkOutTime, checkDisConnectTask.Task);
|
|
|
|
- // if(response == checkOutTime)
|
|
|
|
- // {
|
|
|
|
- // retryCount++;
|
|
|
|
- // logger.Info($"{sendTag}-{sendKey}: time out,retrying... ({retryCount} / 3)");
|
|
|
|
- // continue;
|
|
|
|
- // }
|
|
|
|
- // //CommonMessage response = await tcs.Task.WaitAsync(cts.Token);
|
|
|
|
- // _tcsDictionary.TryRemove(sendKey, out _);
|
|
|
|
- // if (response == checkDisConnectTask.Task)
|
|
|
|
- // {
|
|
|
|
- // return new ErrorMessage()
|
|
|
|
- // {
|
|
|
|
- // IsError = true,
|
|
|
|
- // TheErrorType = CommonMessage.ErrorType.DISCONNECT,
|
|
|
|
- // ErrorMessage = $"the client is disconnet"
|
|
|
|
- // };
|
|
|
|
- // }
|
|
|
|
- // return await (Task<CommonMessage>)response;
|
|
|
|
- // } catch (Exception)
|
|
|
|
- // {
|
|
|
|
- // retryCount++;
|
|
|
|
- // logger.Info($"{sendTag}-{sendKey}: error,retrying... ({retryCount} / 3)");
|
|
|
|
- // } finally
|
|
|
|
- // {
|
|
|
|
- // if(retryCount >= 3)
|
|
|
|
- // {
|
|
|
|
- // logger.Info($"{sendTag}-{sendKey}: is time out add retry 3 time");
|
|
|
|
- // _tcsDictionary.TryRemove(sendKey,out _);
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- // return new ErrorMessage()
|
|
|
|
- // {
|
|
|
|
- // IsError = true,
|
|
|
|
- // TheErrorType = CommonMessage.ErrorType.TIMEOUT,
|
|
|
|
- // ErrorMessage = $"{sendTag}: can not receive response after 3 retries"
|
|
|
|
- // };
|
|
|
|
- //}
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 添加或修改订单
|
|
/// 添加或修改订单
|
|
@@ -1369,19 +1387,60 @@ namespace HengshanPaymentTerminal
|
|
private async void CreateOrRedeemTransaction(FccOrderInfo fccOrderInfo)
|
|
private async void CreateOrRedeemTransaction(FccOrderInfo fccOrderInfo)
|
|
{
|
|
{
|
|
MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
- CreateTransaction createTransaction = new CreateTransaction(fccOrderInfo);
|
|
|
|
- logger.Info($"create transaction, {JsonConvert.SerializeObject(createTransaction)}");
|
|
|
|
- HttpResponseMessage httpResponseMessage = await httpClientUtil.CreateTransaction(JsonConvert.SerializeObject(createTransaction));
|
|
|
|
-
|
|
|
|
- //var b = httpResponseMessage.Content;
|
|
|
|
- //var a = httpResponseMessage;
|
|
|
|
- string responseStr = await httpResponseMessage.Content.ReadAsStringAsync();
|
|
|
|
- Response<CreateTransactionResponse>? response = JsonConvert.DeserializeObject<Response<CreateTransactionResponse>>(responseStr);
|
|
|
|
- logger.Info($"reveice create transaction response:{JsonConvert.SerializeObject(response)}");
|
|
|
|
|
|
+ if (fccOrderInfo.CloundOrderId == null)
|
|
|
|
+ {
|
|
|
|
+ CreateTransaction createTransaction = new CreateTransaction(fccOrderInfo);
|
|
|
|
+ logger.Info($"create transaction, {JsonConvert.SerializeObject(createTransaction)}");
|
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.CreateTransaction(JsonConvert.SerializeObject(createTransaction));
|
|
|
|
+
|
|
|
|
+ string responseStr = await httpResponseMessage.Content.ReadAsStringAsync();
|
|
|
|
+ Response<CreateTransactionResponse>? response = JsonConvert.DeserializeObject<Response<CreateTransactionResponse>>(responseStr);
|
|
|
|
+ logger.Info($"reveice create transaction response:{JsonConvert.SerializeObject(response)}");
|
|
|
|
+
|
|
|
|
+ fccOrderInfo.CloundOrderId = response?.data?.Id;
|
|
|
|
+ fccOrderInfo.UploadState = response?.data == null ? 0 : 1;
|
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
|
+ } else
|
|
|
|
+ {
|
|
|
|
+ //MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
|
+ if(fccOrderInfo.Amount == 0 && fccOrderInfo.Volume == 0)
|
|
|
|
+ {
|
|
|
|
+ //0交易订单,证明为取消授权后产生的订单,不走核销,而是在小程序上显示为授权失败,让其重新发起授权或退款
|
|
|
|
+ logger.Info("0交易,取消授权");
|
|
|
|
+ fccOrderInfo.AuthorizationStatus = 0; //存在油机手动取消授权的情况,因此这里也要更新授权状态
|
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
|
+
|
|
|
|
+ SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
|
|
+ sendUnAuthorizationResult.NozzleId = fccOrderInfo.NozzleNum;
|
|
|
|
+ sendUnAuthorizationResult.TransactionNumber = fccOrderInfo.Ttc.ToString();
|
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.SendUnAuthorizationResult(JsonConvert.SerializeObject(sendUnAuthorizationResult));
|
|
|
|
+ logger.Info($"手动取消授权:send Unauthorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ //核销
|
|
|
|
+ Redeem redeem = new Redeem();
|
|
|
|
+ redeem.trxId = (int)fccOrderInfo.CloundOrderId;
|
|
|
|
+ redeem.OriginalQty = fccOrderInfo.Volume;
|
|
|
|
+
|
|
|
|
+ string param = JsonConvert.SerializeObject(redeem);
|
|
|
|
+
|
|
|
|
+ logger.Info($"Redeem order:{param}");
|
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.Redeem(param);
|
|
|
|
+
|
|
|
|
+ string responseStr = await httpResponseMessage.Content.ReadAsStringAsync();
|
|
|
|
+ Response<CreateTransactionResponse>? response = JsonConvert.DeserializeObject<Response<CreateTransactionResponse>>(responseStr);
|
|
|
|
+ logger.Info($"Redeem order response:{JsonConvert.SerializeObject(response)}");
|
|
|
|
+
|
|
|
|
+ //fccOrderInfo.CloundOrderId = response?.data?.Id;
|
|
|
|
+ //fccOrderInfo.UploadState = response?.data == null ? 0 : 1;
|
|
|
|
+ //mysqlDbContext.SaveChanges();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //mysqlDbContext.SaveChanges();
|
|
|
|
+ }
|
|
|
|
|
|
- fccOrderInfo.CloundOrderId = response?.data?.Id;
|
|
|
|
- fccOrderInfo.UploadState = response?.data == null ? 0 : 1;
|
|
|
|
- mysqlDbContext.SaveChanges();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -1392,6 +1451,7 @@ namespace HengshanPaymentTerminal
|
|
{
|
|
{
|
|
//提取出状态有变化的油枪,打包成要发送至云端的数据,添加到列表
|
|
//提取出状态有变化的油枪,打包成要发送至云端的数据,添加到列表
|
|
List<SendNozzleStatu> sendNozzleStatus = new List<SendNozzleStatu>();
|
|
List<SendNozzleStatu> sendNozzleStatus = new List<SendNozzleStatu>();
|
|
|
|
+ List<int> fuelingNozzle = new List<int>();
|
|
foreach (var nozzleState in heartBeatMessage.NozzleStatus)
|
|
foreach (var nozzleState in heartBeatMessage.NozzleStatus)
|
|
{
|
|
{
|
|
if (nozzleStatusDic.TryGetValue(nozzleState.NozzleNum, out var value))
|
|
if (nozzleStatusDic.TryGetValue(nozzleState.NozzleNum, out var value))
|
|
@@ -1400,6 +1460,7 @@ namespace HengshanPaymentTerminal
|
|
}
|
|
}
|
|
//保存变量
|
|
//保存变量
|
|
nozzleStatusDic[nozzleState.NozzleNum] = nozzleState.STATU;
|
|
nozzleStatusDic[nozzleState.NozzleNum] = nozzleState.STATU;
|
|
|
|
+ if (nozzleState.STATU == 8) fuelingNozzle.Add(nozzleState.NozzleNum);
|
|
|
|
|
|
//查找fcc数据库油枪id
|
|
//查找fcc数据库油枪id
|
|
DetailsNozzleInfoOutput? detailsNozzleInfoOutput = nozzleInfoList.Find(nozzle => nozzle.NozzleNum == nozzleState.NozzleNum);
|
|
DetailsNozzleInfoOutput? detailsNozzleInfoOutput = nozzleInfoList.Find(nozzle => nozzle.NozzleNum == nozzleState.NozzleNum);
|
|
@@ -1408,24 +1469,41 @@ namespace HengshanPaymentTerminal
|
|
logger.Error($"can not find nozzleInfo from nozzleInfoList:{nozzleState.NozzleNum} ,send nozzle state fail");
|
|
logger.Error($"can not find nozzleInfo from nozzleInfoList:{nozzleState.NozzleNum} ,send nozzle state fail");
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- SendNozzleStatu sendNozzleStatu = new SendNozzleStatu(detailsNozzleInfoOutput.Id, nozzleState);
|
|
|
|
|
|
+ SendNozzleStatu sendNozzleStatu = new SendNozzleStatu(detailsNozzleInfoOutput.CloundNozzleId, nozzleState);
|
|
sendNozzleStatus.Add(sendNozzleStatu);
|
|
sendNozzleStatus.Add(sendNozzleStatu);
|
|
}
|
|
}
|
|
|
|
|
|
- if (sendNozzleStatus.IsNullOrEmpty()) return;
|
|
|
|
-
|
|
|
|
- //发送云端
|
|
|
|
- string reuqestJson = JsonConvert.SerializeObject(sendNozzleStatus);
|
|
|
|
- logger.Info($"send nozzle state to cloud,{reuqestJson}");
|
|
|
|
- try
|
|
|
|
|
|
+
|
|
|
|
+ if (!sendNozzleStatus.IsNullOrEmpty())
|
|
{
|
|
{
|
|
- HttpResponseMessage httpResponseMessage = await httpClientUtil.SendNozzleStatu(reuqestJson);
|
|
|
|
- Response<object>? response = JsonConvert.DeserializeObject<Response<object>>(await httpResponseMessage.Content.ReadAsStringAsync());
|
|
|
|
- logger.Info($"reveice send nozzle state response:{JsonConvert.SerializeObject(response)}");
|
|
|
|
- } catch (Exception ex)
|
|
|
|
|
|
+ //发送云端
|
|
|
|
+ string reuqestJson = JsonConvert.SerializeObject(sendNozzleStatus);
|
|
|
|
+ logger.Info($"send nozzle state to cloud,{reuqestJson}");
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.SendNozzleStatu(reuqestJson);
|
|
|
|
+ Response<object>? response = JsonConvert.DeserializeObject<Response<object>>(await httpResponseMessage.Content.ReadAsStringAsync());
|
|
|
|
+ logger.Info($"reveice send nozzle state response:{JsonConvert.SerializeObject(response)}");
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ logger.Error($"send nozzle stat fail:{ex.Message}");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //当前油枪为加油态,找到该油枪最近一笔已授权的订单,将其赋为加油中
|
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
|
+ foreach(int nozzleNum in fuelingNozzle)
|
|
{
|
|
{
|
|
- logger.Error($"send nozzle stat fail:{ex.Message}");
|
|
|
|
|
|
+ FccOrderInfo? fccOrderInfo = await mysqlDbContext.FccOrderInfos
|
|
|
|
+ .OrderByDescending(order => order.AuthorizationTime)
|
|
|
|
+ .FirstOrDefaultAsync(order => order.NozzleNum == nozzleNum && order.AuthorizationStatus == 1);
|
|
|
|
+ if(fccOrderInfo != null)
|
|
|
|
+ {
|
|
|
|
+ fccOrderInfo.AuthorizationStatus = 3;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|