Pārlūkot izejas kodu

[WebApplicationSample] 从 NotifyController 拆分出 AlipayNotifyController、WeChatPayNotifyController、WeChatPayV3NotifyController,从 AlipayController 拆分出 AlipayReturnController。

Roc 5 gadi atpakaļ
vecāks
revīzija
e420b51804
20 mainītis faili ar 200 papildinājumiem un 175 dzēšanām
  1. 1 42
      samples/WebApplicationSample/Controllers/AlipayController.cs
  2. 1 117
      samples/WebApplicationSample/Controllers/AlipayNotifyController.cs
  3. 61 0
      samples/WebApplicationSample/Controllers/AlipayReturnController.cs
  4. 76 0
      samples/WebApplicationSample/Controllers/WeChatPayNotifyController.cs
  5. 2 2
      samples/WebApplicationSample/Controllers/WeChatPayV3Controller.cs
  6. 45 0
      samples/WebApplicationSample/Controllers/WeChatPayV3NotifyController.cs
  7. 2 2
      samples/WebApplicationSample/Views/Alipay/PagePay.cshtml
  8. 2 2
      samples/WebApplicationSample/Views/Alipay/WapPay.cshtml
  9. 0 0
      samples/WebApplicationSample/Views/AlipayReturn/PagePay.cshtml
  10. 0 0
      samples/WebApplicationSample/Views/AlipayReturn/WapPay.cshtml
  11. 1 1
      samples/WebApplicationSample/Views/WeChatPay/AppPay.cshtml
  12. 1 1
      samples/WebApplicationSample/Views/WeChatPay/H5Pay.cshtml
  13. 1 1
      samples/WebApplicationSample/Views/WeChatPay/MiniProgramPay.cshtml
  14. 1 1
      samples/WebApplicationSample/Views/WeChatPay/PubPay.cshtml
  15. 1 1
      samples/WebApplicationSample/Views/WeChatPay/QrCodePay.cshtml
  16. 1 1
      samples/WebApplicationSample/Views/WeChatPay/Refund.cshtml
  17. 1 1
      samples/WebApplicationSample/Views/WeChatPayV3/AppPay.cshtml
  18. 1 1
      samples/WebApplicationSample/Views/WeChatPayV3/H5Pay.cshtml
  19. 1 1
      samples/WebApplicationSample/Views/WeChatPayV3/PubPay.cshtml
  20. 1 1
      samples/WebApplicationSample/Views/WeChatPayV3/QrCodePay.cshtml

+ 1 - 42
samples/WebApplicationSample/Controllers/AlipayController.cs

@@ -2,7 +2,6 @@
 using System.Threading.Tasks;
 using Essensoft.AspNetCore.Payment.Alipay;
 using Essensoft.AspNetCore.Payment.Alipay.Domain;
-using Essensoft.AspNetCore.Payment.Alipay.Notify;
 using Essensoft.AspNetCore.Payment.Alipay.Request;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Options;
@@ -13,13 +12,11 @@ namespace WebApplicationSample.Controllers
     public class AlipayController : Controller
     {
         private readonly IAlipayClient _client;
-        private readonly IAlipayNotifyClient _notifyClient;
         private readonly IOptions<AlipayOptions> _optionsAccessor;
 
-        public AlipayController(IAlipayClient client, IAlipayNotifyClient notifyClient, IOptions<AlipayOptions> optionsAccessor)
+        public AlipayController(IAlipayClient client, IOptions<AlipayOptions> optionsAccessor)
         {
             _client = client;
-            _notifyClient = notifyClient;
             _optionsAccessor = optionsAccessor;
         }
 
@@ -371,43 +368,5 @@ namespace WebApplicationSample.Controllers
             ViewData["response"] = response.Body;
             return View();
         }
