123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557 |
- 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;
- }
- /// <summary>
- /// 电脑网站支付异步通知
- /// </summary>
- /// <returns></returns>
- [Route("pagepay")]
- [HttpPost]
- public async Task<IActionResult> PagePayAsync()
- {
- try
- {
- var notify = await _client.ExecuteAsync<AlipayTradePagePayNotifyResponse>(Request);
- if ("TRADE_SUCCESS" == notify.TradeStatus)
- {
- Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
- return Content("success", "text/plain");
- }
- return NoContent();
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 手机网站支付异步通知
- /// </summary>
- /// <returns></returns>
- [Route("wappay")]
- [HttpPost]
- public async Task<IActionResult> WapPayAsync()
- {
- try
- {
- var notify = await _client.ExecuteAsync<AlipayTradeWapPayNotifyResponse>(Request);
- if ("TRADE_SUCCESS" == notify.TradeStatus)
- {
- Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
- return Content("success", "text/plain");
- }
- return NoContent();
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 扫码支付异步通知
- /// </summary>
- /// <returns></returns>
- [Route("precreate")]
- [HttpPost]
- public async Task<IActionResult> PrecreateAsync()
- {
- try
- {
- var notify = await _client.ExecuteAsync<AlipayTradePrecreateNotifyResponse>(Request);
- if ("TRADE_SUCCESS" == notify.TradeStatus)
- {
- Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
- return Content("success", "text/plain");
- }
- return NoContent();
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 条码支付异步通知
- /// </summary>
- /// <returns></returns>
- [Route("pay")]
- [HttpPost]
- public async Task<IActionResult> PayAsync()
- {
- try
- {
- var notify = await _client.ExecuteAsync<AlipayTradePayNotifyResponse>(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<IActionResult> PostAsync()
- {
- try
- {
- var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotifyResponse>(Request);
- if (notify.ReturnCode == "SUCCESS")
- {
- if (notify.ResultCode == "SUCCESS")
- {
- Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
- return Content("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>", "text/xml");
- }
- }
- return NoContent();
- }
- catch
- {
- return NoContent();
- }
- }
- }
- /// <summary>
- /// 微信支付退款通知
- /// </summary>
- [Route("notify/wechatpay/refund")]
- public class WeChatPayRefundNotifyController : Controller
- {
- private readonly WeChatPayNotifyClient _client = null;
- public WeChatPayRefundNotifyController(WeChatPayNotifyClient client)
- {
- _client = client;
- }
- [HttpPost]
- public async Task<IActionResult> PostAsync()
- {
- try
- {
- var notify = await _client.ExecuteAsync<WeChatPayRefundNotifyResponse>(Request);
- if (notify.ReturnCode == "SUCCESS")
- {
- if (notify.RefundStatus == "SUCCESS")
- {
- Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
- return Content("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>", "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<IActionResult> PostAsync()
- {
- try
- {
- var notify = await _client.ExecuteAsync<QPayUnifiedOrderNotifyResponse>(Request);
- if ("SUCCESS" == notify.TradeState)
- {
- Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
- return Content("<xml><return_code>SUCCESS</return_code></xml>", "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<IActionResult> Async()
- {
- try
- {
- var notify = await _client.ExecuteAsync<JDPayAsyncNotifyResponse>(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;
- }
- /// <summary>
- /// 二维码支付 - 二维码消费(被扫)通知
- /// </summary>
- /// <returns></returns>
- [Route("appconsume")]
- [HttpPost]
- public async Task<IActionResult> AppConsume()
- {
- try
- {
- var notify = await _client.ExecuteAsync<UnionPayForm05_6_2_AppConsumeNotifyResponse>(Request);
- Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
- return Content("ok", "text/plain");
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 二维码支付 - 申请二维码(主扫)通知
- /// </summary>
- /// <returns></returns>
- [Route("applyqrcode")]
- [HttpPost]
- public async Task<IActionResult> ApplyQrCode()
- {
- try
- {
- var notify = await _client.ExecuteAsync<UnionPayForm05_6_1_ApplyQrCodeNotifyResponse>(Request);
- Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
- return Content("ok", "text/plain");
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 二维码支付 - 消费撤销通知
- /// </summary>
- /// <returns></returns>
- [Route("purchaseundo")]
- [HttpPost]
- public async Task<IActionResult> PurchaseUndo()
- {
- try
- {
- var notify = await _client.ExecuteAsync<UnionPayUpacpPurchaseUndoNotifyResponse>(Request);
- Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
- return Content("ok", "text/plain");
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 二维码支付 - 退货通知
- /// </summary>
- /// <returns></returns>
- [Route("refund")]
- [HttpPost]
- public async Task<IActionResult> Refund()
- {
- try
- {
- var notify = await _client.ExecuteAsync<UnionPayUpacpRefundNotifyResponse>(Request);
- Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
- return Content("ok", "text/plain");
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 网关支付 - 跳转网关页面支付通知
- /// </summary>
- /// <returns></returns>
- [Route("frontconsume62")]
- [HttpPost]
- public async Task<IActionResult> FrontConsume62()
- {
- try
- {
- var notify = await _client.ExecuteAsync<UnionPayForm_6_2_FrontConsumeNotifyResponse>(Request);
- Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
- return Content("ok", "text/plain");
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 网关支付 - 消费撤销通知
- /// </summary>
- /// <returns></returns>
- [Route("consumeundo63")]
- [HttpPost]
- public async Task<IActionResult> ConsumeUndo63()
- {
- try
- {
- var notify = await _client.ExecuteAsync<UnionPayForm_6_3_ConsumeUndoNotifyResponse>(Request);
- Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
- return Content("ok", "text/plain");
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 网关支付 - 退货通知
- /// </summary>
- /// <returns></returns>
- [Route("refund64")]
- [HttpPost]
- public async Task<IActionResult> Refund64()
- {
- try
- {
- var notify = await _client.ExecuteAsync<UnionPayForm_6_4_RefundNotifyResponse>(Request);
- Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
- return Content("ok", "text/plain");
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 网关支付 - 预授权通知
- /// </summary>
- /// <returns></returns>
- [Route("authdealfront671")]
- [HttpPost]
- public async Task<IActionResult> AuthDealFront671()
- {
- try
- {
- var notify = await _client.ExecuteAsync<UnionPayForm_6_7_1_AuthDeal_FrontNotifyResponse>(Request);
- Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
- return Content("ok", "text/plain");
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 网关支付 - 预授权撤销通知
- /// </summary>
- /// <returns></returns>
- [Route("authundo672")]
- [HttpPost]
- public async Task<IActionResult> AuthUndo672()
- {
- try
- {
- var notify = await _client.ExecuteAsync<UnionPayForm_6_7_2_AuthUndoNotifyResponse>(Request);
- Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
- return Content("ok", "text/plain");
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 网关支付 - 预授权完成通知
- /// </summary>
- /// <returns></returns>
- [Route("authfinish673")]
- [HttpPost]
- public async Task<IActionResult> AuthFinish673()
- {
- try
- {
- var notify = await _client.ExecuteAsync<UnionPayForm_6_7_3_AuthFinishNotifyResponse>(Request);
- Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
- return Content("ok", "text/plain");
- }
- catch
- {
- return NoContent();
- }
- }
- /// <summary>
- /// 网关支付 - 预授权完成撤销通知
- /// </summary>
- /// <returns></returns>
- [Route("authfinishundo674")]
- [HttpPost]
- public async Task<IActionResult> AuthFinishUndo674()
- {
- try
- {
- var notify = await _client.ExecuteAsync<UnionPayForm_6_7_4_AuthFinishUndoNotifyResponse>(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<IActionResult> QuickPay()
- {
- try
- {
- var notify = await _client.ExecuteAsync<LianLianPayWebQuickPayNotifyResponse>(Request);
- Console.WriteLine("NoOrder: " + notify.NoOrder);
- return Content("{\"ret_code\":\"0000\",\"ret_msg\":\"交易成功\"}", "application/json");
- }
- catch
- {
- return NoContent();
- }
- }
- [Route("bankpay")]
- [HttpPost]
- public async Task<IActionResult> BankPay()
- {
- try
- {
- var notify = await _client.ExecuteAsync<LianLianPayBankPayNotifyResponse>(Request);
- Console.WriteLine("NoOrder: " + notify.NoOrder);
- return Content("{\"ret_code\":\"0000\",\"ret_msg\":\"交易成功\"}", "application/json");
- }
- catch
- {
- return NoContent();
- }
- }
- [Route("authpay")]
- [HttpPost]
- public async Task<IActionResult> AuthPay()
- {
- try
- {
- var notify = await _client.ExecuteAsync<LianLianPayWapAuthPayNotifyResponse>(Request);
- Console.WriteLine("NoOrder: " + notify.NoOrder);
- return Content("{\"ret_code\":\"0000\",\"ret_msg\":\"交易成功\"}", "application/json");
- }
- catch
- {
- return NoContent();
- }
- }
- [Route("refund")]
- [HttpPost]
- public async Task<IActionResult> Refund()
- {
- try
- {
- var notify = await _client.ExecuteAsync<LianLianPayRefundNotifyResponse>(Request);
- Console.WriteLine("NoRefund: " + notify.NoRefund);
- return Content("{\"ret_code\":\"0000\",\"ret_msg\":\"交易成功\"}", "application/json");
- }
- catch
- {
- return NoContent();
- }
- }
- }
- }
|