/***********************************************************************
* Project: baifenBinfa
* ProjectName: 百分兵法管理系统
* Web: http://chuanyin.com
* Author:
* Email:
* CreateTime: 2022/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using System;
using System.Threading.Tasks;
using CoreCms.Net.Configuration;
using CoreCms.Net.IServices;
using CoreCms.Net.Loging;
using Essensoft.Paylink.Alipay;
using Essensoft.Paylink.Alipay.Notify;
using InitQ.Abstractions;
using InitQ.Attributes;
using Newtonsoft.Json;
namespace CoreCms.Net.RedisMQ
{
///
/// 支付宝支付成功后推送到接口进行数据处理
///
public class AliPayNoticeSubscribe : IRedisSubscribe
{
private readonly ICoreCmsBillPaymentsServices _billPaymentsServices;
public AliPayNoticeSubscribe(ICoreCmsBillPaymentsServices billPaymentsServices)
{
_billPaymentsServices = billPaymentsServices;
}
///
/// 支付宝支付成功后推送到接口进行数据处理
///
///
///
[Subscribe(RedisMessageQueueKey.AliPayNotice)]
private async Task AliPayNotice(string msg)
{
try
{
var notify = JsonConvert.DeserializeObject(msg);
if (notify is { TradeStatus: AlipayTradeStatus.Success })
{
if (notify.TradeStatus == AlipayTradeStatus.Success)
{
var money = decimal.Parse(notify.TotalAmount);
await _billPaymentsServices.ToUpdate(notify.OutTradeNo,
(int)GlobalEnumVars.BillPaymentsStatus.Payed,
GlobalEnumVars.PaymentsTypes.alipay.ToString(), money, notify.TradeStatus,notify.TradeNo);
}
else
{
var money = decimal.Parse(notify.TotalAmount);
var message = notify.TradeStatus;
await _billPaymentsServices.ToUpdate(notify.OutTradeNo,
(int)GlobalEnumVars.BillPaymentsStatus.Other,
GlobalEnumVars.PaymentsTypes.alipay.ToString(), money, message, notify.TradeNo);
}
}
NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "支付宝支付成功后推送到接口进行数据处理", msg);
}
catch (Exception ex)
{
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.RedisMessageQueue, "支付宝支付成功后推送到接口进行数据处理", msg, ex);
throw;
}
await Task.CompletedTask;
}
}
}