123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- using Essensoft.AspNetCore.Payment.UnionPay;
- using Essensoft.AspNetCore.Payment.UnionPay.Notify;
- using Essensoft.AspNetCore.Payment.UnionPay.Request;
- using Microsoft.AspNetCore.Mvc;
- using System.Threading.Tasks;
- namespace WebApplicationSample.Controllers
- {
- public class UnionPayController : Controller
- {
- private readonly UnionPayClient _client = null;
- private readonly UnionPayNotifyClient _notifyClient = null;
- public UnionPayController(UnionPayClient client, UnionPayNotifyClient notifyClient)
- {
- _client = client;
- _notifyClient = notifyClient;
- }
- #region 二维码支付
- [HttpPost]
- public async Task<IActionResult> PurchaseUndo(string orderId, string txnTime, string txnAmt, string origQryId, string origOrderId, string origTxnTime, string backUrl)
- {
- var request = new UnionPayUpacpPurchaseUndoRequest()
- {
- TxnType = "31",
- TxnSubType = "00",
- BizType = "000000",
- ChannelType = "08",
- OrderId = orderId,
- TxnTime = txnTime,
- TxnAmt = txnAmt,
- OrigQryId = origQryId,
- OrigOrderId = origOrderId,
- OrigTxnTime = origTxnTime,
- BackUrl = backUrl,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- [HttpPost]
- public async Task<IActionResult> Refund(string orderId, string txnTime, string txnAmt, string origQryId, string origOrderId, string origTxnTime, string backUrl)
- {
- var request = new UnionPayUpacpRefundRequest()
- {
- TxnType = "04",
- TxnSubType = "00",
- BizType = "000000",
- ChannelType = "08",
- OrderId = orderId,
- TxnTime = txnTime,
- TxnAmt = txnAmt,
- OrigQryId = origQryId,
- OrigOrderId = origOrderId,
- OrigTxnTime = origTxnTime,
- BackUrl = backUrl,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- [HttpPost]
- public async Task<IActionResult> ApplyQrCode(string orderId, string txnTime, string txnAmt, string currencyCode, string backUrl)
- {
- var request = new UnionPayForm05_6_1_ApplyQrCodeRequest()
- {
- TxnType = "01",
- TxnSubType = "07",
- BizType = "000000",
- ChannelType = "08",
- OrderId = orderId,
- TxnTime = txnTime,
- TxnAmt = txnAmt,
- BackUrl = backUrl,
- CurrencyCode = currencyCode
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- [HttpPost]
- public async Task<IActionResult> AppConsume(string orderId, string qrNo, string txnTime, string txnAmt, string currencyCode, string backUrl)
- {
- var request = new UnionPayForm05_6_2_AppConsumeRequest()
- {
- TxnType = "01",
- TxnSubType = "06",
- BizType = "000000",
- ChannelType = "08",
- OrderId = orderId,
- TxnTime = txnTime,
- TxnAmt = txnAmt,
- CurrencyCode = currencyCode,
- QrNo = qrNo,
- BackUrl = backUrl,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- [HttpPost]
- public async Task<IActionResult> Query563(string orderId, string txnTime)
- {
- var request = new UnionPayForm05_6_3_QueryRequest()
- {
- TxnType = "00",
- TxnSubType = "00",
- BizType = "000201",
- OrderId = orderId,
- TxnTime = txnTime,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- [HttpPost]
- public async Task<IActionResult> Reversal0565(string orderId, string txnTime)
- {
- var request = new UnionPayForm05_6_5_ReversalRequest()
- {
- TxnType = "99",
- TxnSubType = "01",
- BizType = "000000",
- ChannelType = "08",
- OrderId = orderId,
- TxnTime = txnTime,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- [HttpPost]
- public async Task<IActionResult> FileTransfer057(string fileType, string txnTime, string settleDate)
- {
- var request = new UnionPayForm05_7_FileTransferRequest()
- {
- TxnType = "76",
- TxnSubType = "01",
- BizType = "000000",
- FileType = fileType,
- TxnTime = txnTime,
- SettleDate = settleDate,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- #endregion
- #region 网关支付
- [HttpPost]
- public async Task<IActionResult> FrontConsume62(string orderId, string txnTime, string txnAmt, string currencyCode, string payTimeout, string frontUrl, string backUrl)
- {
- var request = new UnionPayForm_6_2_FrontConsumeRequest()
- {
- TxnType = "01",
- TxnSubType = "01",
- BizType = "000201",
- ChannelType = "07",
- OrderId = orderId,
- TxnTime = txnTime,
- TxnAmt = txnAmt,
- CurrencyCode = currencyCode,
- PayTimeout = payTimeout,
- FrontUrl = frontUrl,
- BackUrl = backUrl,
- };
- var response = await _client.PageExecuteAsync(request, "POST");
- return Content(response.Body, "text/html");
- }
- [HttpPost]
- public async Task<IActionResult> FrontConsume62Return()
- {
- try
- {
- var notify = await _notifyClient.ExecuteAsync<UnionPayForm_6_2_FrontConsumeReturnResponse>(Request);
- return Content("ok", "text/plain");
- }
- catch
- {
- return Content("error", "text/plain");
- }
- }
- [HttpPost]
- public async Task<IActionResult> ConsumeUndo63(string orderId, string txnTime, string txnAmt, string origQryId, string backUrl)
- {
- var request = new UnionPayForm_6_3_ConsumeUndoRequest()
- {
- TxnType = "31",
- TxnSubType = "00",
- BizType = "000201",
- ChannelType = "07",
- OrderId = orderId,
- TxnTime = txnTime,
- TxnAmt = txnAmt,
- OrigQryId = origQryId,
- BackUrl = backUrl,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- [HttpPost]
- public async Task<IActionResult> Refund64(string orderId, string txnTime, string txnAmt, string origQryId, string backUrl)
- {
- var request = new UnionPayForm_6_4_RefundRequest()
- {
- TxnType = "04",
- TxnSubType = "00",
- BizType = "000301",
- ChannelType = "07",
- OrderId = orderId,
- TxnTime = txnTime,
- TxnAmt = txnAmt,
- OrigQryId = origQryId,
- BackUrl = backUrl,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- [HttpPost]
- public async Task<IActionResult> Query65(string orderId, string txnTime)
- {
- var request = new UnionPayForm_6_5_QueryRequest()
- {
- TxnType = "00",
- TxnSubType = "00",
- BizType = "000201",
- OrderId = orderId,
- TxnTime = txnTime,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- [HttpPost]
- public async Task<IActionResult> AuthDealFront671(string orderId, string txnTime, string txnAmt, string currencyCode, string payTimeout, string frontUrl, string backUrl)
- {
- var request = new UnionPayForm_6_7_1_AuthDeal_FrontRequest()
- {
- TxnType = "02",
- TxnSubType = "01",
- BizType = "000201",
- ChannelType = "07",
- OrderId = orderId,
- TxnTime = txnTime,
- TxnAmt = txnAmt,
- CurrencyCode = currencyCode,
- PayTimeout = payTimeout,
- FrontUrl = frontUrl,
- BackUrl = backUrl,
- };
- var response = await _client.PageExecuteAsync(request, "POST");
- return Content(response.Body, "text/html");
- }
- [HttpPost]
- public async Task<IActionResult> AuthUndo672(string orderId, string txnTime, string txnAmt, string origQryId, string backUrl)
- {
- var request = new UnionPayForm_6_7_2_AuthUndoRequest()
- {
- TxnType = "32",
- TxnSubType = "00",
- BizType = "000201",
- ChannelType = "07",
- OrderId = orderId,
- TxnTime = txnTime,
- TxnAmt = txnAmt,
- OrigQryId = origQryId,
- BackUrl = backUrl,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- [HttpPost]
- public async Task<IActionResult> AuthFinish673(string orderId, string txnTime, string txnAmt, string origQryId, string backUrl)
- {
- var request = new UnionPayForm_6_7_3_AuthFinishRequest()
- {
- TxnType = "03",
- TxnSubType = "00",
- BizType = "000201",
- ChannelType = "07",
- OrderId = orderId,
- TxnTime = txnTime,
- TxnAmt = txnAmt,
- OrigQryId = origQryId,
- BackUrl = backUrl,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- [HttpPost]
- public async Task<IActionResult> AuthFinishUndo674(string orderId, string txnTime, string txnAmt, string origQryId, string backUrl)
- {
- var request = new UnionPayForm_6_7_4_AuthFinishUndoRequest()
- {
- TxnType = "03",
- TxnSubType = "00",
- BizType = "000201",
- ChannelType = "07",
- OrderId = orderId,
- TxnTime = txnTime,
- TxnAmt = txnAmt,
- OrigQryId = origQryId,
- BackUrl = backUrl,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- [HttpPost]
- public async Task<IActionResult> FileTransfer66(string fileType, string txnTime, string settleDate)
- {
- var request = new UnionPayForm_6_6_FileTransferRequest()
- {
- TxnType = "76",
- TxnSubType = "01",
- BizType = "000000",
- FileType = fileType,
- TxnTime = txnTime,
- SettleDate = settleDate,
- };
- var response = await _client.ExecuteAsync(request);
- return Ok(response.Body);
- }
- #endregion
- }
- }
|