NotifyController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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;
  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<AlipayTradePrecreateNotify>(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<AlipayTradeAppPayNotify>(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<AlipayTradePagePayNotify>(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<AlipayTradeWapPayNotify>(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;
  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<WeChatPayUnifiedOrderNotify>(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<WeChatPayRefundNotify>(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;
  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<QPayUnifiedOrderNotify>(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<QPayMicroPayNotify>(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("b2cpay")]
  244. [HttpPost]
  245. public async Task<IActionResult> B2CPay()
  246. {
  247. try
  248. {
  249. var notify = await _client.ExecuteAsync<QPayEPayB2CNotify>(Request);
  250. Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
  251. return QPayNotifyResult.Success;
  252. }
  253. catch
  254. {
  255. return NoContent();
  256. }
  257. }
  258. }
  259. #endregion
  260. #region 京东支付异步通知
  261. [Route("notify/jdpay")]
  262. public class JDPayNotifyController : Controller
  263. {
  264. private readonly IJDPayNotifyClient _client;
  265. public JDPayNotifyController(IJDPayNotifyClient client)
  266. {
  267. _client = client;
  268. }
  269. [Route("async")]
  270. [HttpPost]
  271. public async Task<IActionResult> Async()
  272. {
  273. try
  274. {
  275. var notify = await _client.ExecuteAsync<JDPayAsyncNotify>(Request);
  276. Console.WriteLine("TradeNum: " + notify.TradeNum + " tradeType :" + notify.TradeType);// notify.TradeType 0-消费 1-退款
  277. return JDPayNotifyResult.Success;
  278. }
  279. catch
  280. {
  281. return NoContent();
  282. }
  283. }
  284. [Route("defraypay")]
  285. [HttpPost]
  286. public async Task<IActionResult> DefrayPay()
  287. {
  288. try
  289. {
  290. var notify = await _client.ExecuteAsync<JDPayDefrayPayNotify>(Request);
  291. Console.WriteLine("trade_no: " + notify.TradeNo + " trade_amount :" + notify.TradeAmount);
  292. return JDPayNotifyResult.Success;
  293. }
  294. catch
  295. {
  296. return NoContent();
  297. }
  298. }
  299. }
  300. #endregion
  301. #region 连连支付异步通知
  302. [Route("notify/lianlianpay")]
  303. public class LianLianPayNotifyController : Controller
  304. {
  305. private readonly ILianLianPayNotifyClient _client;
  306. public LianLianPayNotifyController(ILianLianPayNotifyClient client)
  307. {
  308. _client = client;
  309. }
  310. [Route("receivemoney")]
  311. [HttpPost]
  312. public async Task<IActionResult> ReceiveMoney()
  313. {
  314. try
  315. {
  316. var notify = await _client.ExecuteAsync<LianLianPayReceiveMoneyNotify>(Request);
  317. Console.WriteLine("NoOrder: " + notify.NoOrder);
  318. return LianLianPayNotifyResult.Success;
  319. }
  320. catch
  321. {
  322. return NoContent();
  323. }
  324. }
  325. [Route("refund")]
  326. [HttpPost]
  327. public async Task<IActionResult> Refund()
  328. {
  329. try
  330. {
  331. var notify = await _client.ExecuteAsync<LianLianPayRefundNotify>(Request);
  332. Console.WriteLine("NoRefund: " + notify.NoRefund);
  333. return LianLianPayNotifyResult.Success;
  334. }
  335. catch
  336. {
  337. return NoContent();
  338. }
  339. }
  340. }
  341. #endregion
  342. #region 银联支付异步通知
  343. [Route("notify/unionpay")]
  344. public class UnionPayNotifyController : Controller
  345. {
  346. private readonly IUnionPayNotifyClient _client;
  347. public UnionPayNotifyController(IUnionPayNotifyClient client)
  348. {
  349. _client = client;
  350. }
  351. /// <summary>
  352. /// 网关支付 - 跳转网关页面支付通知
  353. /// </summary>
  354. /// <returns></returns>
  355. [Route("gatewaypayfrontconsume")]
  356. [HttpPost]
  357. public async Task<IActionResult> GatewayPayFrontConsume()
  358. {
  359. try
  360. {
  361. var notify = await _client.ExecuteAsync<UnionPayGatewayPayFrontConsumeNotify>(Request);
  362. Console.WriteLine("OrderId: " + notify.OrderId + " respCode :" + notify.RespCode);
  363. return UnionPayNotifyResult.Success;
  364. }
  365. catch
  366. {
  367. return NoContent();
  368. }
  369. }
  370. }
  371. #endregion
  372. }