UnionPayController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. using Essensoft.AspNetCore.Payment.UnionPay;
  2. using Essensoft.AspNetCore.Payment.UnionPay.Notify;
  3. using Essensoft.AspNetCore.Payment.UnionPay.Request;
  4. using Microsoft.AspNetCore.Mvc;
  5. using System.Threading.Tasks;
  6. namespace WebApplicationSample.Controllers
  7. {
  8. public class UnionPayController : Controller
  9. {
  10. private readonly UnionPayClient _client = null;
  11. private readonly UnionPayNotifyClient _notifyClient = null;
  12. public UnionPayController(UnionPayClient client, UnionPayNotifyClient notifyClient)
  13. {
  14. _client = client;
  15. _notifyClient = notifyClient;
  16. }
  17. #region 二维码支付
  18. [HttpPost]
  19. public async Task<IActionResult> PurchaseUndo(string orderId, string txnTime, string txnAmt, string origQryId, string origOrderId, string origTxnTime, string backUrl)
  20. {
  21. var request = new UnionPayUpacpPurchaseUndoRequest()
  22. {
  23. TxnType = "31",
  24. TxnSubType = "00",
  25. BizType = "000000",
  26. ChannelType = "08",
  27. OrderId = orderId,
  28. TxnTime = txnTime,
  29. TxnAmt = txnAmt,
  30. OrigQryId = origQryId,
  31. OrigOrderId = origOrderId,
  32. OrigTxnTime = origTxnTime,
  33. BackUrl = backUrl,
  34. };
  35. var response = await _client.ExecuteAsync(request);
  36. return Ok(response.Body);
  37. }
  38. [HttpPost]
  39. public async Task<IActionResult> Refund(string orderId, string txnTime, string txnAmt, string origQryId, string origOrderId, string origTxnTime, string backUrl)
  40. {
  41. var request = new UnionPayUpacpRefundRequest()
  42. {
  43. TxnType = "04",
  44. TxnSubType = "00",
  45. BizType = "000000",
  46. ChannelType = "08",
  47. OrderId = orderId,
  48. TxnTime = txnTime,
  49. TxnAmt = txnAmt,
  50. OrigQryId = origQryId,
  51. OrigOrderId = origOrderId,
  52. OrigTxnTime = origTxnTime,
  53. BackUrl = backUrl,
  54. };
  55. var response = await _client.ExecuteAsync(request);
  56. return Ok(response.Body);
  57. }
  58. [HttpPost]
  59. public async Task<IActionResult> ApplyQrCode(string orderId, string txnTime, string txnAmt, string currencyCode, string backUrl)
  60. {
  61. var request = new UnionPayForm05_6_1_ApplyQrCodeRequest()
  62. {
  63. TxnType = "01",
  64. TxnSubType = "07",
  65. BizType = "000000",
  66. ChannelType = "08",
  67. OrderId = orderId,
  68. TxnTime = txnTime,
  69. TxnAmt = txnAmt,
  70. BackUrl = backUrl,
  71. CurrencyCode = currencyCode
  72. };
  73. var response = await _client.ExecuteAsync(request);
  74. return Ok(response.Body);
  75. }
  76. [HttpPost]
  77. public async Task<IActionResult> AppConsume(string orderId, string qrNo, string txnTime, string txnAmt, string currencyCode, string backUrl)
  78. {
  79. var request = new UnionPayForm05_6_2_AppConsumeRequest()
  80. {
  81. TxnType = "01",
  82. TxnSubType = "06",
  83. BizType = "000000",
  84. ChannelType = "08",
  85. OrderId = orderId,
  86. TxnTime = txnTime,
  87. TxnAmt = txnAmt,
  88. CurrencyCode = currencyCode,
  89. QrNo = qrNo,
  90. BackUrl = backUrl,
  91. };
  92. var response = await _client.ExecuteAsync(request);
  93. return Ok(response.Body);
  94. }
  95. [HttpPost]
  96. public async Task<IActionResult> Query563(string orderId, string txnTime)
  97. {
  98. var request = new UnionPayForm05_6_3_QueryRequest()
  99. {
  100. TxnType = "00",
  101. TxnSubType = "00",
  102. BizType = "000201",
  103. OrderId = orderId,
  104. TxnTime = txnTime,
  105. };
  106. var response = await _client.ExecuteAsync(request);
  107. return Ok(response.Body);
  108. }
  109. [HttpPost]
  110. public async Task<IActionResult> Reversal0565(string orderId, string txnTime)
  111. {
  112. var request = new UnionPayForm05_6_5_ReversalRequest()
  113. {
  114. TxnType = "99",
  115. TxnSubType = "01",
  116. BizType = "000000",
  117. ChannelType = "08",
  118. OrderId = orderId,
  119. TxnTime = txnTime,
  120. };
  121. var response = await _client.ExecuteAsync(request);
  122. return Ok(response.Body);
  123. }
  124. [HttpPost]
  125. public async Task<IActionResult> FileTransfer057(string fileType, string txnTime, string settleDate)
  126. {
  127. var request = new UnionPayForm05_7_FileTransferRequest()
  128. {
  129. TxnType = "76",
  130. TxnSubType = "01",
  131. BizType = "000000",
  132. FileType = fileType,
  133. TxnTime = txnTime,
  134. SettleDate = settleDate,
  135. };
  136. var response = await _client.ExecuteAsync(request);
  137. return Ok(response.Body);
  138. }
  139. #endregion
  140. #region 网关支付
  141. [HttpPost]
  142. public async Task<IActionResult> FrontConsume62(string orderId, string txnTime, string txnAmt, string currencyCode, string payTimeout, string frontUrl, string backUrl)
  143. {
  144. var request = new UnionPayForm_6_2_FrontConsumeRequest()
  145. {
  146. TxnType = "01",
  147. TxnSubType = "01",
  148. BizType = "000201",
  149. ChannelType = "07",
  150. OrderId = orderId,
  151. TxnTime = txnTime,
  152. TxnAmt = txnAmt,
  153. CurrencyCode = currencyCode,
  154. PayTimeout = payTimeout,
  155. FrontUrl = frontUrl,
  156. BackUrl = backUrl,
  157. };
  158. var response = await _client.PageExecuteAsync(request, "POST");
  159. return Content(response.Body, "text/html");
  160. }
  161. [HttpPost]
  162. public async Task<IActionResult> FrontConsume62Return()
  163. {
  164. try
  165. {
  166. var notify = await _notifyClient.ExecuteAsync<UnionPayForm_6_2_FrontConsumeReturnResponse>(Request);
  167. return Content("ok", "text/plain");
  168. }
  169. catch
  170. {
  171. return Content("error", "text/plain");
  172. }
  173. }
  174. [HttpPost]
  175. public async Task<IActionResult> ConsumeUndo63(string orderId, string txnTime, string txnAmt, string origQryId, string backUrl)
  176. {
  177. var request = new UnionPayForm_6_3_ConsumeUndoRequest()
  178. {
  179. TxnType = "31",
  180. TxnSubType = "00",
  181. BizType = "000201",
  182. ChannelType = "07",
  183. OrderId = orderId,
  184. TxnTime = txnTime,
  185. TxnAmt = txnAmt,
  186. OrigQryId = origQryId,
  187. BackUrl = backUrl,
  188. };
  189. var response = await _client.ExecuteAsync(request);
  190. return Ok(response.Body);
  191. }
  192. [HttpPost]
  193. public async Task<IActionResult> Refund64(string orderId, string txnTime, string txnAmt, string origQryId, string backUrl)
  194. {
  195. var request = new UnionPayForm_6_4_RefundRequest()
  196. {
  197. TxnType = "04",
  198. TxnSubType = "00",
  199. BizType = "000301",
  200. ChannelType = "07",
  201. OrderId = orderId,
  202. TxnTime = txnTime,
  203. TxnAmt = txnAmt,
  204. OrigQryId = origQryId,
  205. BackUrl = backUrl,
  206. };
  207. var response = await _client.ExecuteAsync(request);
  208. return Ok(response.Body);
  209. }
  210. [HttpPost]
  211. public async Task<IActionResult> Query65(string orderId, string txnTime)
  212. {
  213. var request = new UnionPayForm_6_5_QueryRequest()
  214. {
  215. TxnType = "00",
  216. TxnSubType = "00",
  217. BizType = "000201",
  218. OrderId = orderId,
  219. TxnTime = txnTime,
  220. };
  221. var response = await _client.ExecuteAsync(request);
  222. return Ok(response.Body);
  223. }
  224. [HttpPost]
  225. public async Task<IActionResult> AuthDealFront671(string orderId, string txnTime, string txnAmt, string currencyCode, string payTimeout, string frontUrl, string backUrl)
  226. {
  227. var request = new UnionPayForm_6_7_1_AuthDeal_FrontRequest()
  228. {
  229. TxnType = "02",
  230. TxnSubType = "01",
  231. BizType = "000201",
  232. ChannelType = "07",
  233. OrderId = orderId,
  234. TxnTime = txnTime,
  235. TxnAmt = txnAmt,
  236. CurrencyCode = currencyCode,
  237. PayTimeout = payTimeout,
  238. FrontUrl = frontUrl,
  239. BackUrl = backUrl,
  240. };
  241. var response = await _client.PageExecuteAsync(request, "POST");
  242. return Content(response.Body, "text/html");
  243. }
  244. [HttpPost]
  245. public async Task<IActionResult> AuthUndo672(string orderId, string txnTime, string txnAmt, string origQryId, string backUrl)
  246. {
  247. var request = new UnionPayForm_6_7_2_AuthUndoRequest()
  248. {
  249. TxnType = "32",
  250. TxnSubType = "00",
  251. BizType = "000201",
  252. ChannelType = "07",
  253. OrderId = orderId,
  254. TxnTime = txnTime,
  255. TxnAmt = txnAmt,
  256. OrigQryId = origQryId,
  257. BackUrl = backUrl,
  258. };
  259. var response = await _client.ExecuteAsync(request);
  260. return Ok(response.Body);
  261. }
  262. [HttpPost]
  263. public async Task<IActionResult> AuthFinish673(string orderId, string txnTime, string txnAmt, string origQryId, string backUrl)
  264. {
  265. var request = new UnionPayForm_6_7_3_AuthFinishRequest()
  266. {
  267. TxnType = "03",
  268. TxnSubType = "00",
  269. BizType = "000201",
  270. ChannelType = "07",
  271. OrderId = orderId,
  272. TxnTime = txnTime,
  273. TxnAmt = txnAmt,
  274. OrigQryId = origQryId,
  275. BackUrl = backUrl,
  276. };
  277. var response = await _client.ExecuteAsync(request);
  278. return Ok(response.Body);
  279. }
  280. [HttpPost]
  281. public async Task<IActionResult> AuthFinishUndo674(string orderId, string txnTime, string txnAmt, string origQryId, string backUrl)
  282. {
  283. var request = new UnionPayForm_6_7_4_AuthFinishUndoRequest()
  284. {
  285. TxnType = "03",
  286. TxnSubType = "00",
  287. BizType = "000201",
  288. ChannelType = "07",
  289. OrderId = orderId,
  290. TxnTime = txnTime,
  291. TxnAmt = txnAmt,
  292. OrigQryId = origQryId,
  293. BackUrl = backUrl,
  294. };
  295. var response = await _client.ExecuteAsync(request);
  296. return Ok(response.Body);
  297. }
  298. [HttpPost]
  299. public async Task<IActionResult> FileTransfer66(string fileType, string txnTime, string settleDate)
  300. {
  301. var request = new UnionPayForm_6_6_FileTransferRequest()
  302. {
  303. TxnType = "76",
  304. TxnSubType = "01",
  305. BizType = "000000",
  306. FileType = fileType,
  307. TxnTime = txnTime,
  308. SettleDate = settleDate,
  309. };
  310. var response = await _client.ExecuteAsync(request);
  311. return Ok(response.Body);
  312. }
  313. #endregion
  314. }
  315. }