NotifyController.cs 14 KB

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