NotifyController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. namespace WebApplicationSample.Controllers
  17. {
  18. #region 支付宝异步通知
  19. [Route("notify/alipay")]
  20. public class AlipayNotifyController : Controller
  21. {
  22. private readonly IAlipayNotifyClient _client = null;
  23. public AlipayNotifyController(IAlipayNotifyClient 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. /// APP支付异步通知
  52. /// </summary>
  53. /// <returns></returns>
  54. [Route("apppay")]
  55. [HttpPost]
  56. public async Task<IActionResult> AppPay()
  57. {
  58. try
  59. {
  60. var notify = await _client.ExecuteAsync<AlipayTradeAppPayNotifyResponse>(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. /// 电脑网站支付异步通知
  75. /// </summary>
  76. /// <returns></returns>
  77. [Route("pagepay")]
  78. [HttpPost]
  79. public async Task<IActionResult> PagePay()
  80. {
  81. try
  82. {
  83. var notify = await _client.ExecuteAsync<AlipayTradePagePayNotifyResponse>(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("wappay")]
  101. [HttpPost]
  102. public async Task<IActionResult> WapPay()
  103. {
  104. try
  105. {
  106. var notify = await _client.ExecuteAsync<AlipayTradeWapPayNotifyResponse>(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. }
  120. #endregion
  121. #region 微信支付异步通知
  122. [Route("notify/wechatpay")]
  123. public class WeChatPayNotifyController : Controller
  124. {
  125. private readonly IWeChatPayNotifyClient _client = null;
  126. public WeChatPayNotifyController(IWeChatPayNotifyClient client)
  127. {
  128. _client = client;
  129. }
  130. /// <summary>
  131. /// 统一下单支付结果通知
  132. /// </summary>
  133. /// <returns></returns>
  134. [Route("unifiedorder")]
  135. [HttpPost]
  136. public async Task<IActionResult> Unifiedorder()
  137. {
  138. try
  139. {
  140. var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotifyResponse>(Request);
  141. if (notify.ReturnCode == "SUCCESS")
  142. {
  143. if (notify.ResultCode == "SUCCESS")
  144. {
  145. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  146. return WeChatPayNotifyResult.Success;
  147. }
  148. }
  149. return NoContent();
  150. }
  151. catch
  152. {
  153. return NoContent();
  154. }
  155. }
  156. /// <summary>
  157. /// 退款结果通知
  158. /// </summary>
  159. /// <returns></returns>
  160. [Route("refund")]
  161. [HttpPost]
  162. public async Task<IActionResult> Refund()
  163. {
  164. try
  165. {
  166. var notify = await _client.ExecuteAsync<WeChatPayRefundNotifyResponse>(Request);
  167. if (notify.ReturnCode == "SUCCESS")
  168. {
  169. if (notify.RefundStatus == "SUCCESS")
  170. {
  171. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  172. return WeChatPayNotifyResult.Success;
  173. }
  174. }
  175. return NoContent();
  176. }
  177. catch
  178. {
  179. return NoContent();
  180. }
  181. }
  182. }
  183. #endregion
  184. #region QQ钱包异步通知
  185. [Route("notify/qpay")]
  186. public class QPayNotifyController : Controller
  187. {
  188. private readonly IQPayNotifyClient _client = null;
  189. public QPayNotifyController(IQPayNotifyClient client)
  190. {
  191. _client = client;
  192. }
  193. /// <summary>
  194. /// 统一下单支付结果通知
  195. /// </summary>
  196. /// <returns></returns>
  197. [Route("unifiedorder")]
  198. [HttpPost]
  199. public async Task<IActionResult> Unifiedorder()
  200. {
  201. try
  202. {
  203. var notify = await _client.ExecuteAsync<QPayUnifiedOrderNotifyResponse>(Request);
  204. if ("SUCCESS" == notify.TradeState)
  205. {
  206. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  207. return QPayNotifyResult.Success;
  208. }
  209. return NoContent();
  210. }
  211. catch
  212. {
  213. return NoContent();
  214. }
  215. }
  216. /// <summary>
  217. /// 付款码支付结果通知
  218. /// </summary>
  219. /// <returns></returns>
  220. [Route("micropay")]
  221. [HttpPost]
  222. public async Task<IActionResult> MicroPay()
  223. {
  224. try
  225. {
  226. var notify = await _client.ExecuteAsync<QPayMicroPayNotifyResponse>(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. }
  240. #endregion
  241. #region 京东支付异步通知
  242. [Route("notify/jdpay")]
  243. public class JDPayNotifyController : Controller
  244. {
  245. private readonly IJDPayNotifyClient _client = null;
  246. public JDPayNotifyController(IJDPayNotifyClient client)
  247. {
  248. _client = client;
  249. }
  250. [Route("async")]
  251. [HttpPost]
  252. public async Task<IActionResult> Async()
  253. {
  254. try
  255. {
  256. var notify = await _client.ExecuteAsync<JDPayAsyncNotifyResponse>(Request);
  257. Console.WriteLine("TradeNum: " + notify.TradeNum + " tradeType :" + notify.TradeType);// notify.TradeType 0-消费 1-退款
  258. return JDPayNotifyResult.Success;
  259. }
  260. catch
  261. {
  262. return NoContent();
  263. }
  264. }
  265. [Route("defraypay")]
  266. [HttpPost]
  267. public async Task<IActionResult> DefrayPay()
  268. {
  269. try
  270. {
  271. var notify = await _client.ExecuteAsync<JDPayDefrayPayNotifyResponse>(Request);
  272. Console.WriteLine("trade_no: " + notify.TradeNo + " trade_amount :" + notify.TradeAmount);
  273. return JDPayNotifyResult.Success;
  274. }
  275. catch
  276. {
  277. return NoContent();
  278. }
  279. }
  280. }
  281. #endregion
  282. #region 连连支付异步通知
  283. [Route("notify/lianlianpay")]
  284. public class LianLianPayNotifyController : Controller
  285. {
  286. private readonly ILianLianPayNotifyClient _client = null;
  287. public LianLianPayNotifyController(ILianLianPayNotifyClient client)
  288. {
  289. _client = client;
  290. }
  291. [Route("receivemoney")]
  292. [HttpPost]
  293. public async Task<IActionResult> ReceiveMoney()
  294. {
  295. try
  296. {
  297. var notify = await _client.ExecuteAsync<LianLianPayReceiveMoneyNotifyResponse>(Request);
  298. Console.WriteLine("NoOrder: " + notify.NoOrder);
  299. return LianLianPayNotifyResult.Success;
  300. }
  301. catch
  302. {
  303. return NoContent();
  304. }
  305. }
  306. [Route("refund")]
  307. [HttpPost]
  308. public async Task<IActionResult> Refund()
  309. {
  310. try
  311. {
  312. var notify = await _client.ExecuteAsync<LianLianPayRefundNotifyResponse>(Request);
  313. Console.WriteLine("NoRefund: " + notify.NoRefund);
  314. return LianLianPayNotifyResult.Success;
  315. }
  316. catch
  317. {
  318. return NoContent();
  319. }
  320. }
  321. }
  322. #endregion
  323. #region 银联支付异步通知
  324. [Route("notify/unionpay")]
  325. public class UnionPayNotifyController : Controller
  326. {
  327. private readonly IUnionPayNotifyClient _client = null;
  328. public UnionPayNotifyController(IUnionPayNotifyClient client)
  329. {
  330. _client = client;
  331. }
  332. /// <summary>
  333. /// 网关支付 - 跳转网关页面支付通知
  334. /// </summary>
  335. /// <returns></returns>
  336. [Route("frontconsume62")]
  337. [HttpPost]
  338. public async Task<IActionResult> FrontConsume62()
  339. {
  340. try
  341. {
  342. var notify = await _client.ExecuteAsync<UnionPayForm_6_2_FrontConsumeNotifyResponse>(Request);
  343. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  344. return UnionPayNotifyResult.Ok;
  345. }
  346. catch
  347. {
  348. return NoContent();
  349. }
  350. }
  351. }
  352. #endregion
  353. }