AlipayReturnController.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Threading.Tasks;
  2. using Essensoft.AspNetCore.Payment.Alipay;
  3. using Essensoft.AspNetCore.Payment.Alipay.Notify;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Options;
  6. namespace WebApplicationSample.Controllers
  7. {
  8. [Route("alipay/return")]
  9. public class AlipayReturnController : Controller
  10. {
  11. private readonly IAlipayNotifyClient _client;
  12. private readonly IOptions<AlipayOptions> _optionsAccessor;
  13. public AlipayReturnController(IAlipayNotifyClient client, IOptions<AlipayOptions> optionsAccessor)
  14. {
  15. _client = client;
  16. _optionsAccessor = optionsAccessor;
  17. }
  18. /// <summary>
  19. /// 电脑网站支付 - 同步跳转
  20. /// </summary>
  21. [Route("pagepay")]
  22. [HttpGet]
  23. public async Task<IActionResult> PagePay()
  24. {
  25. try
  26. {
  27. var notify = await _client.ExecuteAsync<AlipayTradePagePayReturn>(Request, _optionsAccessor.Value);
  28. ViewData["response"] = "支付成功";
  29. return View();
  30. }
  31. catch
  32. {
  33. ViewData["response"] = "出现错误";
  34. return View();
  35. }
  36. }
  37. /// <summary>
  38. /// 手机网站支付 - 同步跳转
  39. /// </summary>
  40. [HttpGet]
  41. [Route("wappay")]
  42. public async Task<IActionResult> WapPay()
  43. {
  44. try
  45. {
  46. var notify = await _client.ExecuteAsync<AlipayTradeWapPayReturn>(Request, _optionsAccessor.Value);
  47. ViewData["response"] = "支付成功";
  48. return View();
  49. }
  50. catch
  51. {
  52. ViewData["response"] = "出现错误";
  53. return View();
  54. }
  55. }
  56. }
  57. }