Exemplo n.º 1
0
 public IActionResult PagePayReturn()
 {
     try
     {
         var notify = _notifyClient.Execute <AlipayTradePagePayReturnResponse>(Request);
         return(Content("success", "text/plain"));
     }
     catch
     {
         return(Content("error", "text/plain"));
     }
 }
Exemplo n.º 2
0
        public IActionResult PagePay()
        {
            try
            {
                var notify = _client.Execute <AlipayTradePagePayNotifyResponse>(Request);
                if ("TRADE_SUCCESS" == notify.TradeStatus)
                {
                    Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);

                    return(Content("success", "text/plain"));
                }
                return(NoContent());
            }
            catch
            {
                return(NoContent());
            }
        }
Exemplo n.º 3
0
        public IActionResult WapPayAsync()
        {
            // var log = new Logs
            //{
            //    Content = "活动预约,支付宝回调唤起",
            //    UserId = 1,
            //    UserName = "******",
            //    IpAddress = HttpWeb.Ip,
            //};
            //Resolve<IBookingSignupOrderService>().Log("活动预约,支付宝回调唤起",LogsLevel.Success);
            try
            {
                var config  = Ioc.Resolve <IAutoConfigService>().GetValue <AlipayPaymentConfig>();
                var _client = new AlipayNotifyClient("RSA2", config.RsaAlipayPublicKey);

                var notify       = _client.Execute <AlipayTradeWapPayNotifyResponse>(Request);
                var aliPayConfig = Resolve <IAutoConfigService>().GetValue <AlipayPaymentConfig>();

                // 返回的商户号要与配置中的相同
                if (aliPayConfig.AppId == notify.AppId) // 支付状态为成功
                {
                    if ("TRADE_SUCCESS" == notify.TradeStatus)
                    {
                        var payId = notify.PassbackParams.ConvertToLong(0); // 通过支付宝获取订单Id参数
                        var pay   = Resolve <IPayService>().GetSingle(payId);

                        if (pay != null)
                        {
                            // 如果支付金额同
                            if (pay.Amount.EqualsDigits(notify.ReceiptAmount.ToDecimal()))
                            {
                                pay.ResponseTime = DateTime.Now;
                                pay.Message      = "回调成功," + notify.ToJson();
                                pay.PayType      = PayType.AlipayWap;
                                Resolve <IPayService>().AfterPay(pay, true);

                                Resolve <IBookingSignupService>()
                                .AfterPaySuccess(new List <object> {
                                    pay.PayExtension.TradeNo
                                });
                            }
                            else
                            {
                                pay.ResponseTime = DateTime.Now;
                                pay.Message      = "回调成功,支付金额不相符." + notify.ToJson();
                                pay.PayType      = PayType.AlipayWap;
                                Resolve <IPayService>().AfterPay(pay, false);
                            }
                        }

                        return(Content("success", "text/plain"));
                    }
                }
                // 如果支付状态为成功

                return(NoContent());
            }
            catch (Exception ex)
            {
                Resolve <IBookingSignupOrderService>().Log("WapPayAsync=>" + ex.Message, LogsLevel.Error);
                return(NoContent());
            }
        }
Exemplo n.º 4
0
        public IActionResult WapPayAsync()
        {
            var log = new Logs
            {
                Content   = "支付宝回调唤起",
                UserId    = 1,
                UserName  = "******",
                IpAddress = HttpWeb.Ip
            };

            try
            {
                //Resolve<IPayService>().Log("在回调中执行pay中的预留方法  try");
                var config  = Ioc.Resolve <IAutoConfigService>().GetValue <AlipayPaymentConfig>();
                var _client = new AlipayNotifyClient("RSA2", config.RsaAlipayPublicKey);

                var notify = _client.Execute <AlipayTradeWapPayNotifyResponse>(Request);
                log.Content += ",支付宝回调唤起notify=>" + notify.ToJsons();
                Resolve <ILogsService>().Add(log);

                var aliPayConfig = Resolve <IAutoConfigService>().GetValue <AlipayPaymentConfig>();
                //Resolve<IPayService>().Log("在回调中执行pay中的预留方法  aliPayConfig");
                // 返回的商户号要与配置中的相同
                if (aliPayConfig.AppId == notify.AppId
                    ) //Resolve<IPayService>().Log("在回调中执行pay中的预留方法aliPayConfig.AppId == notify.AppId");
                {
                    // 支付状态为成功
                    if ("TRADE_SUCCESS" == notify.TradeStatus)
                    {
                        var payId = notify.PassbackParams.ConvertToLong(0); // 通过支付宝获取订单Id参数
                        var pay   = Resolve <IPayService>().GetSingle(payId);
                        //Resolve<IPayService>().Log("在回调中执行pay中的预留方法TRADE_SUCCESS");
                        if (pay != null)
                        {
                            //Resolve<ILogsService>().Log("在回调中执行pay != null");
                            // 如果支付金额同
                            if (pay.Amount.EqualsDigits(notify.ReceiptAmount.ToDecimal()))
                            {
                                // Resolve<ILogsService>().Log("在回调中执行支付金额同");
                                pay.ResponseTime   = DateTime.Now;
                                pay.Message        = notify.ToJson();
                                pay.ResponseSerial = notify.TradeNo;
                                pay.PayType        = PayType.AlipayWap;
                                Resolve <IPayService>().AfterPay(pay, true);
                                //Resolve<IPayService>().Log("在回调中执行pay中的预留方法pay.PayExtension.AfterSuccess != null!");
                                if (pay.PayExtension.AfterSuccess != null)
                                {
                                    //Resolve<IPayService>().Log("在回调中执行pay中的预留方法!");

                                    if (pay.PayExtension.AfterSuccess?.Parameter != null)
                                    {
                                        // Resolve<IPayService>().Log($@"在回调中执行pay中的预留方法!有参数{pay.PayExtension.AfterSuccess?.ServiceName}
                                        //    {pay.PayExtension.AfterSuccess?.Method}
                                        //   {pay.PayExtension.AfterSuccess?.Parameter.ToJsons()}");

                                        dynamic a = pay.PayExtension.AfterSuccess?.ServiceName;

                                        Dynamics.DynamicService.ResolveMethod(
                                            pay.PayExtension.AfterSuccess?.ServiceName,
                                            pay.PayExtension.AfterSuccess?.Method,
                                            pay.PayExtension.AfterSuccess?.Parameter);
                                    }
                                    else
                                    {
                                        //Resolve<IPayService>().Log($@"在回调中执行pay中的预留方法!无参数{pay.PayExtension.AfterSuccess?.ServiceName}
                                        //    {pay.PayExtension.AfterSuccess?.Method}");
                                        Dynamics.DynamicService.ResolveMethod(
                                            pay.PayExtension.AfterSuccess?.ServiceName,
                                            pay.PayExtension.AfterSuccess?.Method);
                                    }
                                }
                            }
                            else
                            {
                                pay.ResponseTime = DateTime.Now;
                                pay.Message      = "回调成功,支付金额不相符" + notify.ToJson();
                                pay.PayType      = PayType.AlipayWap;
                                Resolve <IPayService>().AfterPay(pay, false);
                            }
                        }

                        return(Content("success", "text/plain"));
                    }
                }
                // 如果支付状态为成功

                return(NoContent());
            }
            catch (Exception ex)
            {
                log.Content += $",异常=>{ex.Message}";
                Resolve <ILogsService>().Add(log);
                return(NoContent());
            }
        }