Browse Source

支付记录调整

warr.qian 2 years ago
parent
commit
5e48b02581
2 changed files with 21 additions and 16 deletions
  1. 10 10
      Common/AlipayCommon.cs
  2. 11 6
      Service/PaymentService.cs

+ 10 - 10
Common/AlipayCommon.cs

@@ -1,3 +1,4 @@
+using System.Text;
 using System.Net.Cache;
 using System.Security.Cryptography.X509Certificates;
 using System;
@@ -9,6 +10,7 @@ using Newtonsoft.Json;
 using Aop.Api.Domain;
 using System.Collections.Generic;
 using WingServerCommon.Log;
+using WingServerCommon.Utilities;
 
 namespace WingPaymentService.Common
 {
@@ -33,9 +35,9 @@ namespace WingPaymentService.Common
         /// </summary>
         /// <param name="subject"></param>
         /// <param name="totalAmount"></param>
-        /// <param name="orderCode"></param>
+        /// <param name="recordCode"></param>
         /// <returns></returns>
-        public (string, string) AlipayPagePay(string subject, double totalAmount, string orderCode, string recordCode)
+        public (string, string) AlipayPagePay(string subject, double totalAmount, string recordCode)
         {
             try
             {
@@ -45,9 +47,8 @@ namespace WingPaymentService.Common
                 {
                     Subject = subject,
                     TotalAmount = totalAmount.ToString("0.00"),
-                    OutTradeNo = orderCode,
-                    ProductCode = "QUICK_WAP_WAY",
-                    StoreId = recordCode
+                    OutTradeNo = recordCode,
+                    ProductCode = "QUICK_WAP_WAY"
                 };
                 // 1. 创建IAopClient实例
                 IAopClient client = new DefaultAopClient
@@ -92,9 +93,9 @@ namespace WingPaymentService.Common
         /// </summary>
         /// <param name="subject"></param>
         /// <param name="totalAmount"></param>
-        /// <param name="orderCode"></param>
+        /// <param name="recordCode"></param>
         /// <returns></returns>
-        public (string, string) AlipayWapPay(string subject, double totalAmount, string orderCode, string recordCode)
+        public (string, string) AlipayWapPay(string subject, double totalAmount, string recordCode)
         {
             try
             {
@@ -104,9 +105,8 @@ namespace WingPaymentService.Common
                 {
                     Subject = subject,
                     TotalAmount = totalAmount.ToString("0.00"),
-                    OutTradeNo = orderCode,
-                    ProductCode = "QUICK_WAP_WAY",
-                    StoreId = recordCode
+                    OutTradeNo = recordCode,
+                    ProductCode = "QUICK_WAP_WAY"
                 };
                 // 1. 创建IAopClient实例
                 IAopClient client = new DefaultAopClient

+ 11 - 6
Service/PaymentService.cs

@@ -1,3 +1,5 @@
+using System.Collections.Concurrent;
+using System.Text;
 using System;
 using System.Web;
 using WingServerCommon.Service;
@@ -25,6 +27,7 @@ namespace WingPaymentService.Service
         private IPaymentDBService _paymentDBService;
         private AlipayCommon _alipayCommon;
         private WeChatCommon _weChatCommon;
+        private ConcurrentDictionary<string, string> _recordRelation = new();
         public override void Load(JsonRpcClientPool jsonRpcClientPool)
         {
             _alipayCommon = new AlipayCommon();
@@ -99,14 +102,16 @@ namespace WingPaymentService.Service
                 if (orderInfo != null && orderInfo.OrderAmount > 0)
                 {
                     string recordCode = Guid.NewGuid().ToString("N");
-                    (string payUrl, string recordContent) payContent = (string.Empty,string.Empty);
+                    (string payUrl, string recordContent) payContent = (string.Empty, string.Empty);
                     switch (request.PayType)
                     {
                         case PayTypeEnum.Alipay_PAGE:
-                            payContent = _alipayCommon.AlipayPagePay(orderInfo.OrderTitle, orderInfo.OrderAmount, orderInfo.Code, recordCode);
+                            _recordRelation.AddOrUpdate(recordCode, request.OrderCode, (a,b)=> { return request.OrderCode; });
+                            payContent = _alipayCommon.AlipayPagePay(orderInfo.OrderTitle, orderInfo.OrderAmount, recordCode);
                             break;
                         case PayTypeEnum.Alipay_WAP:
-                            payContent = _alipayCommon.AlipayWapPay(orderInfo.OrderTitle, orderInfo.OrderAmount, orderInfo.Code, recordCode);
+                            _recordRelation.AddOrUpdate(recordCode, request.OrderCode, (a,b)=> { return request.OrderCode; });
+                            payContent = _alipayCommon.AlipayWapPay(orderInfo.OrderTitle, orderInfo.OrderAmount, recordCode);
                             break;
                         case PayTypeEnum.WeChat_PAGE:
                             payContent = await _weChatCommon.GetWebPayUrlAsync(orderInfo.OrderTitle, orderInfo.OrderAmount, orderInfo.Code, recordCode, string.Empty, string.Empty);
@@ -183,12 +188,12 @@ namespace WingPaymentService.Service
                     keyValuePairs.Add(key, value);
                 }
             }
-            var payOutTradeNo = keyValuePairs.GetValueOrDefault("out_trade_no");
+            var recordCode = keyValuePairs.GetValueOrDefault("out_trade_no");
+            _recordRelation.TryGetValue(recordCode, out string orderCode);
             var totalAmount = keyValuePairs.GetValueOrDefault("total_amount");
-            var payRecordCode = keyValuePairs.GetValueOrDefault("pay_record_code");
             var payStatus = keyValuePairs.GetValueOrDefault("trade_status") == "TRADE_SUCCESS" ? WingInterfaceLibrary.Enum.PayStatusEnum.Paid : WingInterfaceLibrary.Enum.PayStatusEnum.NoPay;
             var payTime = DateTime.UtcNow;
-            return await PayRecordWriteRes(payOutTradeNo, payRecordCode, totalAmount, payStatus, payTime, request);
+            return await PayRecordWriteRes(orderCode, recordCode, totalAmount, payStatus, payTime, request);
         }
 
         /// <summary>