|
@@ -464,6 +464,7 @@ namespace HengshanPaymentTerminal
|
|
|
{
|
|
|
Task.Run(() => SendUnAuthorizationTimerAsync());
|
|
|
};
|
|
|
+ timer.Start();
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -472,7 +473,6 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
public async Task Process(IContext<byte[], CommonMessage> context)
|
|
|
{
|
|
|
- logger.Info($"获取到信息:{JsonConvert.SerializeObject(context.Incoming.Message)}");
|
|
|
switch (context.Incoming.Message.Handle)
|
|
|
{
|
|
|
//心跳,带油枪状态信息
|
|
@@ -487,7 +487,6 @@ namespace HengshanPaymentTerminal
|
|
|
case 0x18:
|
|
|
{
|
|
|
//添加或修改数据库订单
|
|
|
- logger.Info($"订单信息");
|
|
|
OrderFromMachine orderFromMachine = (OrderFromMachine)context.Incoming.Message;
|
|
|
if(nozzlePumpCode.TryGetValue(orderFromMachine.nozzleNum, out string pumpCodeAndTTC))
|
|
|
{
|
|
@@ -778,33 +777,41 @@ namespace HengshanPaymentTerminal
|
|
|
/// <param name="message"></param>
|
|
|
public async void OnReceiveMqttMessage(string topic,string message)
|
|
|
{
|
|
|
- logger.Info($"getMqtt topic:{topic},and message is {message}");
|
|
|
- MqttRequest? mqttRequest = JsonConvert.DeserializeObject<MqttRequest>(message);
|
|
|
- if (mqttRequest == null)
|
|
|
+ try
|
|
|
{
|
|
|
- logger.Error($"mqtt message turn on object fail,message:{message}");
|
|
|
- return;
|
|
|
- }
|
|
|
- if ($"authorization/{buildID}".Equals(topic))
|
|
|
- {
|
|
|
- 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);
|
|
|
+ logger.Info($"getMqtt topic:{topic},and message is {message}");
|
|
|
+ MqttRequest? mqttRequest = JsonConvert.DeserializeObject<MqttRequest>(message);
|
|
|
+ if (mqttRequest == null)
|
|
|
+ {
|
|
|
+ logger.Error($"mqtt message turn on object fail,message:{message}");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if ($"authorization/{buildID}".Equals(topic))
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
- if ($"refund/{buildID}".Equals(topic))
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- MqttRefundRequest? mqttRefundRequest = JsonConvert.DeserializeObject<MqttRefundRequest>(mqttRequest.data);
|
|
|
- await OnRecieveOrderRefund(mqttRefundRequest);
|
|
|
+ logger.Error($"mqtt have error:{JsonConvert.SerializeObject(ex)}");
|
|
|
}
|
|
|
+
|
|
|
//switch (mqttRequest.type)
|
|
|
//{
|
|
|
// case MQTT_TYPE.AUTHORIZATION:
|
|
@@ -919,18 +926,7 @@ namespace HengshanPaymentTerminal
|
|
|
logger.Info($"send actuallyPaid result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
|
|
FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
|
- if (fccOrderInfo == 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
|
|
|
+ if (fccOrderInfo != null)
|
|
|
{
|
|
|
logger.Info($"[mqtt paid order notice]:find order,update order right now");
|
|
|
//后支付,这里更新支付信息
|
|
@@ -945,22 +941,23 @@ namespace HengshanPaymentTerminal
|
|
|
fccOrderInfo.UserName = userName ?? "";
|
|
|
fccOrderInfo.PhoneNumber = phoneNumber ?? string.Empty;
|
|
|
fccOrderInfo.PaymentStatus = 1;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
- mysqlDbContext.SaveChanges();
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
|
|
|
- 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)
|
|
|
+
|
|
|
+ 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) =>
|
|
|
{
|
|
|
- CommonAnswerBack commonAnswerBack = (CommonAnswerBack)response;
|
|
|
- return commonAnswerBack.Command == (byte)CommonMessage.Command.SEND_NEED_AMOUNT && commonAnswerBack.NozzleNum == sendActuallyPaid.NozzleNum;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }, sendActuallyPaid);
|
|
|
+ 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>
|
|
@@ -978,14 +975,20 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
|
|
|
//添加订单到数据库
|
|
|
+ logger.Info($"[mqtt authorization order notice]:insert order");
|
|
|
DateTime authorizationTime = request.AuthorizationTime ?? DateTime.Now;
|
|
|
- FccOrderInfo? fccOrderInfo = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.CloundOrderId == request.Id);
|
|
|
- if(fccOrderInfo == null)
|
|
|
+ string paymentName = "未知类型";
|
|
|
+ if (request.PaymentMethod != null)
|
|
|
{
|
|
|
- logger.Error($"authorization find order by clound id:{request.Id} is null");
|
|
|
- return;
|
|
|
+ paymentName = stationPayment[request.PaymentMethod ?? 0] ?? "未知类型";
|
|
|
}
|
|
|
- fccOrderInfo.AuthorizationTime = authorizationTime;
|
|
|
+ FccOrderInfo fccOrderInfo = request.ToComponent(authorizationTime, paymentName,userName, phoneNumber);
|
|
|
+ //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));
|
|
@@ -1047,6 +1050,7 @@ namespace HengshanPaymentTerminal
|
|
|
logger.Info($"send authorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
|
|
//更新订单
|
|
|
+ mysqlDbContext.FccOrderInfos.Add(fccOrderInfo);
|
|
|
mysqlDbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
@@ -1078,6 +1082,7 @@ namespace HengshanPaymentTerminal
|
|
|
SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
|
sendUnAuthorizationResult.NozzleId = request.NozzleId;
|
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
+ sendUnAuthorizationResult.TransactionID = request.Id;
|
|
|
|
|
|
if (ttc != 0 && !isUnauthorization)
|
|
|
{
|
|
@@ -1283,8 +1288,7 @@ namespace HengshanPaymentTerminal
|
|
|
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);
|
|
|
+ FccOrderInfo? fccOrderInfo = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.AuthorizationStatus == 1 && order.AuthorizationTime.AddMinutes(stationInfo.CheckOrderInterval) < DateTime.Now);
|
|
|
|
|
|
if (fccOrderInfo == null)
|
|
|
{
|
|
@@ -1293,6 +1297,7 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
|
sendUnAuthorizationResult.NozzleId = fccOrderInfo.NozzleNum;
|
|
|
+ sendUnAuthorizationResult.TransactionID = fccOrderInfo.CloundOrderId;
|
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
|
|
|
SendUnAuthorization sendUnAuthorization = new SendUnAuthorization(fccOrderInfo.NozzleNum, fccOrderInfo.AuthorizationTime, fccOrderInfo.Ttc, getFrame(null));
|
|
@@ -1386,61 +1391,83 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
private async void CreateOrRedeemTransaction(FccOrderInfo fccOrderInfo)
|
|
|
{
|
|
|
- MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
- if (fccOrderInfo.CloundOrderId == null)
|
|
|
+ try
|
|
|
{
|
|
|
- CreateTransaction createTransaction = new CreateTransaction(fccOrderInfo);
|
|
|
- logger.Info($"create transaction, {JsonConvert.SerializeObject(createTransaction)}");
|
|
|
- HttpResponseMessage httpResponseMessage = await httpClientUtil.CreateTransaction(JsonConvert.SerializeObject(createTransaction));
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
+ 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)}");
|
|
|
+ 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())}");
|
|
|
+ FccOrderInfo? order = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.Id == fccOrderInfo.Id);
|
|
|
+ if (order != null)
|
|
|
+ {
|
|
|
+ order.CloundOrderId = response?.data?.Id;
|
|
|
+ order.UploadState = response?.data == null ? 0 : 1;
|
|
|
+ int v = await mysqlDbContext.SaveChangesAsync();
|
|
|
+ logger.Info($"修改行数{v}");
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //核销
|
|
|
- Redeem redeem = new Redeem();
|
|
|
- redeem.trxId = (int)fccOrderInfo.CloundOrderId;
|
|
|
- redeem.OriginalQty = fccOrderInfo.Volume;
|
|
|
+ //MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
+ if (fccOrderInfo.Amount == 0 && fccOrderInfo.Volume == 0)
|
|
|
+ {
|
|
|
+ //0交易订单,证明为取消授权后产生的订单,不走核销,而是在小程序上显示为授权失败,让其重新发起授权或退款
|
|
|
+ logger.Info("0交易,取消授权");
|
|
|
+ FccOrderInfo? order = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.Id == fccOrderInfo.Id);
|
|
|
+ if (order != null)
|
|
|
+ {
|
|
|
+ order.AuthorizationStatus = 0; //存在油机手动取消授权的情况,因此这里也要更新授权状态
|
|
|
+ int v = await mysqlDbContext.SaveChangesAsync();
|
|
|
+ logger.Info($"修改行数{v}");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- string param = JsonConvert.SerializeObject(redeem);
|
|
|
+ SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
|
+ sendUnAuthorizationResult.NozzleId = fccOrderInfo.NozzleNum;
|
|
|
+ sendUnAuthorizationResult.TransactionID = fccOrderInfo.CloundOrderId;
|
|
|
+ sendUnAuthorizationResult.TransactionNumber = fccOrderInfo.Ttc.ToString();
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
+ logger.Info($"0交易,取消授权:{JsonConvert.SerializeObject(sendUnAuthorizationResult)}");
|
|
|
+ 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;
|
|
|
+ redeem.FuelItemPumpTotalizerVolume = fccOrderInfo.PumpCode ?? 0m;
|
|
|
|
|
|
- logger.Info($"Redeem order:{param}");
|
|
|
- HttpResponseMessage httpResponseMessage = await httpClientUtil.Redeem(param);
|
|
|
+ string param = JsonConvert.SerializeObject(redeem);
|
|
|
|
|
|
- string responseStr = await httpResponseMessage.Content.ReadAsStringAsync();
|
|
|
- Response<CreateTransactionResponse>? response = JsonConvert.DeserializeObject<Response<CreateTransactionResponse>>(responseStr);
|
|
|
- logger.Info($"Redeem order response:{JsonConvert.SerializeObject(response)}");
|
|
|
+ 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();
|
|
|
+ }
|
|
|
|
|
|
- //fccOrderInfo.CloundOrderId = response?.data?.Id;
|
|
|
- //fccOrderInfo.UploadState = response?.data == null ? 0 : 1;
|
|
|
//mysqlDbContext.SaveChanges();
|
|
|
}
|
|
|
-
|
|
|
- //mysqlDbContext.SaveChanges();
|
|
|
+ } catch(Exception ex)
|
|
|
+ {
|
|
|
+ logger.Error($"出错:{JsonConvert.SerializeObject(ex)}");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|