| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 | using System;using System.Threading.Tasks;using Essensoft.AspNetCore.Payment.WeChatPay;using Essensoft.AspNetCore.Payment.WeChatPay.V2;using Essensoft.AspNetCore.Payment.WeChatPay.V2.Notify;using Microsoft.AspNetCore.Mvc;using Microsoft.Extensions.Options;namespace WebApplicationSample.Controllers{    [Route("wechatpay/notify")]    public class WeChatPayNotifyController : Controller    {        private readonly IWeChatPayNotifyClient _client;        private readonly IOptions<WeChatPayOptions> _optionsAccessor;        public WeChatPayNotifyController(IWeChatPayNotifyClient client, IOptions<WeChatPayOptions> optionsAccessor)        {            _client = client;            _optionsAccessor = optionsAccessor;        }        /// <summary>        /// 统一下单支付结果通知        /// </summary>        [Route("unifiedorder")]        [HttpPost]        public async Task<IActionResult> Unifiedorder()        {            try            {                var notify = await _client.ExecuteAsync<WeChatPayUnifiedOrderNotify>(Request, _optionsAccessor.Value);                if (notify.ReturnCode == WeChatPayCode.Success)                {                    if (notify.ResultCode == WeChatPayCode.Success)                    {                        Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);                        return WeChatPayNotifyResult.Success;                    }                }                return WeChatPayNotifyResult.Failure;            }            catch            {                return WeChatPayNotifyResult.Failure;            }        }        /// <summary>        /// 退款结果通知        /// </summary>        [Route("refund")]        [HttpPost]        public async Task<IActionResult> Refund()        {            try            {                var notify = await _client.ExecuteAsync<WeChatPayRefundNotify>(Request, _optionsAccessor.Value);                if (notify.ReturnCode == WeChatPayCode.Success)                {                    if (notify.RefundStatus == WeChatPayCode.Success)                    {                        Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);                        return WeChatPayNotifyResult.Success;                    }                }                return WeChatPayNotifyResult.Failure;            }            catch            {                return WeChatPayNotifyResult.Failure;            }        }    }}
 |