NotifyController.cs 11 KB

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