1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using System;
- using System.Threading.Tasks;
- using Essensoft.AspNetCore.Payment.WeChatPay;
- using Essensoft.AspNetCore.Payment.WeChatPay.V3;
- using Essensoft.AspNetCore.Payment.WeChatPay.V3.Notify;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Options;
- namespace WebApplicationSample.Controllers
- {
- [Route("wechatpay/v3/notify")]
- public class WeChatPayV3NotifyController : Controller
- {
- private readonly IWeChatPayNotifyClient _client;
- private readonly IOptions<WeChatPayOptions> _optionsAccessor;
- public WeChatPayV3NotifyController(IWeChatPayNotifyClient client, IOptions<WeChatPayOptions> optionsAccessor)
- {
- _client = client;
- _optionsAccessor = optionsAccessor;
- }
- /// <summary>
- /// 支付结果通知
- /// </summary>
- [Route("transactions")]
- [HttpPost]
- public async Task<IActionResult> Transactions()
- {
- try
- {
- var notify = await _client.ExecuteV3Async<WeChatPayTransactionsNotify>(Request, _optionsAccessor.Value);
- if (notify.TradeState == WeChatPayTradeState.Success)
- {
- Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
- return WeChatPayNotifyResult.Success;
- }
- return WeChatPayNotifyResult.Failure;
- }
- catch
- {
- return WeChatPayNotifyResult.Failure;
- }
- }
- }
- }
|