-
-        /// <summary>
-        /// 电脑网站支付 - 同步跳转
-        /// </summary>
-        [HttpGet]
-        public async Task<IActionResult> PagePayReturn()
-        {
-            try
-            {
-                var notify = await _notifyClient.ExecuteAsync<AlipayTradePagePayReturn>(Request, _optionsAccessor.Value);
-                ViewData["response"] = "支付成功";
-                return View();
-            }
-            catch
-            {
-                ViewData["response"] = "出现错误";
-                return View();
-            }
-        }
-
-        /// <summary>
-        /// 手机网站支付 - 同步跳转
-        /// </summary>
-        [HttpGet]
-        public async Task<IActionResult> WapPayReturn()
-        {
-            try
-            {
-                var notify = await _notifyClient.ExecuteAsync<AlipayTradeWapPayReturn>(Request, _optionsAccessor.Value);
-                ViewData["response"] = "支付成功";
-                return View();
-            }
-            catch
-            {
-                ViewData["response"] = "出现错误";
-                return View();
-            }
-        }
     }
 }

+ 1 - 117
samples/WebApplicationSample/Controllers/NotifyController.cs → samples/WebApplicationSample/Controllers/AlipayNotifyController.cs

@@ -4,16 +4,12 @@ using System.Xml;
 using Essensoft.AspNetCore.Payment.Alipay;
 using Essensoft.AspNetCore.Payment.Alipay.Notify;
 using Essensoft.AspNetCore.Payment.Alipay.Utility;
-using Essensoft.AspNetCore.Payment.WeChatPay;
-using Essensoft.AspNetCore.Payment.WeChatPay.Notify;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Options;
 
 namespace WebApplicationSample.Controllers
 {
-    #region 支付宝异步通知
-
-    [Route("notify/alipay")]
+    [Route("alipay/notify")]
     public class AlipayNotifyController : Controller
     {
         private readonly IAlipayNotifyClient _client;
@@ -261,116 +257,4 @@ namespace WebApplicationSample.Controllers
             return xmlDoc.InnerXml;
         }
     }
-
-    #endregion
-
-    #region 微信支付异步通知
-
-    [Route("notify/wechatpay")]
-    public class WeChatPayNotifyController : Controller
-    {
-        private readonly IWeChatPayNotifyClient _client;
-        private readonly IOptions<WeChatPayOptions> _optionsAccessor;
-
-        public WeChatPayNotifyController(IWeChatPayNotifyClient client, IOptions<WeChatPayOptions> optionsAccessor)
-        {
-            _client = client;
-            _optionsAccessor = optionsAccessor;
-        }
-
-        /// <summary>
-        /// 统一下单支付结果通知
-        /// </summary>
-        [Route("unifiedorder")]
-        [HttpPost]
-        public async Task<IActionResult> Unifiedorder()
-        {
-            try
-            {
-                var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotify>(Request, _optionsAccessor.Value);
-                if (notify.ReturnCode == WeChatPayCode.Success)
-                {
-                    if (notify.ResultCode == WeChatPayCode.Success)
-                    {
-                        Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
-
-                        return WeChatPayNotifyResult.Success;
-                    }
-                }
-                return NoContent();
-            }
-            catch
-            {
-                return NoContent();
-            }
-        }
-
-        /// <summary>
-        /// 退款结果通知
-        /// </summary>
-        [Route("refund")]
-        [HttpPost]
-        public async Task<IActionResult> Refund()
-        {
-            try
-            {
-                var notify = await _client.ExecuteAsync<WeChatPayRefundNotify>(Request, _optionsAccessor.Value);
-                if (notify.ReturnCode == WeChatPayCode.Success)
-                {
-                    if (notify.RefundStatus == WeChatPayCode.Success)
-                    {
-                        Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
-                        return WeChatPayNotifyResult.Success;
-                    }
-                }
-                return NoContent();
-            }
-            catch
-            {
-                return NoContent();
-            }
-        }
-    }
-
-    #endregion
-
-    #region 微信支付V3异步通知
-
-    [Route("notify/wechatpay/v3")]
-    public class WeChatPayV3NotifyController : Controller
-    {
-        private readonly IWeChatPayV3NotifyClient _client;
-        private readonly IOptions<WeChatPayOptions> _optionsAccessor;
-
-        public WeChatPayV3NotifyController(IWeChatPayV3NotifyClient client, IOptions<WeChatPayOptions> optionsAccessor)
-        {
-            _client = client;
-            _optionsAccessor = optionsAccessor;
-        }
-
-        /// <summary>
-        /// 支付结果通知
-        /// </summary>
-        [Route("transactions")]
-        [HttpPost]
-        public async Task<IActionResult> Transactions()
-        {
-            try
-            {
-                var notify = await _client.ExecuteAsync<WeChatPayTransactionsNotify>(Request, _optionsAccessor.Value);
-                if (notify.TradeState == WeChatPayTradeState.Success)
-                {
-                    Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
-                    return WeChatPayV3NotifyResult.Success;
-                }
-                return NoContent();
-            }
-            catch
-            {
-                return NoContent();
-            }
-        }
-    }
-
-    #endregion
 }

