李昊 пре 4 година
родитељ
комит
2426c0e862

+ 9 - 14
gx_api/GxPress/Api/GxPress.Api/WebControllers/AlipayController.cs

@@ -30,16 +30,16 @@ namespace GxPress.Api.WebControllers
         public string GetNativePayUrl()
         {
             var alipay = new PcPay();
-            return alipay.PayRequest("637263608658642543_7", "汪峰讲故事", "0.01", "汪峰讲故事","");
+            return alipay.PayRequest("637263608658642543_7", "汪峰讲故事", "0.01", "汪峰讲故事", "");
         }
         /// <summary>
         /// 回调地址
         /// </summary>
-        [HttpGet("notify")]
+        [HttpPost("notify")]
         [AllowAnonymous]
         public async Task Callback()
         {
-            Dictionary<string, string> sArray = GetRequestGet();
+            Dictionary<string, string> sArray = GetRequestPost();
             if (sArray.Count != 0)
             {
                 try
@@ -51,17 +51,12 @@ namespace GxPress.Api.WebControllers
                         //Console.WriteLine($"同步验证通过,订单号:{sArray["out_trade_no"]}");
                         if (await orderService.InsertAliPayOrderAsync(sArray))
                         {
-                            var res = new WxPayData();
-                            res.SetValue("out_trade_no", sArray["out_trade_no"]);
-                            res.SetValue("attach", sArray["out_trade_no"]);
-                            res.SetValue("total_fee", sArray["total_amount"]);
-                            res.SetValue("transaction_id", sArray["trade_no"]);
-                            //创建订单
-                            if (await orderService.InsertWxOrderAsync(res))
-                            {
-                                _context.Response.StatusCode = 200;
-
-                            }
+                            // var res = new WxPayData();
+                            // res.SetValue("out_trade_no", sArray["out_trade_no"]);
+                            // res.SetValue("attach", sArray["out_trade_no"]);
+                            // res.SetValue("total_fee", sArray["total_amount"]);
+                            // res.SetValue("transaction_id", sArray["trade_no"]);
+                            _context.Response.StatusCode = 200;
                         }
                         else
                         {

+ 2 - 4
gx_api/GxPress/Api/GxPress.Api/WebControllers/PayController.cs

@@ -60,7 +60,7 @@ namespace GxPress.Api.WebControllers
 
                 decimal price = 0;
                 var title = string.Empty;
-                var antoNumber = DateTime.Now.Ticks.ToString();
+                var antoNumber =SnowflakeHelper.MakeSnowflake();
                 var attach = antoNumber;
                 if (request.MediaId > 0 || request.VipType > 0)
                 {
@@ -68,9 +68,7 @@ namespace GxPress.Api.WebControllers
                     if (request.MediaId > 0)
                     {
                         var media = await mediaRepository.GetAsync(request.MediaId);
-                        if (media != null)
-                            attach = $"{antoNumber}";
-                        else
+                        if (media == null)
                             throw new BusinessException("服务器异常");
                         price = decimal.Parse("0.01");
                         //创建订单

+ 2 - 2
gx_api/GxPress/Infrastructure/GxPress.Common/AliPay/PcPay.cs

@@ -30,9 +30,9 @@ namespace GxPress.Common.AliPay
 
             AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
             // 设置同步回调地址
-            request.SetReturnUrl("http://payzzz.top/api/web/alipay/notify");
+            request.SetReturnUrl(notifyUrl);
             // 设置异步通知接收地址
-            request.SetNotifyUrl(notifyUrl);
+            request.SetNotifyUrl("http://payzzz.top/api/web/alipay/notify");
             // 将业务model载入到request
             request.SetBizModel(model);
 

+ 1 - 0
gx_api/GxPress/Infrastructure/GxPress.Common/GxPress.Common.csproj

@@ -19,6 +19,7 @@
     <PackageReference Include="LitJson" Version="0.16.0" />
     <PackageReference Include="Alipay.AopSdk.Core" Version="2.5.0.1" />
     <PackageReference Include="VersOne.Epub" Version="3.0.3.1" />
+    <PackageReference Include="Snowflake.Core" Version="2.0.0" />
   </ItemGroup>
 
 </Project>

+ 17 - 0
gx_api/GxPress/Infrastructure/GxPress.Common/Tools/SnowflakeHelper.cs

@@ -0,0 +1,17 @@
+using Snowflake.Core;
+
+namespace GxPress.Common.Tools
+{
+    /// <summary>
+    /// 雪花算法生成不同的ID
+    /// </summary>
+    public static class SnowflakeHelper
+    {
+        public static string MakeSnowflake()
+        {
+            var worker = new IdWorker(1, 1);
+            long id = worker.NextId();
+            return id.ToString();
+        }
+    }
+}

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/Media/MediaRepository.cs

@@ -102,7 +102,7 @@ namespace GxPress.Repository.Implement.Media
             {
                 using (var transactionScope = new TransactionScope())
                 {
-                    model.AutoNumber = DateTime.Now.Ticks.ToString();
+                    model.AutoNumber = SnowflakeHelper.MakeSnowflake();
                     var categoryId = "";
                     foreach (var item in result.CategoryId)
                     {

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Doc/DocService.cs

@@ -58,7 +58,7 @@ namespace GxPress.Service.Implement.Doc
             //流程
             // CreateDocFlowTable(teable, flowDto);
             //保存文档
-            var ticks = DateTime.Now.Ticks.ToString();
+            var ticks = SnowflakeHelper.MakeSnowflake();
             doc.SaveToFile($"wwwroot/cache/doc/{ticks}.docx", FileFormat.Docx2013);
             return $"/cache/doc/{ticks}.docx";
         }

+ 13 - 23
gx_api/GxPress/Service/GxPress.Service.Implement/Order/OrderService.cs

@@ -84,30 +84,20 @@ namespace GxPress.Service.Implement.Order
         /// <returns></returns>
         public async Task<bool> InsertAliPayOrderAsync(Dictionary<string, string> sArray)
         {
-            var order = new Entity.Order.Order();
+
             var attach = sArray["out_trade_no"].ToString();
-            if (attach.Split('_').Length > 0)
-            {
-                //获取medio属性
-                var media = await mediaRepository.GetAsync(attach.Split('_')[0]);
-                //获取用户数据
-                var user = await userRepository.GetAsync(int.Parse(attach.Split('_')[1]));
-                order.OutTradeNo = sArray["out_trade_no"].ToString();
-                order.OrderType = 1;
-                order.IsRefund = false;
-                order.IsSuccess = true;
-                order.IsVip = user.IsVip;
-                order.MediaId = media.Id;
-                order.Explain = media.Title;
-                order.Name = user.Name;
-                order.OrderNumber = DateTime.Now.Ticks.ToString();
-                order.Price = decimal.Parse(sArray["total_amount"].ToString());
-                order.TransactionId = sArray["trade_no"].ToString();
-                order.UserId = user.Id;
-                order.PayWay = 2;
-                return await orderRepository.InsertAsync(order) > 0;
-            }
-            return false;
+            if (attach.Split('_').Length > 1)
+                return true;
+            //获取medio属性
+            var order = await orderRepository.GetOrderAsync(attach.ToString());
+            //获取用户数据
+            var user = await userRepository.GetAsync(order.UserId);
+            order.OutTradeNo = sArray["out_trade_no"].ToString();
+            order.Price = decimal.Parse(sArray["total_amount"].ToString());
+            order.TransactionId = sArray["trade_no"].ToString();
+            order.IsVip = user.IsVip;
+            order.PayWay = 2;
+            return await orderRepository.UpdateAsync(order);
         }
     }
 }