예제 #1
0
        public async Task <IActionResult> Unifiedorder()
        {
            try
            {
                Request.EnableBuffering();

                Request.Body.Seek(0, SeekOrigin.Begin);
                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);
            }
        }
예제 #2
0
        // 付款通知
        public async Task <bool> Notify(long orderId)
        {
            try
            {
                var res = await notifyClient.ExecuteAsync <WeChatPayUnifiedOrderNotify>(
                    App.Context.Request, options.Value);

                if (res.ReturnCode == "SUCCESS" && res.ResultCode == "SUCCESS")
                {
                    logger.LogDebug($"Wepay Notify with: {orderId} SUCCESS");
                    OrderService.Paidup(
                        orderId,
                        res.TransactionId,
                        (decimal)(res.TotalFee / 100.0),
                        res.TimeEnd,
                        PayType.Wechat
                        );
                    return(true);
                }

                logger.LogDebug($"Wepay Notify with: {orderId} FAIL: {res.ErrCode}:{res.ErrCodeDes}");
                return(false);
            }
            catch (Exception ex)
            {
                logger.LogDebug($"Wepay Notify with: {orderId} FAIL: {ex.GetMessage()}");
                return(false);
            }
        }
예제 #3
0
        public async Task <IActionResult> NotifyByOrderNo(string no)
        {
            try
            {
                var notify = await _client.ExecuteAsync <WeChatPayUnifiedOrderNotify>(Request);

                if (notify.ReturnCode == "SUCCESS")
                {
                    if (notify.ResultCode == "SUCCESS")
                    {
                        await _mqService.DirectSend(QueueKeys.PaymentReceived, new PaymentReceived()
                        {
                            Note             = "微信支付成功结果通知",
                            OrderNo          = no,
                            PaymentFeeAmount = int.Parse(notify.TotalFee) / 100M,
                            PaymentMethod    = PaymentMethod.WeChat,
                            PaymentOn        = DateTime.ParseExact(notify.TimeEnd, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture)
                        });

                        return(WeChatPayNotifyResult.Success);
                    }
                }
                return(NoContent());
            }
            catch
            {
                return(NoContent());
            }
        }
        public async Task <IActionResult> Unifiedorder(string no)
        {
            try
            {
                var notify = await _client.ExecuteAsync <WeChatPayUnifiedOrderNotify>(Request, _wechatOptions);

                if (notify.ReturnCode == WeChatPayCode.Success)
                {
                    if (notify.ResultCode == WeChatPayCode.Success)
                    {
                        await _mediator.Publish(new PaymentReceivedEvent
                        {
                            OrderNo       = no,
                            PaymentFee    = notify.TotalFee,
                            PaymentMethod = PaymentMethods.Wechat,
                            PaymentTime   = DateTime.ParseExact(notify.TimeEnd, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture)
                        });

                        return(WeChatPayNotifyResult.Success);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
            }
            return(WeChatPayNotifyResult.Failure);
        }
        public async Task <IActionResult> Unifiedorder()
        {
            var notify = await _client.ExecuteAsync <WeChatPayUnifiedOrderNotify>(Request, _optionsAccessor.Value);

            if (notify.ReturnCode == WeChatPayCode.Success)
            {
                if (notify.ResultCode == WeChatPayCode.Success)
                {
                    return(WeChatPayNotifyResult.Success);
                }
                else
                {
                    var msg = notify.ErrCode + ":" + notify.ErrCodeDes;
                    return(WeChatPayNotifyResult.Success);
                }
            }
            return(NoContent());
        }
예제 #6
0
        public async Task <IActionResult> Transactions()
        {
            try
            {
                var notify = await _client.ExecuteAsync <WeChatPayTransactionsNotify>(Request, _optionsAccessor.Value);

                if (notify.TradeState == WeChatPayTradeState.Success)
                {
                    Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
                    return(WeChatPayNotifyResult.Success);
                }

                return(WeChatPayNotifyResult.Failure);
            }
            catch (WeChatPayException ex)
            {
                Console.WriteLine("出现异常: " + ex.Message);
                return(WeChatPayNotifyResult.Failure);
            }
        }
예제 #7
0
        public async Task <IActionResult> Unifiedorder()
        {
            try
            {
                var notify = await _client.ExecuteAsync <WeChatPayUnifiedOrderNotify>(Request, _optionsAccessor.Value);

                if (notify.ReturnCode == "SUCCESS")
                {
                    if (notify.ResultCode == "SUCCESS")
                    {
                        Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);

                        return(WeChatPayNotifyResult.Success);
                    }
                }
                return(NoContent());
            }
            catch
            {
                return(NoContent());
            }
        }
        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)
                    {
                        _logger.LogInformation("统一下单支付结果通知 => OutTradeNo: " + notify.OutTradeNo);
                        return(WeChatPayNotifyResult.Success);
                    }
                }

                return(WeChatPayNotifyResult.Failure);
            }
            catch (WeChatPayException ex)
            {
                _logger.LogWarning("出现异常: " + ex.Message);
                return(WeChatPayNotifyResult.Failure);
            }
        }
예제 #9
0
        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 (WeChatPayException ex)
            {
                Console.WriteLine("出现异常: " + ex.Message);
                return(WeChatPayNotifyResult.Failure);
            }
        }
예제 #10
0
        public async Task <IActionResult> NotifyByOrderNo(string no)
        {
            try
            {
                var config = await _appSettingService.Get <MiniProgramOptions>();

                var opt = new WeChatPayOptions()
                {
                    AppId  = config.AppId,
                    MchId  = config.MchId,
                    Secret = config.AppSecret,
                    Key    = config.Key
                };

                var notify = await _client.ExecuteAsync <WeChatPayUnifiedOrderNotify>(Request, opt);

                if (notify.ReturnCode == "SUCCESS")
                {
                    if (notify.ResultCode == "SUCCESS")
                    {
                        await _mqService.Send(QueueKeys.PaymentReceived, new PaymentReceived()
                        {
                            Note             = "微信支付成功结果通知",
                            OrderNo          = no,
                            PaymentFeeAmount = notify.TotalFee / 100M,
                            PaymentMethod    = PaymentMethod.WeChat,
                            PaymentOn        = DateTime.ParseExact(notify.TimeEnd, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture)
                        });

                        return(WeChatPayNotifyResult.Success);
                    }
                }
                return(NoContent());
            }
            catch
            {
                return(NoContent());
            }
            finally
            {
                _logger.LogInformation("参数:{@no}", no);
            }
        }
예제 #11
0
        public async Task <IActionResult> Transactions()
        {
            try
            {
                var notify = await _client.ExecuteAsync <WeChatPayTransactionsNotify>(Request, _optionsAccessor.Value);

                if (notify.TradeState == WeChatPayTradeState.Success)
                {
                    _logger.LogInformation("支付结果通知 => OutTradeNo: " + notify.OutTradeNo);
                    return(WeChatPayNotifyResult.Success);
                }

                return(WeChatPayNotifyResult.Failure);
            }
            catch (WeChatPayException ex)
            {
                _logger.LogWarning("出现异常: " + ex.Message);
                return(WeChatPayNotifyResult.Failure);
            }
        }