+ 61 - 0
samples/WebApplicationSample/Controllers/AlipayReturnController.cs

@@ -0,0 +1,61 @@
+using System.Threading.Tasks;
+using Essensoft.AspNetCore.Payment.Alipay;
+using Essensoft.AspNetCore.Payment.Alipay.Notify;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+
+namespace WebApplicationSample.Controllers
+{
+    [Route("alipay/return")]
+    public class AlipayReturnController : Controller
+    {
+        private readonly IAlipayNotifyClient _client;
+        private readonly IOptions<AlipayOptions> _optionsAccessor;
+
+        public AlipayReturnController(IAlipayNotifyClient client, IOptions<AlipayOptions> optionsAccessor)
+        {
+            _client = client;
+            _optionsAccessor = optionsAccessor;
+        }
+
+        /// <summary>
+        /// 电脑网站支付 - 同步跳转
+        /// </summary>
+        [Route("pagepay")]
+        [HttpGet]
+        public async Task<IActionResult> PagePay()
+        {
+            try
+            {
+                var notify = await _client.ExecuteAsync<AlipayTradePagePayReturn>(Request, _optionsAccessor.Value);
+                ViewData["response"] = "支付成功";
+                return View();
+            }
+            catch
+            {
+                ViewData["response"] = "出现错误";
+                return View();
+            }
+        }
+
+        /// <summary>
+        /// 手机网站支付 - 同步跳转
+        /// </summary>
+        [HttpGet]
+        [Route("wappay")]
+        public async Task<IActionResult> WapPay()
+        {
+            try
+            {
+                var notify = await _client.ExecuteAsync<AlipayTradeWapPayReturn>(Request, _optionsAccessor.Value);
+                ViewData["response"] = "支付成功";
+                return View();
+            }
+            catch
+            {
+                ViewData["response"] = "出现错误";
+                return View();
+            }
+        }
+    }
+}

+ 76 - 0
samples/WebApplicationSample/Controllers/WeChatPayNotifyController.cs

@@ -0,0 +1,76 @@
+using System;
+using System.Threading.Tasks;
+using Essensoft.AspNetCore.Payment.WeChatPay;
+using Essensoft.AspNetCore.Payment.WeChatPay.Notify;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+
+namespace WebApplicationSample.Controllers
+{
+    [Route("wechatpay/notify")]
+    public class WeChatPayNotifyController : Controller
+    {
+        private readonly IWeChatPayNotifyClient _client;
+        private readonly IOptions<WeChatPayOptions> _optionsAccessor;
+
+        public WeChatPayNotifyController(IWeChatPayNotifyClient client, IOptions<WeChatPayOptions> optionsAccessor)
+        {
+            _client = client;
+            _optionsAccessor = optionsAccessor;
+        }
+
+        /// <summary>
+        /// 统一下单支付结果通知
+        /// </summary>
+        [Route("unifiedorder")]
+        [HttpPost]
+        public async Task<IActionResult> Unifiedorder()
+        {
+            try
+            {
+                var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotify>(Request, _optionsAccessor.Value);
+                if (notify.ReturnCode == WeChatPayCode.Success)
+                {
+                    if (notify.ResultCode == WeChatPayCode.Success)
+                    {
+                        Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
+
+                        return WeChatPayNotifyResult.Success;
+                    }
+                }
+                return NoContent();
+            }
+            catch
+            {
+                return NoContent();
+            }
+        }
+
+        /// <summary>
+        /// 退款结果通知
+        /// </summary>
+        [Route("refund")]
+        [HttpPost]
+        public async Task<IActionResult> Refund()
+        {
+            try
+            {
+                var notify = await _client.ExecuteAsync<WeChatPayRefundNotify>(Request, _optionsAccessor.Value);
+                if (notify.ReturnCode == WeChatPayCode.Success)
+                {
+                    if (notify.RefundStatus == WeChatPayCode.Success)
+                    {
+                        Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
+                        return WeChatPayNotifyResult.Success;
+                    }
+                }
+                return NoContent();
+            }
+            catch
+            {
+                return NoContent();
+            }
+        }
+    }
+
+}

