using Essensoft.AspNetCore.Payment.Alipay; using Essensoft.AspNetCore.Payment.Alipay.Notify; using Essensoft.AspNetCore.Payment.JDPay; using Essensoft.AspNetCore.Payment.JDPay.Notify; using Essensoft.AspNetCore.Payment.LianLianPay; using Essensoft.AspNetCore.Payment.LianLianPay.Notify; using Essensoft.AspNetCore.Payment.QPay; using Essensoft.AspNetCore.Payment.QPay.Notify; using Essensoft.AspNetCore.Payment.UnionPay; using Essensoft.AspNetCore.Payment.UnionPay.Notify; using Essensoft.AspNetCore.Payment.WeChatPay; using Essensoft.AspNetCore.Payment.WeChatPay.Notify; using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; namespace WebApplicationSample.Controllers { [Route("notify/alipay")] public class AlipayNotifyController : Controller { private readonly AlipayNotifyClient _client = null; public AlipayNotifyController(AlipayNotifyClient client) { _client = client; } /// /// 电脑网站支付异步通知 /// /// [Route("pagepay")] [HttpPost] public async Task PagePayAsync() { try { var notify = await _client.ExecuteAsync(Request); if ("TRADE_SUCCESS" == notify.TradeStatus) { Console.WriteLine("OutTradeNo: " + notify.OutTradeNo); return Content("success", "text/plain"); } return NoContent(); } catch { return NoContent(); } } /// /// 手机网站支付异步通知 /// /// [Route("wappay")] [HttpPost] public async Task WapPayAsync() { try { var notify = await _client.ExecuteAsync(Request); if ("TRADE_SUCCESS" == notify.TradeStatus) { Console.WriteLine("OutTradeNo: " + notify.OutTradeNo); return Content("success", "text/plain"); } return NoContent(); } catch { return NoContent(); } } /// /// 扫码支付异步通知 /// /// [Route("precreate")] [HttpPost] public async Task PrecreateAsync() { try { var notify = await _client.ExecuteAsync(Request); if ("TRADE_SUCCESS" == notify.TradeStatus) { Console.WriteLine("OutTradeNo: " + notify.OutTradeNo); return Content("success", "text/plain"); } return NoContent(); } catch { return NoContent(); } } /// /// 条码支付异步通知 /// /// [Route("pay")] [HttpPost] public async Task PayAsync() { try { var notify = await _client.ExecuteAsync(Request); if ("TRADE_SUCCESS" == notify.TradeStatus) { Console.WriteLine("OutTradeNo: " + notify.OutTradeNo); return Content("success", "text/plain"); } return NoContent(); } catch { return NoContent(); } } } [Route("notify/wechatpay")] public class WeChatPayNotifyController : Controller { private readonly WeChatPayNotifyClient _client = null; public WeChatPayNotifyController(WeChatPayNotifyClient client) { _client = client; } [HttpPost] public async Task PostAsync() { try { var notify = await _client.ExecuteAsync(Request); if (notify.ReturnCode == "SUCCESS") { if (notify.ResultCode == "SUCCESS") { Console.WriteLine("OutTradeNo: " + notify.OutTradeNo); return Content("", "text/xml"); } } return NoContent(); } catch { return NoContent(); } } } /// /// 微信支付退款通知 /// [Route("notify/wechatpay/refund")] public class WeChatPayRefundNotifyController : Controller { private readonly WeChatPayNotifyClient _client = null; public WeChatPayRefundNotifyController(WeChatPayNotifyClient client) { _client = client; } [HttpPost] public async Task PostAsync() { try { var notify = await _client.ExecuteAsync(Request); if (notify.ReturnCode == "SUCCESS") { if (notify.RefundStatus == "SUCCESS") { Console.WriteLine("OutTradeNo: " + notify.OutTradeNo); return Content("", "text/xml"); } } return NoContent(); } catch { return NoContent(); } } } [Route("notify/qpay")] public class QPayNotifyController : Controller { private readonly QPayNotifyClient _client = null; public QPayNotifyController(QPayNotifyClient client) { _client = client; } [HttpPost] public async Task PostAsync() { try { var notify = await _client.ExecuteAsync(Request); if ("SUCCESS" == notify.TradeState) { Console.WriteLine("OutTradeNo: " + notify.OutTradeNo); return Content("SUCCESS", "text/xml"); } return NoContent(); } catch { return NoContent(); } } } [Route("notify/jdpay")] public class JDPayNotifyController : Controller { private readonly JDPayNotifyClient _client = null; public JDPayNotifyController(JDPayNotifyClient client) { _client = client; } [HttpPost] public async Task Async() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("TradeNum: " + notify.TradeNum + " tradeType :" + notify.TradeType); return Content("success", "text/plain"); } catch { return NoContent(); } } } [Route("notify/unionpay")] public class UnionPayNotifyController : Controller { private readonly UnionPayNotifyClient _client = null; public UnionPayNotifyController(UnionPayNotifyClient client) { _client = client; } /// /// 二维码支付 - 二维码消费(被扫)通知 /// /// [Route("appconsume")] [HttpPost] public async Task AppConsume() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode); return Content("ok", "text/plain"); } catch { return NoContent(); } } /// /// 二维码支付 - 申请二维码(主扫)通知 /// /// [Route("applyqrcode")] [HttpPost] public async Task ApplyQrCode() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode); return Content("ok", "text/plain"); } catch { return NoContent(); } } /// /// 二维码支付 - 消费撤销通知 /// /// [Route("purchaseundo")] [HttpPost] public async Task PurchaseUndo() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode); return Content("ok", "text/plain"); } catch { return NoContent(); } } /// /// 二维码支付 - 退货通知 /// /// [Route("refund")] [HttpPost] public async Task Refund() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode); return Content("ok", "text/plain"); } catch { return NoContent(); } } /// /// 网关支付 - 跳转网关页面支付通知 /// /// [Route("frontconsume62")] [HttpPost] public async Task FrontConsume62() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode); return Content("ok", "text/plain"); } catch { return NoContent(); } } /// /// 网关支付 - 消费撤销通知 /// /// [Route("consumeundo63")] [HttpPost] public async Task ConsumeUndo63() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode); return Content("ok", "text/plain"); } catch { return NoContent(); } } /// /// 网关支付 - 退货通知 /// /// [Route("refund64")] [HttpPost] public async Task Refund64() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode); return Content("ok", "text/plain"); } catch { return NoContent(); } } /// /// 网关支付 - 预授权通知 /// /// [Route("authdealfront671")] [HttpPost] public async Task AuthDealFront671() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode); return Content("ok", "text/plain"); } catch { return NoContent(); } } /// /// 网关支付 - 预授权撤销通知 /// /// [Route("authundo672")] [HttpPost] public async Task AuthUndo672() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode); return Content("ok", "text/plain"); } catch { return NoContent(); } } /// /// 网关支付 - 预授权完成通知 /// /// [Route("authfinish673")] [HttpPost] public async Task AuthFinish673() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode); return Content("ok", "text/plain"); } catch { return NoContent(); } } /// /// 网关支付 - 预授权完成撤销通知 /// /// [Route("authfinishundo674")] [HttpPost] public async Task AuthFinishUndo674() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode); return Content("ok", "text/plain"); } catch { return NoContent(); } } } [Route("notify/LianLianPay")] public class LianLianPayNotifyController : Controller { private readonly LianLianPayNotifyClient _client = null; public LianLianPayNotifyController(LianLianPayNotifyClient client) { _client = client; } [Route("quickpay")] [HttpPost] public async Task QuickPay() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("NoOrder: " + notify.NoOrder); return Content("{\"ret_code\":\"0000\",\"ret_msg\":\"交易成功\"}", "application/json"); } catch { return NoContent(); } } [Route("bankpay")] [HttpPost] public async Task BankPay() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("NoOrder: " + notify.NoOrder); return Content("{\"ret_code\":\"0000\",\"ret_msg\":\"交易成功\"}", "application/json"); } catch { return NoContent(); } } [Route("authpay")] [HttpPost] public async Task AuthPay() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("NoOrder: " + notify.NoOrder); return Content("{\"ret_code\":\"0000\",\"ret_msg\":\"交易成功\"}", "application/json"); } catch { return NoContent(); } } [Route("refund")] [HttpPost] public async Task Refund() { try { var notify = await _client.ExecuteAsync(Request); Console.WriteLine("NoRefund: " + notify.NoRefund); return Content("{\"ret_code\":\"0000\",\"ret_msg\":\"交易成功\"}", "application/json"); } catch { return NoContent(); } } } }