移动系统liao
2025-02-17 557c2711a3e103ebc3d0492344eca9730d5e92b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/***********************************************************************
 *            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
{
    /// <summary>
    /// 支付宝支付成功后推送到接口进行数据处理
    /// </summary>
    public class AliPayNoticeSubscribe : IRedisSubscribe
    {
        private readonly ICoreCmsBillPaymentsServices _billPaymentsServices;
 
        public AliPayNoticeSubscribe(ICoreCmsBillPaymentsServices billPaymentsServices)
        {
            _billPaymentsServices = billPaymentsServices;
        }
 
        /// <summary>
        /// 支付宝支付成功后推送到接口进行数据处理
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        [Subscribe(RedisMessageQueueKey.AliPayNotice)]
        private async Task AliPayNotice(string msg)
        {
            try
            {
               var notify = JsonConvert.DeserializeObject<AlipayTradeAppPayNotify>(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;
        }
 
    }
}