NotifyController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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 NewWebApplicationSample.Controllers
  17. {
  18. #region 支付宝异步通知
  19. [Route("notify/alipay")]
  20. public class AlipayNotifyController : Controller
  21. {
  22. private readonly AlipayNotifyClient _client = null;
  23. public AlipayNotifyController(AlipayNotifyClient client)
  24. {
  25. _client = client;
  26. }
  27. /// <summary>
  28. /// 扫码支付异步通知
  29. /// </summary>
  30. /// <returns></returns>
  31. [Route("precreate")]
  32. [HttpPost]
  33. public async Task<IActionResult> Precreate()
  34. {
  35. try
  36. {
  37. var notify = await _client.ExecuteAsync<AlipayTradePrecreateNotifyResponse>(Request);
  38. if ("TRADE_SUCCESS" == notify.TradeStatus)
  39. {
  40. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  41. return AlipayNotifyResult.Success;
  42. }
  43. return NoContent();
  44. }
  45. catch
  46. {
  47. return NoContent();
  48. }
  49. }
  50. /// <summary>
  51. /// 条码支付异步通知
  52. /// </summary>
  53. /// <returns></returns>
  54. [Route("pay")]
  55. [HttpPost]
  56. public async Task<IActionResult> Pay()
  57. {
  58. try
  59. {
  60. var notify = await _client.ExecuteAsync<AlipayTradePayNotifyResponse>(Request);
  61. if ("TRADE_SUCCESS" == notify.TradeStatus)
  62. {
  63. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  64. return AlipayNotifyResult.Success;
  65. }
  66. return NoContent();
  67. }
  68. catch
  69. {
  70. return NoContent();
  71. }
  72. }
  73. /// <summary>
  74. /// APP支付异步通知
  75. /// </summary>
  76. /// <returns></returns>
  77. [Route("apppay")]
  78. [HttpPost]
  79. public async Task<IActionResult> AppPay()
  80. {
  81. try
  82. {
  83. var notify = await _client.ExecuteAsync<AlipayTradeAppPayNotifyResponse>(Request);
  84. if ("TRADE_SUCCESS" == notify.TradeStatus)
  85. {
  86. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  87. return AlipayNotifyResult.Success;
  88. }
  89. return NoContent();
  90. }
  91. catch
  92. {
  93. return NoContent();
  94. }
  95. }
  96. /// <summary>
  97. /// 电脑网站支付异步通知
  98. /// </summary>
  99. /// <returns></returns>
  100. [Route("pagepay")]
  101. [HttpPost]
  102. public async Task<IActionResult> PagePay()
  103. {
  104. try
  105. {
  106. var notify = await _client.ExecuteAsync<AlipayTradePagePayNotifyResponse>(Request);
  107. if ("TRADE_SUCCESS" == notify.TradeStatus)
  108. {
  109. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  110. return AlipayNotifyResult.Success;
  111. }
  112. return NoContent();
  113. }
  114. catch
  115. {
  116. return NoContent();
  117. }
  118. }
  119. /// <summary>
  120. /// 手机网站支付异步通知
  121. /// </summary>
  122. /// <returns></returns>
  123. [Route("wappay")]
  124. [HttpPost]
  125. public async Task<IActionResult> WapPay()
  126. {
  127. try
  128. {
  129. var notify = await _client.ExecuteAsync<AlipayTradeWapPayNotifyResponse>(Request);
  130. if ("TRADE_SUCCESS" == notify.TradeStatus)
  131. {
  132. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  133. return AlipayNotifyResult.Success;
  134. }
  135. return NoContent();
  136. }
  137. catch
  138. {
  139. return NoContent();
  140. }
  141. }
  142. }
  143. #endregion
  144. #region 微信支付异步通知
  145. [Route("notify/wechatpay")]
  146. public class WeChatPayNotifyController : Controller
  147. {
  148. private readonly WeChatPayNotifyClient _client = null;
  149. public WeChatPayNotifyController(WeChatPayNotifyClient client)
  150. {
  151. _client = client;
  152. }
  153. /// <summary>
  154. /// 统一下单支付结果通知
  155. /// </summary>
  156. /// <returns></returns>
  157. [Route("unifiedorder")]
  158. [HttpPost]
  159. public async Task<IActionResult> Unifiedorder()
  160. {
  161. try
  162. {
  163. var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotifyResponse>(Request);
  164. if (notify.ReturnCode == "SUCCESS")
  165. {
  166. if (notify.ResultCode == "SUCCESS")
  167. {
  168. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  169. return WeChatPayNotifyResult.Success;
  170. }
  171. }
  172. return NoContent();
  173. }
  174. catch
  175. {
  176. return NoContent();
  177. }
  178. }
  179. /// <summary>
  180. /// 退款结果通知
  181. /// </summary>
  182. /// <returns></returns>
  183. [Route("refund")]
  184. [HttpPost]
  185. public async Task<IActionResult> Refund()
  186. {
  187. try
  188. {
  189. var notify = await _client.ExecuteAsync<WeChatPayRefundNotifyResponse>(Request);
  190. if (notify.ReturnCode == "SUCCESS")
  191. {
  192. if (notify.RefundStatus == "SUCCESS")
  193. {
  194. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  195. return WeChatPayNotifyResult.Success;
  196. }
  197. }
  198. return NoContent();
  199. }
  200. catch
  201. {
  202. return NoContent();
  203. }
  204. }
  205. }
  206. #endregion
  207. #region QQ钱包异步通知
  208. [Route("notify/qpay")]
  209. public class QPayNotifyController : Controller
  210. {
  211. private readonly QPayNotifyClient _client = null;
  212. public QPayNotifyController(QPayNotifyClient client)
  213. {
  214. _client = client;
  215. }
  216. /// <summary>
  217. /// 统一下单支付结果通知
  218. /// </summary>
  219. /// <returns></returns>
  220. [Route("unifiedorder")]
  221. [HttpPost]
  222. public async Task<IActionResult> Unifiedorder()
  223. {
  224. try
  225. {
  226. var notify = await _client.ExecuteAsync<QPayUnifiedOrderNotifyResponse>(Request);
  227. if ("SUCCESS" == notify.TradeState)
  228. {
  229. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  230. return QPayNotifyResult.Success;
  231. }
  232. return NoContent();
  233. }
  234. catch
  235. {
  236. return NoContent();
  237. }
  238. }
  239. /// <summary>
  240. /// 付款码支付结果通知
  241. /// </summary>
  242. /// <returns></returns>
  243. [Route("micropay")]
  244. [HttpPost]
  245. public async Task<IActionResult> MicroPay()
  246. {
  247. try
  248. {
  249. var notify = await _client.ExecuteAsync<QPayMicroPayNotifyResponse>(Request);
  250. if ("SUCCESS" == notify.TradeState)
  251. {
  252. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  253. return QPayNotifyResult.Success;
  254. }
  255. return NoContent();
  256. }
  257. catch
  258. {
  259. return NoContent();
  260. }
  261. }
  262. }
  263. #endregion
  264. #region 京东支付异步通知
  265. [Route("notify/jdpay")]
  266. public class JDPayNotifyController : Controller
  267. {
  268. private readonly JDPayNotifyClient _client = null;
  269. public JDPayNotifyController(JDPayNotifyClient client)
  270. {
  271. _client = client;
  272. }
  273. [Route("async")]
  274. [HttpPost]
  275. public async Task<IActionResult> Async()
  276. {
  277. try
  278. {
  279. var notify = await _client.ExecuteAsync<JDPayAsyncNotifyResponse>(Request);
  280. Console.WriteLine("TradeNum: " + notify.TradeNum + " tradeType :" + notify.TradeType);// notify.TradeType 0-消费 1-退款
  281. return JDPayNotifyResult.Success;
  282. }
  283. catch
  284. {
  285. return NoContent();
  286. }
  287. }
  288. [Route("defraypay")]
  289. [HttpPost]
  290. public async Task<IActionResult> DefrayPay()
  291. {
  292. try
  293. {
  294. var notify = await _client.ExecuteAsync<JDPayDefrayPayNotifyResponse>(Request);
  295. Console.WriteLine("trade_no: " + notify.TradeNo + " trade_amount :" + notify.TradeAmount);
  296. return JDPayNotifyResult.Success;
  297. }
  298. catch
  299. {
  300. return NoContent();
  301. }
  302. }
  303. }
  304. #endregion
  305. #region 连连支付异步通知
  306. [Route("notify/lianlianpay")]
  307. public class LianLianPayNotifyController : Controller
  308. {
  309. private readonly LianLianPayNotifyClient _client = null;
  310. public LianLianPayNotifyController(LianLianPayNotifyClient client)
  311. {
  312. _client = client;
  313. }
  314. [Route("webquickpay")]
  315. [HttpPost]
  316. public async Task<IActionResult> WebQuickPay()
  317. {
  318. try
  319. {
  320. var notify = await _client.ExecuteAsync<LianLianPayWebQuickPayNotifyResponse>(Request);
  321. Console.WriteLine("NoOrder: " + notify.NoOrder);
  322. return LianLianPayNotifyResult.Success;
  323. }
  324. catch
  325. {
  326. return NoContent();
  327. }
  328. }
  329. [Route("wapquickpay")]
  330. [HttpPost]
  331. public async Task<IActionResult> WapQuickPay()
  332. {
  333. try
  334. {
  335. var notify = await _client.ExecuteAsync<LianLianPayWapQuickPayNotifyResponse>(Request);
  336. Console.WriteLine("NoOrder: " + notify.NoOrder);
  337. return LianLianPayNotifyResult.Success;
  338. }
  339. catch
  340. {
  341. return NoContent();
  342. }
  343. }
  344. [Route("refund")]
  345. [HttpPost]
  346. public async Task<IActionResult> Refund()
  347. {
  348. try
  349. {
  350. var notify = await _client.ExecuteAsync<LianLianPayRefundNotifyResponse>(Request);
  351. Console.WriteLine("NoRefund: " + notify.NoRefund);
  352. return LianLianPayNotifyResult.Success;
  353. }
  354. catch
  355. {
  356. return NoContent();
  357. }
  358. }
  359. }
  360. #endregion
  361. #region 银联支付异步通知
  362. [Route("notify/unionpay")]
  363. public class UnionPayNotifyController : Controller
  364. {
  365. private readonly UnionPayNotifyClient _client = null;
  366. public UnionPayNotifyController(UnionPayNotifyClient client)
  367. {
  368. _client = client;
  369. }
  370. /// <summary>
  371. /// 网关支付 - 跳转网关页面支付通知
  372. /// </summary>
  373. /// <returns></returns>
  374. [Route("frontconsume62")]
  375. [HttpPost]
  376. public async Task<IActionResult> FrontConsume62()
  377. {
  378. try
  379. {
  380. var notify = await _client.ExecuteAsync<UnionPayForm_6_2_FrontConsumeNotifyResponse>(Request);
  381. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  382. return UnionPayNotifyResult.Ok;
  383. }
  384. catch
  385. {
  386. return NoContent();
  387. }
  388. }
  389. }
  390. #endregion
  391. }