NotifyController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. using Essensoft.AspNetCore.Payment.Alipay;
  2. using Essensoft.AspNetCore.Payment.Alipay.Notify;
  3. using Essensoft.AspNetCore.Payment.JDPay;
  4. using Essensoft.AspNetCore.Payment.JDPay.Notify;
  5. using Essensoft.AspNetCore.Payment.LianLianPay;
  6. using Essensoft.AspNetCore.Payment.LianLianPay.Notify;
  7. using Essensoft.AspNetCore.Payment.QPay;
  8. using Essensoft.AspNetCore.Payment.QPay.Notify;
  9. using Essensoft.AspNetCore.Payment.UnionPay;
  10. using Essensoft.AspNetCore.Payment.UnionPay.Notify;
  11. using Essensoft.AspNetCore.Payment.WeChatPay;
  12. using Essensoft.AspNetCore.Payment.WeChatPay.Notify;
  13. using Microsoft.AspNetCore.Mvc;
  14. using System;
  15. using System.Threading.Tasks;
  16. namespace WebApplicationSample.Controllers
  17. {
  18. [Route("notify/alipay")]
  19. public class AlipayNotifyController : Controller
  20. {
  21. private readonly AlipayNotifyClient _client = null;
  22. public AlipayNotifyController(AlipayNotifyClient client)
  23. {
  24. _client = client;
  25. }
  26. /// <summary>
  27. /// 电脑网站支付异步通知
  28. /// </summary>
  29. /// <returns></returns>
  30. [Route("pagepay")]
  31. [HttpPost]
  32. public async Task<IActionResult> PagePayAsync()
  33. {
  34. try
  35. {
  36. var notify = await _client.ExecuteAsync<AlipayTradePagePayNotifyResponse>(Request);
  37. if ("TRADE_SUCCESS" == notify.TradeStatus)
  38. {
  39. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  40. return Content("success", "text/plain");
  41. }
  42. return NoContent();
  43. }
  44. catch
  45. {
  46. return NoContent();
  47. }
  48. }
  49. /// <summary>
  50. /// 手机网站支付异步通知
  51. /// </summary>
  52. /// <returns></returns>
  53. [Route("wappay")]
  54. [HttpPost]
  55. public async Task<IActionResult> WapPayAsync()
  56. {
  57. try
  58. {
  59. var notify = await _client.ExecuteAsync<AlipayTradeWapPayNotifyResponse>(Request);
  60. if ("TRADE_SUCCESS" == notify.TradeStatus)
  61. {
  62. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  63. return Content("success", "text/plain");
  64. }
  65. return NoContent();
  66. }
  67. catch
  68. {
  69. return NoContent();
  70. }
  71. }
  72. /// <summary>
  73. /// 扫码支付异步通知
  74. /// </summary>
  75. /// <returns></returns>
  76. [Route("precreate")]
  77. [HttpPost]
  78. public async Task<IActionResult> PrecreateAsync()
  79. {
  80. try
  81. {
  82. var notify = await _client.ExecuteAsync<AlipayTradePrecreateNotifyResponse>(Request);
  83. if ("TRADE_SUCCESS" == notify.TradeStatus)
  84. {
  85. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  86. return Content("success", "text/plain");
  87. }
  88. return NoContent();
  89. }
  90. catch
  91. {
  92. return NoContent();
  93. }
  94. }
  95. /// <summary>
  96. /// 条码支付异步通知
  97. /// </summary>
  98. /// <returns></returns>
  99. [Route("pay")]
  100. [HttpPost]
  101. public async Task<IActionResult> PayAsync()
  102. {
  103. try
  104. {
  105. var notify = await _client.ExecuteAsync<AlipayTradePayNotifyResponse>(Request);
  106. if ("TRADE_SUCCESS" == notify.TradeStatus)
  107. {
  108. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  109. return Content("success", "text/plain");
  110. }
  111. return NoContent();
  112. }
  113. catch
  114. {
  115. return NoContent();
  116. }
  117. }
  118. }
  119. [Route("notify/wechatpay")]
  120. public class WeChatPayNotifyController : Controller
  121. {
  122. private readonly WeChatPayNotifyClient _client = null;
  123. public WeChatPayNotifyController(WeChatPayNotifyClient client)
  124. {
  125. _client = client;
  126. }
  127. [HttpPost]
  128. public async Task<IActionResult> PostAsync()
  129. {
  130. try
  131. {
  132. var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotifyResponse>(Request);
  133. if (notify.ReturnCode == "SUCCESS")
  134. {
  135. if (notify.ResultCode == "SUCCESS")
  136. {
  137. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  138. return Content("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>", "text/xml");
  139. }
  140. }
  141. return NoContent();
  142. }
  143. catch
  144. {
  145. return NoContent();
  146. }
  147. }
  148. }
  149. /// <summary>
  150. /// 微信支付退款通知
  151. /// </summary>
  152. [Route("notify/wechatpay/refund")]
  153. public class WeChatPayRefundNotifyController : Controller
  154. {
  155. private readonly WeChatPayNotifyClient _client = null;
  156. public WeChatPayRefundNotifyController(WeChatPayNotifyClient client)
  157. {
  158. _client = client;
  159. }
  160. [HttpPost]
  161. public async Task<IActionResult> PostAsync()
  162. {
  163. try
  164. {
  165. var notify = await _client.ExecuteAsync<WeChatPayRefundNotifyResponse>(Request);
  166. if (notify.ReturnCode == "SUCCESS")
  167. {
  168. if (notify.RefundStatus == "SUCCESS")
  169. {
  170. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  171. return Content("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>", "text/xml");
  172. }
  173. }
  174. return NoContent();
  175. }
  176. catch
  177. {
  178. return NoContent();
  179. }
  180. }
  181. }
  182. [Route("notify/qpay")]
  183. public class QPayNotifyController : Controller
  184. {
  185. private readonly QPayNotifyClient _client = null;
  186. public QPayNotifyController(QPayNotifyClient client)
  187. {
  188. _client = client;
  189. }
  190. [HttpPost]
  191. public async Task<IActionResult> PostAsync()
  192. {
  193. try
  194. {
  195. var notify = await _client.ExecuteAsync<QPayUnifiedOrderNotifyResponse>(Request);
  196. if ("SUCCESS" == notify.TradeState)
  197. {
  198. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  199. return Content("<xml><return_code>SUCCESS</return_code></xml>", "text/xml");
  200. }
  201. return NoContent();
  202. }
  203. catch
  204. {
  205. return NoContent();
  206. }
  207. }
  208. }
  209. [Route("notify/jdpay")]
  210. public class JDPayNotifyController : Controller
  211. {
  212. private readonly JDPayNotifyClient _client = null;
  213. public JDPayNotifyController(JDPayNotifyClient client)
  214. {
  215. _client = client;
  216. }
  217. [HttpPost]
  218. public async Task<IActionResult> Async()
  219. {
  220. try
  221. {
  222. var notify = await _client.ExecuteAsync<JDPayAsyncNotifyResponse>(Request);
  223. Console.WriteLine("TradeNum: " + notify.TradeNum + " tradeType :" + notify.TradeType);
  224. return Content("success", "text/plain");
  225. }
  226. catch
  227. {
  228. return NoContent();
  229. }
  230. }
  231. }
  232. [Route("notify/unionpay")]
  233. public class UnionPayNotifyController : Controller
  234. {
  235. private readonly UnionPayNotifyClient _client = null;
  236. public UnionPayNotifyController(UnionPayNotifyClient client)
  237. {
  238. _client = client;
  239. }
  240. /// <summary>
  241. /// 二维码支付 - 二维码消费(被扫)通知
  242. /// </summary>
  243. /// <returns></returns>
  244. [Route("appconsume")]
  245. [HttpPost]
  246. public async Task<IActionResult> AppConsume()
  247. {
  248. try
  249. {
  250. var notify = await _client.ExecuteAsync<UnionPayForm05_6_2_AppConsumeNotifyResponse>(Request);
  251. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  252. return Content("ok", "text/plain");
  253. }
  254. catch
  255. {
  256. return NoContent();
  257. }
  258. }
  259. /// <summary>
  260. /// 二维码支付 - 申请二维码(主扫)通知
  261. /// </summary>
  262. /// <returns></returns>
  263. [Route("applyqrcode")]
  264. [HttpPost]
  265. public async Task<IActionResult> ApplyQrCode()
  266. {
  267. try
  268. {
  269. var notify = await _client.ExecuteAsync<UnionPayForm05_6_1_ApplyQrCodeNotifyResponse>(Request);
  270. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  271. return Content("ok", "text/plain");
  272. }
  273. catch
  274. {
  275. return NoContent();
  276. }
  277. }
  278. /// <summary>
  279. /// 二维码支付 - 消费撤销通知
  280. /// </summary>
  281. /// <returns></returns>
  282. [Route("purchaseundo")]
  283. [HttpPost]
  284. public async Task<IActionResult> PurchaseUndo()
  285. {
  286. try
  287. {
  288. var notify = await _client.ExecuteAsync<UnionPayUpacpPurchaseUndoNotifyResponse>(Request);
  289. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  290. return Content("ok", "text/plain");
  291. }
  292. catch
  293. {
  294. return NoContent();
  295. }
  296. }
  297. /// <summary>
  298. /// 二维码支付 - 退货通知
  299. /// </summary>
  300. /// <returns></returns>
  301. [Route("refund")]
  302. [HttpPost]
  303. public async Task<IActionResult> Refund()
  304. {
  305. try
  306. {
  307. var notify = await _client.ExecuteAsync<UnionPayUpacpRefundNotifyResponse>(Request);
  308. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  309. return Content("ok", "text/plain");
  310. }
  311. catch
  312. {
  313. return NoContent();
  314. }
  315. }
  316. /// <summary>
  317. /// 网关支付 - 跳转网关页面支付通知
  318. /// </summary>
  319. /// <returns></returns>
  320. [Route("frontconsume62")]
  321. [HttpPost]
  322. public async Task<IActionResult> FrontConsume62()
  323. {
  324. try
  325. {
  326. var notify = await _client.ExecuteAsync<UnionPayForm_6_2_FrontConsumeNotifyResponse>(Request);
  327. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  328. return Content("ok", "text/plain");
  329. }
  330. catch
  331. {
  332. return NoContent();
  333. }
  334. }
  335. /// <summary>
  336. /// 网关支付 - 消费撤销通知
  337. /// </summary>
  338. /// <returns></returns>
  339. [Route("consumeundo63")]
  340. [HttpPost]
  341. public async Task<IActionResult> ConsumeUndo63()
  342. {
  343. try
  344. {
  345. var notify = await _client.ExecuteAsync<UnionPayForm_6_3_ConsumeUndoNotifyResponse>(Request);
  346. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  347. return Content("ok", "text/plain");
  348. }
  349. catch
  350. {
  351. return NoContent();
  352. }
  353. }
  354. /// <summary>
  355. /// 网关支付 - 退货通知
  356. /// </summary>
  357. /// <returns></returns>
  358. [Route("refund64")]
  359. [HttpPost]
  360. public async Task<IActionResult> Refund64()
  361. {
  362. try
  363. {
  364. var notify = await _client.ExecuteAsync<UnionPayForm_6_4_RefundNotifyResponse>(Request);
  365. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  366. return Content("ok", "text/plain");
  367. }
  368. catch
  369. {
  370. return NoContent();
  371. }
  372. }
  373. /// <summary>
  374. /// 网关支付 - 预授权通知
  375. /// </summary>
  376. /// <returns></returns>
  377. [Route("authdealfront671")]
  378. [HttpPost]
  379. public async Task<IActionResult> AuthDealFront671()
  380. {
  381. try
  382. {
  383. var notify = await _client.ExecuteAsync<UnionPayForm_6_7_1_AuthDeal_FrontNotifyResponse>(Request);
  384. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  385. return Content("ok", "text/plain");
  386. }
  387. catch
  388. {
  389. return NoContent();
  390. }
  391. }
  392. /// <summary>
  393. /// 网关支付 - 预授权撤销通知
  394. /// </summary>
  395. /// <returns></returns>
  396. [Route("authundo672")]
  397. [HttpPost]
  398. public async Task<IActionResult> AuthUndo672()
  399. {
  400. try
  401. {
  402. var notify = await _client.ExecuteAsync<UnionPayForm_6_7_2_AuthUndoNotifyResponse>(Request);
  403. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  404. return Content("ok", "text/plain");
  405. }
  406. catch
  407. {
  408. return NoContent();
  409. }
  410. }
  411. /// <summary>
  412. /// 网关支付 - 预授权完成通知
  413. /// </summary>
  414. /// <returns></returns>
  415. [Route("authfinish673")]
  416. [HttpPost]
  417. public async Task<IActionResult> AuthFinish673()
  418. {
  419. try
  420. {
  421. var notify = await _client.ExecuteAsync<UnionPayForm_6_7_3_AuthFinishNotifyResponse>(Request);
  422. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  423. return Content("ok", "text/plain");
  424. }
  425. catch
  426. {
  427. return NoContent();
  428. }
  429. }
  430. /// <summary>
  431. /// 网关支付 - 预授权完成撤销通知
  432. /// </summary>
  433. /// <returns></returns>
  434. [Route("authfinishundo674")]
  435. [HttpPost]
  436. public async Task<IActionResult> AuthFinishUndo674()
  437. {
  438. try
  439. {
  440. var notify = await _client.ExecuteAsync<UnionPayForm_6_7_4_AuthFinishUndoNotifyResponse>(Request);
  441. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  442. return Content("ok", "text/plain");
  443. }
  444. catch
  445. {
  446. return NoContent();
  447. }
  448. }
  449. }
  450. [Route("notify/LianLianPay")]
  451. public class LianLianPayNotifyController : Controller
  452. {
  453. private readonly LianLianPayNotifyClient _client = null;
  454. public LianLianPayNotifyController(LianLianPayNotifyClient client)
  455. {
  456. _client = client;
  457. }
  458. [Route("quickpay")]
  459. [HttpPost]
  460. public async Task<IActionResult> QuickPay()
  461. {
  462. try
  463. {
  464. var notify = await _client.ExecuteAsync<LianLianPayWebQuickPayNotifyResponse>(Request);
  465. Console.WriteLine("NoOrder: " + notify.NoOrder);
  466. return Content("{\"ret_code\":\"0000\",\"ret_msg\":\"交易成功\"}", "application/json");
  467. }
  468. catch
  469. {
  470. return NoContent();
  471. }
  472. }
  473. [Route("bankpay")]
  474. [HttpPost]
  475. public async Task<IActionResult> BankPay()
  476. {
  477. try
  478. {
  479. var notify = await _client.ExecuteAsync<LianLianPayBankPayNotifyResponse>(Request);
  480. Console.WriteLine("NoOrder: " + notify.NoOrder);
  481. return Content("{\"ret_code\":\"0000\",\"ret_msg\":\"交易成功\"}", "application/json");
  482. }
  483. catch
  484. {
  485. return NoContent();
  486. }
  487. }
  488. [Route("authpay")]
  489. [HttpPost]
  490. public async Task<IActionResult> AuthPay()
  491. {
  492. try
  493. {
  494. var notify = await _client.ExecuteAsync<LianLianPayWapAuthPayNotifyResponse>(Request);
  495. Console.WriteLine("NoOrder: " + notify.NoOrder);
  496. return Content("{\"ret_code\":\"0000\",\"ret_msg\":\"交易成功\"}", "application/json");
  497. }
  498. catch
  499. {
  500. return NoContent();
  501. }
  502. }
  503. [Route("refund")]
  504. [HttpPost]
  505. public async Task<IActionResult> Refund()
  506. {
  507. try
  508. {
  509. var notify = await _client.ExecuteAsync<LianLianPayRefundNotifyResponse>(Request);
  510. Console.WriteLine("NoRefund: " + notify.NoRefund);
  511. return Content("{\"ret_code\":\"0000\",\"ret_msg\":\"交易成功\"}", "application/json");
  512. }
  513. catch
  514. {
  515. return NoContent();
  516. }
  517. }
  518. }
  519. }