+ 2 - 2
samples/WebApplicationSample/Controllers/WeChatPayV3Controller.cs

@@ -240,7 +240,7 @@ namespace WebApplicationSample.Controllers
         public async Task<IActionResult> QueryByTransactionId(WeChatPayQueryByTransactionIdViewModel viewModel)
         {
             var request = new WeChatPayTransactionsIdRequest
-            { 
+            {
                 TransactionId = viewModel.TransactionId,
                 MchId = _optionsAccessor.Value.MchId,
             };
@@ -366,7 +366,7 @@ namespace WebApplicationSample.Controllers
             ViewData["response"] = response.Body;
             return View();
         }
-        
+
         /// <summary>
         /// 下载账单
         /// </summary>

+ 45 - 0
samples/WebApplicationSample/Controllers/WeChatPayV3NotifyController.cs

@@ -0,0 +1,45 @@
+using System;
+using System.Threading.Tasks;
+using Essensoft.AspNetCore.Payment.WeChatPay;
+using Essensoft.AspNetCore.Payment.WeChatPay.Notify;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+
+namespace WebApplicationSample.Controllers
+{
+    [Route("wechatpay/v3/notify")]
+    public class WeChatPayV3NotifyController : Controller
+    {
+        private readonly IWeChatPayV3NotifyClient _client;
+        private readonly IOptions<WeChatPayOptions> _optionsAccessor;
+
+        public WeChatPayV3NotifyController(IWeChatPayV3NotifyClient client, IOptions<WeChatPayOptions> optionsAccessor)
+        {
+            _client = client;
+            _optionsAccessor = optionsAccessor;
+        }
+
+        /// <summary>
+        /// 支付结果通知
+        /// </summary>
+        [Route("transactions")]
+        [HttpPost]
+        public async Task<IActionResult> Transactions()
+        {
+            try
+            {
+                var notify = await _client.ExecuteAsync<WeChatPayTransactionsNotify>(Request, _optionsAccessor.Value);
+                if (notify.TradeState == WeChatPayTradeState.Success)
+                {
+                    Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
+                    return WeChatPayV3NotifyResult.Success;
+                }
+                return NoContent();
+            }
+            catch
+            {
+                return NoContent();
+            }
+        }
+    }
+}

+ 2 - 2
samples/WebApplicationSample/Views/Alipay/PagePay.cshtml

@@ -35,11 +35,11 @@
             </div>
             <div class="form-group">
                 <label asp-for="ReturnUrl"></label>
-                <input type="text" class="form-control" asp-for="ReturnUrl" value="http://*/alipay/pagepayreturn" />
+                <input type="text" class="form-control" asp-for="ReturnUrl" value="http://*/alipay/return/pagepay" />
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/notify/alipay/pagepay" />
+                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/alipay/notify/pagepay" />
             </div>
             <button type="submit" class="btn btn-primary">提交请求</button>
         </form>

+ 2 - 2
samples/WebApplicationSample/Views/Alipay/WapPay.cshtml

@@ -35,11 +35,11 @@
             </div>
             <div class="form-group">
                 <label asp-for="ReturnUrl"></label>
-                <input type="text" class="form-control" asp-for="ReturnUrl" value="http://*/alipay/wappayreturn" />
+                <input type="text" class="form-control" asp-for="ReturnUrl" value="http://*/alipay/return/wappay" />
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/notify/alipay/wappay" />
+                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/alipay/notify/wappay" />
             </div>
             <button type="submit" class="btn btn-primary">提交请求</button>
         </form>

+ 0 - 0
samples/WebApplicationSample/Views/Alipay/PagePayReturn.cshtml → samples/WebApplicationSample/Views/AlipayReturn/PagePay.cshtml


+ 0 - 0
samples/WebApplicationSample/Views/Alipay/WapPayReturn.cshtml → samples/WebApplicationSample/Views/AlipayReturn/WapPay.cshtml


+ 1 - 1
samples/WebApplicationSample/Views/WeChatPay/AppPay.cshtml

@@ -31,7 +31,7 @@
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/notify/wechatpay/unifiedorder" />
+                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/wechatpay/notify/unifiedorder" />
             </div>
             <div class="form-group">
                 <label asp-for="TradeType"></label>

+ 1 - 1
samples/WebApplicationSample/Views/WeChatPay/H5Pay.cshtml

@@ -31,7 +31,7 @@
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/notify/wechatpay/unifiedorder" />
+                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/wechatpay/notify/unifiedorder" />
             </div>
             <div class="form-group">
                 <label asp-for="TradeType"></label>

+ 1 - 1
samples/WebApplicationSample/Views/WeChatPay/MiniProgramPay.cshtml

@@ -31,7 +31,7 @@
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/notify/wechatpay/unifiedorder" />
+                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/wechatpay/notify/unifiedorder" />
             </div>
             <div class="form-group">
                 <label asp-for="TradeType"></label>

+ 1 - 1
samples/WebApplicationSample/Views/WeChatPay/PubPay.cshtml

@@ -31,7 +31,7 @@
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/notify/wechatpay/unifiedorder" />
+                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/wechatpay/notify/unifiedorder" />
             </div>
             <div class="form-group">
                 <label asp-for="TradeType"></label>

+ 1 - 1
samples/WebApplicationSample/Views/WeChatPay/QrCodePay.cshtml

@@ -31,7 +31,7 @@
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/notify/wechatpay/unifiedorder">
+                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/wechatpay/notify/unifiedorder">
             </div>
             <div class="form-group">
                 <label asp-for="TradeType"></label>

+ 1 - 1
samples/WebApplicationSample/Views/WeChatPay/Refund.cshtml

@@ -39,7 +39,7 @@
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/notify/wechatpay/refund">
+                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/wechatpay/notify/refund">
             </div>
             <button type="submit" class="btn btn-primary">提交请求</button>
         </form>

+ 1 - 1
samples/WebApplicationSample/Views/WeChatPayV3/AppPay.cshtml

@@ -27,7 +27,7 @@
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/notify/wechatpay/v3/transactions" />
+                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/wechatpay/v3/notify/transactions" />
             </div>
             <button type="submit" class="btn btn-primary">提交请求</button>
         </form>

+ 1 - 1
samples/WebApplicationSample/Views/WeChatPayV3/H5Pay.cshtml

@@ -27,7 +27,7 @@
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/notify/wechatpay/v3/transactions">
+                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/wechatpay/v3/notify/transactions">
             </div>
             <button type="submit" class="btn btn-primary">提交请求</button>
         </form>

+ 1 - 1
samples/WebApplicationSample/Views/WeChatPayV3/PubPay.cshtml

@@ -27,7 +27,7 @@
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/notify/wechatpay/v3/transactions">
+                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/wechatpay/v3/notify/transactions">
             </div>
             <div class="form-group">
                 <label asp-for="OpenId"></label>

+ 1 - 1
samples/WebApplicationSample/Views/WeChatPayV3/QrCodePay.cshtml

@@ -27,7 +27,7 @@
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/notify/wechatpay/v3/transactions">
+                <input type="text" class="form-control" asp-for="NotifyUrl" value="http://*/wechatpay/v3/notify/transactions">
             </div>
             <button type="submit" class="btn btn-primary">提交请求</button>
         </form>