using Essensoft.Paylink.WeChatPay; using Essensoft.Paylink.WeChatPay.V2; using Essensoft.Paylink.WeChatPay.V2.Notify; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Newtonsoft.Json; namespace DS.TestResult.PayNotify { /// /// 微信支付异步通知 /// [Route("Notify/[controller]/[action]")] public class WeChatPayController : ControllerBase { private readonly IWeChatPayNotifyClient _client; private readonly IOptions _optionsAccessor; /// /// 构造函数 /// public WeChatPayController( IWeChatPayNotifyClient client , IOptions optionsAccessor) { _client = client; _optionsAccessor = optionsAccessor; } /// /// 统一下单支付结果通知 /// [HttpPost] public async Task Unifiedorder() { try { var notify = await _client.ExecuteAsync(Request, _optionsAccessor.Value); if (notify.ReturnCode == WeChatPayCode.Success) { // await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.WeChatPayNotice, JsonConvert.SerializeObject(notify)); return WeChatPayNotifyResult.Success; } // NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "微信支付成功回调", JsonConvert.SerializeObject(notify)); return NoContent(); } catch (Exception ex) { // NLogUtil.WriteAll(LogLevel.Trace, LogType.Order, "微信支付成功回调", "统一下单支付结果通知", ex); return NoContent(); } } /// /// 退款结果通知 /// [HttpPost] public async Task Refund() { try { var notify = await _client.ExecuteAsync(Request, _optionsAccessor.Value); // NLogUtil.WriteAll(LogLevel.Trace, LogType.Refund, "微信退款结果通知", JsonConvert.SerializeObject(notify)); if (notify.ReturnCode == WeChatPayCode.Success) if (notify.RefundStatus == WeChatPayCode.Success) { //Console.WriteLine("OutTradeNo: " + notify.OutTradeNo); var memo = JsonConvert.SerializeObject(notify); // await _billRefundServices.UpdateAsync(p => new CoreCmsBillRefund { memo = memo }, p => p.refundId == notify.OutTradeNo); return WeChatPayNotifyResult.Success; } return NoContent(); } catch (Exception ex) { // NLogUtil.WriteAll(LogLevel.Trace, LogType.Refund, "微信退款结果通知", "退款结果通知", ex); return NoContent(); } } } }