예제 #1
0
파일: PayResult.cs 프로젝트: iampkm/ebs.pay
        /// <summary>
        /// 校验支付结果请求
        /// </summary>
        /// <param name="data">业务数据报文</param>
        /// <param name="resultInfo">支付结果记录</param>
        /// <returns></returns>
        public override ExecuteResult CheckRequest(string data, PayResultInfo resultInfo)
        {
            var result     = new ExecuteResult();
            var paramsData = new ParameterData();

            paramsData.FromUrl(data);
            var paramsDict = paramsData.GetValues();

            //判断是否有带返回参数
            if (paramsDict.Count == 0)
            {
                result.Status            = ResultStatus.Failure;
                result.Message           = resultInfo.ResultDesc = "支付结果无通知参数";
                resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                PayResultDAL.Update(resultInfo);
                return(result);
            }

            //校验请求报文
            resultInfo.OrderId = paramsData.GetValue("out_trade_no");
            var  aliNotify    = new AlipayNotify();
            bool verifyResult = aliNotify.Verify(paramsDict, paramsData.GetValue("notify_id"), paramsData.GetValue("sign"));

            if (!verifyResult)
            {
                result.Status            = ResultStatus.Failure;
                result.Message           = resultInfo.ResultDesc = "verify failed";
                resultInfo.ExecuteResult = (int)ResultStatus.Failure;
                PayResultDAL.Update(resultInfo);
                return(result);
            }

            result.Status = ResultStatus.Success;
            return(result);
        }
예제 #2
0
        /// <summary>
        /// 通知调用
        /// </summary>
        public ActionResult Notify()
        {
            SortedDictionary <string, string> paras = AlipayCore.GetRequestPost();

            if (paras.Count > 0)//判断是否有带返回参数
            {
                bool verifyResult = AlipayNotify.Verify(paras, Request.Form["notify_id"], Request.Form["sign"], AlipayConfig.SignType, AlipayConfig.Key, AlipayConfig.Code, AlipayConfig.VeryfyUrl, AlipayConfig.Partner);
                if (verifyResult && (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "TRADE_SUCCESS")) //验证成功
                {
                    string   out_trade_no = Request.Form["out_trade_no"];                                                                  //商户订单号
                    string   tradeSN      = Request.Form["trade_no"];                                                                      //支付宝交易号
                    decimal  tradeMoney   = TypeHelper.StringToDecimal(Request.Form["total_fee"]);                                         //交易金额
                    DateTime tradeTime    = TypeHelper.StringToDateTime(Request.Form["gmt_payment"]);                                      //交易时间

                    List <OrderInfo> orderList = new List <OrderInfo>();
                    foreach (string oid in StringHelper.SplitString(StringHelper.SubString(out_trade_no, out_trade_no.Length - 10)))
                    {
                        OrderInfo orderInfo = Orders.GetOrderByOid(TypeHelper.StringToInt(oid));
                        orderList.Add(orderInfo);
                    }
                    decimal allSurplusMoney = 0M;
                    foreach (OrderInfo orderInfo in orderList)
                    {
                        allSurplusMoney += orderInfo.SurplusMoney;
                    }

                    if (orderList.Count > 0 && allSurplusMoney <= tradeMoney)
                    {
                        foreach (OrderInfo orderInfo in orderList)
                        {
                            if (orderInfo.SurplusMoney > 0 && orderInfo.OrderState == (int)OrderState.WaitPaying)
                            {
                                Orders.PayOrder(orderInfo.Oid, OrderState.Confirming, tradeSN, DateTime.Now);
                                OrderActions.CreateOrderAction(new OrderActionInfo()
                                {
                                    Oid        = orderInfo.Oid,
                                    Uid        = orderInfo.Uid,
                                    RealName   = "本人",
                                    ActionType = (int)OrderActionType.Pay,
                                    ActionTime = tradeTime,
                                    ActionDes  = "你使用支付宝支付订单成功,支付宝交易号为:" + tradeSN
                                });
                            }
                        }
                    }

                    return(Content("success"));
                }
                else//验证失败
                {
                    return(Content("fail"));
                }
            }
            else
            {
                return(Content("无通知参数"));
            }
        }
예제 #3
0
        /// <summary>
        /// 阿里支付成功同步回调地址
        /// </summary>
        /// <returns></returns>
        public ActionResult CallBack()
        {
            SortedDictionary <string, string> sPara = GetRequestGet();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                AlipayNotify aliNotify    = new AlipayNotify();
                bool         verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]);

                if (verifyResult)//验证成功
                {
                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表
                    string trade_no     = Request.QueryString["trade_no"];          //支付宝交易号
                    string order_no     = Request.QueryString["out_trade_no"];      //获取订单号
                    string total_fee    = Request.QueryString["total_fee"];         //获取总金额
                    string subject      = Request.QueryString["subject"];           //商品名称、订单名称
                    string body         = Request.QueryString["body"];              //商品描述、订单备注、描述
                    string buyer_email  = Request.QueryString["buyer_email"];       //买家支付宝账号
                    string trade_status = Request.QueryString["trade_status"];      //交易状态

                    if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
                    {
                        //判断该笔订单是否在商户网站中已经做过处理
                        //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                        //如果有做过处理,不执行商户的业务程序
                        BaseResponse br = DBOrderBLL.OrderPaySuccess(order_no, decimal.Parse(total_fee), buyer_email);
                        if (br.IsSuccess)
                        {
                            return(RedirectToAction("success", "order", new { ordercode = order_no }));
                        }
                        else
                        {
                            ViewBag.Msg = "对不起未能成功处理您的订单[" + order_no + "],原因是:" + br.Message;
                            return(View("error"));
                        }
                    }
                    else
                    {
                        ViewBag.Msg = "对不起您的订单[" + order_no + "]支付失败了,交易状态:" + trade_status;
                        Logger.Info(ViewBag.Msg);
                        return(View("error"));
                    }
                }
                else//验证失败
                {
                    ViewBag.Msg = "对不起您的订单[" + Request.QueryString["trade_no"] + "]支付失败了,支付返回数据异常";
                    Logger.Info(ViewBag.Msg);
                    return(View("error"));
                }
            }
            else
            {
                ViewBag.Msg = "对不起您的订单[" + Request.QueryString["trade_no"] + "]订单支付失败了,支付返回参数为空";
                Logger.Info(ViewBag.Msg);
                return(View("error"));
            }
        }
예제 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary <string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                //Notify aliNotify = new Notify();
                AlipayNotify aliNotify = new AlipayNotify();

                //对异步通知进行验签
                bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);
                //对验签结果
                //bool isSign = Aop.Api.Util.AlipaySignature.RSACheckV2(sPara, Config.alipay_public_key ,Config.charset,Config.sign_type,false );

                if (verifyResult && CheckParams()) //验签成功 && 关键业务参数校验成功
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码


                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表

                    //商户订单号
                    string out_trade_no = Request.Form["out_trade_no"];


                    //支付宝交易号
                    string trade_no = Request.Form["trade_no"];

                    //交易状态
                    //在支付宝的业务通知中,只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时,才是买家付款成功。
                    string trade_status = Request.Form["trade_status"];


                    //判断是否在商户网站中已经做过了这次通知返回的处理
                    //如果没有做过处理,那么执行商户的业务程序
                    //如果有做过处理,那么不执行商户的业务程序

                    Response.Write("success");  //请不要修改或删除

                    //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——

                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                }
                else//验证失败
                {
                    Response.Write("fail");
                }
            }
            else
            {
                Response.Write("无通知参数");
            }
        }
예제 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Game.Facade.Log.Write("房卡支付宝支付进来了。。。。");

            SortedDictionary <string, string> sPara = GetRequestPost();

            Game.Facade.Log.Write("参数长度:" + sPara.Count);

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                AlipayNotify aliNotify    = new AlipayNotify();
                bool         verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);

                Game.Facade.Log.Write("verifyResult:" + verifyResult);

                if (verifyResult)//验证成功
                {
                    //商户订单号
                    string out_trade_no = Request.Form["out_trade_no"];

                    Game.Facade.Log.Write("out_trade_no:" + out_trade_no);

                    //支付宝交易号
                    string trade_no = Request.Form["trade_no"];

                    //交易状态
                    string trade_status = Request.Form["trade_status"];

                    Game.Facade.Log.Write("trade_status:" + trade_status);

                    if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
                    {
                        ShareDetialInfo detailInfo = new ShareDetialInfo();
                        detailInfo.OrderID   = out_trade_no;
                        detailInfo.IPAddress = Utility.UserIP;
                        detailInfo.PayAmount = Convert.ToDecimal(Request.Form["total_fee"]);
                        Message msg = FacadeManage.aideTreasureFacade.FilliedOnlineFK(detailInfo, 0);

                        Game.Facade.Log.Write("msg:" + msg.Content);
                    }

                    Response.Write("success");  //请不要修改或删除
                }
                else//验证失败
                {
                    Response.Write("fail");
                }
            }
            else
            {
                Response.Write("无通知参数");
            }
        }
예제 #6
0
        /// <summary>
        /// 返回调用
        /// </summary>
        public ActionResult Return()
        {
            SortedDictionary <string, string> paras = AlipayCore.GetRequestGet();

            if (paras.Count > 0)//判断是否有带返回参数
            {
                bool verifyResult = AlipayNotify.Verify(paras, Request.QueryString["notify_id"], Request.QueryString["sign"], AlipayConfig.SignType, AlipayConfig.Key, AlipayConfig.Code, AlipayConfig.VeryfyUrl, AlipayConfig.Partner);
                if (verifyResult && (Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS")) //验证成功
                {
                    string   out_trade_no = Request.QueryString["out_trade_no"];                                                                         //商户订单号
                    string   tradeSN      = Request.QueryString["trade_no"];                                                                             //支付宝交易号
                    decimal  tradeMoney   = TypeHelper.StringToDecimal(Request.QueryString["total_fee"]);                                                //交易金额
                    DateTime tradeTime    = TypeHelper.StringToDateTime(Request.QueryString["notify_time"]);                                             //交易时间

                    int       oid       = TypeHelper.StringToInt(StringHelper.SubString(out_trade_no, out_trade_no.Length - 10));
                    OrderInfo orderInfo = Orders.GetOrderByOid(oid);
                    if (orderInfo != null && orderInfo.PayMode == 1 && orderInfo.PaySN.Length == 0 && orderInfo.SurplusMoney > 0 && orderInfo.SurplusMoney <= tradeMoney)
                    {
                        Orders.PayOrder(oid, OrderState.Confirming, tradeSN, "alipay", "支付宝", DateTime.Now);
                        OrderActions.CreateOrderAction(new OrderActionInfo()
                        {
                            Oid         = oid,
                            Uid         = orderInfo.Uid,
                            RealName    = "本人",
                            AdminGid    = 1,
                            AdminGTitle = "非管理员",
                            ActionType  = (int)OrderActionType.Pay,
                            ActionTime  = tradeTime,
                            ActionDes   = "你使用支付宝支付订单成功,支付宝交易号为:" + tradeSN
                        });

                        //邮件通知客户
                        if (!string.IsNullOrWhiteSpace(orderInfo.Email))
                        {
                            Emails.SendOrderPayEmail(orderInfo.Email, "支付宝", tradeMoney.ToString(), orderInfo.OSN);
                        }
                    }

                    return(RedirectToAction("payresult", "order", new RouteValueDictionary {
                        { "oid", oid }
                    }));
                }
                else//验证失败
                {
                    return(Content("支付失败"));
                }
            }
            else
            {
                return(Content("支付失败"));
            }
        }
예제 #7
0
        /// <summary>
        /// 阿里异步对账地址
        /// </summary>
        /// <returns></returns>
        public ActionResult Notify()
        {
            SortedDictionary <string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                AlipayNotify aliNotify    = new AlipayNotify();
                bool         verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);

                if (verifyResult)//验证成功
                {
                    //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表
                    string trade_no     = Request.Form["trade_no"];     //支付宝交易号
                    string order_no     = Request.Form["out_trade_no"]; //获取订单号
                    string total_fee    = Request.Form["total_fee"];    //获取总金额
                    string subject      = Request.Form["subject"];      //商品名称、订单名称
                    string body         = Request.Form["body"];         //商品描述、订单备注、描述
                    string buyer_email  = Request.Form["buyer_email"];  //买家支付宝账号
                    string trade_status = Request.Form["trade_status"]; //交易状态

                    if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
                    {
                        //判断该笔订单是否在商户网站中已经做过处理
                        //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                        //如果有做过处理,不执行商户的业务程序
                        BaseResponse br = DBOrderBLL.OrderPaySuccess(order_no, decimal.Parse(total_fee), buyer_email);
                        Logger.Info("Notify-1收到alipay的通知更新订单:" + order_no + "交易状态:" + trade_status);
                    }
                    else
                    {
                        Logger.Info("Notify-2收到alipay的通知更新订单:" + order_no + "交易状态:" + trade_status);
                    }
                    return(Content("success"));  //请不要修改或删除
                }
                else//验证失败
                {
                    return(Content("fail"));
                }
            }
            else
            {
                Logger.Info("Notify-3收到alipay的通知更新订单参数为空");
                return(Content("无通知参数"));
            }
        }
예제 #8
0
        /// <summary>
        /// 通知调用
        /// </summary>
        public ActionResult Notify()
        {
            SortedDictionary <string, string> paras = AlipayCore.GetRequestPost();

            if (paras.Count > 0)//判断是否有带返回参数
            {
                bool verifyResult = AlipayNotify.Verify(paras, Request.Form["notify_id"], Request.Form["sign"], AlipayConfig.SignType, AlipayConfig.Key, AlipayConfig.Code, AlipayConfig.VeryfyUrl, AlipayConfig.Partner);
                if (verifyResult && (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "TRADE_SUCCESS")) //验证成功
                {
                    string   out_trade_no = Request.Form["out_trade_no"];                                                                  //商户订单号
                    string   tradeSN      = Request.QueryString["trade_no"];                                                               //支付宝交易号
                    decimal  tradeMoney   = TypeHelper.StringToDecimal(Request.QueryString["total_fee"]);                                  //交易金额
                    DateTime tradeTime    = TypeHelper.StringToDateTime(Request.QueryString["gmt_payment"]);                               //交易时间

                    int       oid       = TypeHelper.StringToInt(StringHelper.SubString(out_trade_no, out_trade_no.Length - 10));
                    OrderInfo orderInfo = Orders.GetOrderByOid(oid);
                    if (orderInfo != null && orderInfo.PayMode == 1 && orderInfo.PaySN.Length == 0 && orderInfo.SurplusMoney > 0 && orderInfo.SurplusMoney <= tradeMoney)
                    {
                        Orders.PayOrder(oid, OrderState.Confirming, tradeSN, DateTime.Now);
                        OrderActions.CreateOrderAction(new OrderActionInfo()
                        {
                            Oid         = oid,
                            Uid         = orderInfo.Uid,
                            RealName    = "本人",
                            AdminGid    = 1,
                            AdminGTitle = "非管理员",
                            ActionType  = (int)OrderActionType.Pay,
                            ActionTime  = tradeTime,
                            ActionDes   = "你使用支付宝支付订单成功,支付宝交易号为:" + tradeSN
                        });
                    }

                    return(Content("success"));
                }
                else//验证失败
                {
                    return(Content("fail"));
                }
            }
            else
            {
                return(Content("无通知参数"));
            }
        }
예제 #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary <string, string> sPara = GetRequestGet();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                AlipayNotify aliNotify    = new AlipayNotify();
                bool         verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]);

                if (verifyResult)//验证成功
                {
                    //商户订单号
                    string out_trade_no = Request.QueryString["out_trade_no"];

                    //支付宝交易号
                    string trade_no = Request.QueryString["trade_no"];

                    //交易状态
                    string trade_status = Request.QueryString["trade_status"];

                    if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
                    {
                        Response.Write("支付完成<br />");
                    }
                    else
                    {
                        Response.Write("支付结束<br />");
                    }
                }
                else//验证失败
                {
                    Response.Write("验证失败");
                }
            }
            else
            {
                Response.Write("无返回参数");
            }
        }
예제 #10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        SortedDictionary <string, string> sPara = GetRequestPost();

        if (sPara.Count > 0)//判断是否有带返回参数
        {
            AlipayNotify aliNotify    = new AlipayNotify();
            bool         verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);

            if (verifyResult)//验证成功
            {
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //请在这里加上商户的业务逻辑程序代码


                //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表

                //商户订单号

                string out_trade_no = Request.Form["out_trade_no"];

                //支付宝交易号

                string trade_no = Request.Form["trade_no"];

                //交易状态
                string trade_status = Request.Form["trade_status"];


                if (Request.Form["trade_status"] == "TRADE_FINISHED")
                {
                    //判断该笔订单是否在商户网站中已经做过处理
                    //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                    //请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
                    //如果有做过处理,不执行商户的业务程序

                    //注意:
                    //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
                }
                else if (Request.Form["trade_status"] == "TRADE_SUCCESS")
                {
                    //判断该笔订单是否在商户网站中已经做过处理
                    //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                    //请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
                    //如果有做过处理,不执行商户的业务程序

                    //注意:
                    //付款完成后,支付宝系统发送该交易状态通知
                }
                else
                {
                }

                //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——

                Response.Write("success");  //请不要修改或删除

                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
            }
            else//验证失败
            {
                Response.Write("fail");
            }
        }
        else
        {
            Response.Write("无通知参数");
        }
    }
        public ActionResult RefundNotify(FormCollection form)
        {
            if (!(_paymentPluginManager.LoadPluginBySystemName("Nop.Plugin.Payments.AliPay") is AliPayPaymentProcessor processor) || !_paymentPluginManager.IsPluginActive(processor))
            {
                throw new NopException("插件无法加载");
            }
            var aliPayPaymentSettings = _settingService.LoadSetting <AliPayPaymentSettings>(_storeContext.CurrentStore.Id);

            var partner = aliPayPaymentSettings.Partner;

            if (string.IsNullOrEmpty(partner))
            {
                throw new Exception("合作身份者ID 不能为空");
            }

            var key = aliPayPaymentSettings.Key;

            if (string.IsNullOrEmpty(key))
            {
                throw new Exception("MD5密钥不能为空");
            }

            var sellerEmail = aliPayPaymentSettings.SellerEmail;

            if (string.IsNullOrEmpty(sellerEmail))
            {
                throw new Exception("卖家Email 不能为空");
            }

            ///↓↓↓↓↓↓↓ 获取支付宝POST过来通知消息,并以“参数名 = 参数值”的形式组成数组↓↓↓↓↓↓↓↓
            int i;
            var coll      = Request.Form;
            var sortedStr = coll.Keys.ToList();
            SortedDictionary <string, string> sPara = new SortedDictionary <string, string>();

            for (i = 0; i < sortedStr.Count; i++)
            {
                sPara.Add(sortedStr[i], Request.Form[sortedStr[i]]);
            }
            ///↑↑↑↑↑↑↑ 获取支付宝POST过来通知消息,并以“参数名 = 参数值”的形式组成数组↑↑↑↑↑↑↑↑
            if (sPara.Count > 0)//判断是否有带返回参数
            {
                AlipayNotify aliNotify    = new AlipayNotify(partner: partner, key: key, input_charset: "utf-8", sign_type: sPara["sign_type"]);
                var          notify_type  = Request.Form["notify_type"];
                var          notify_id    = Request.Form["notify_id"];
                var          sign         = Request.Form["sign"];
                bool         verifyResult = aliNotify.Verify(sPara, notify_id, sign);

                if (verifyResult)//验证成功
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    //批次号

                    string batch_no = Request.Form["batch_no"];

                    //批量退款数据中转账成功的笔数

                    string success_num = Request.Form["success_num"];

                    //批量退款数据中的详细信息
                    string result_details = Request.Form["result_details"];

                    //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓业务处理↓↓↓↓↓↓↓↓↓↓↓↓↓↓
                    try
                    {
                        string create_time = batch_no.Substring(0, 8);
                        var    refundInfo  = _refundInfoService.GetRefundInfoByBatch_no(batch_no);
                        if (refundInfo != null && refundInfo.OrderId > 0)
                        {
                            if (refundInfo.RefundStatus == RefundStatus.refund || notify_id == refundInfo.Notify_Id)
                            {
                                return(Content("success"));
                            }

                            var result_list = result_details.Split('#');
                            var item        = result_list[0];

                            refundInfo.Notify_Id   = notify_id;
                            refundInfo.Notify_Type = notify_type;

                            var obj            = item.Split('^');
                            var out_Trade_No   = obj[0];                //交易号
                            var AmountToRefund = decimal.Parse(obj[1]); //退款金额
                            var note           = obj[2];                //退款说明

                            var order       = _orderService.GetOrderById(refundInfo.OrderId);
                            var paymentInfo = _paymentInfoService.GetByOrderId(refundInfo.OrderId);
                            if (order != null)
                            {
                                if (note.ToUpper() == "SUCCESS")
                                {
                                    if (AmountToRefund >= 0 && AmountToRefund == refundInfo.AmountToRefund)
                                    {
                                        #region 成功
                                        order.OrderNotes.Add(new OrderNote
                                        {
                                            Note = string.Format("支付宝退款成功,退款编号:{0},退款金额:{1},交易号:{2},说明:{3}", batch_no, AmountToRefund, out_Trade_No, note),
                                            DisplayToCustomer = true,
                                            CreatedOnUtc      = DateTime.UtcNow
                                        });

                                        ////总退款
                                        decimal totalAmountRefunded = Math.Abs(order.RefundedAmount) + AmountToRefund;

                                        order.RefundedAmount = totalAmountRefunded;

                                        if (paymentInfo.Total > order.RefundedAmount)
                                        {
                                            order.PaymentStatus = PaymentStatus.PartiallyRefunded;
                                        }
                                        else
                                        {
                                            order.PaymentStatus = PaymentStatus.Refunded;
                                        }

                                        _orderService.UpdateOrder(order);

                                        ///改变订单状态
                                        _orderProcessingService.CheckOrderStatus(order);

                                        //修改退款记录为退款成功
                                        refundInfo.RefundStatusId = (int)RefundStatus.refund;
                                        refundInfo.RefundOnUtc    = DateTime.Now;
                                        refundInfo.Result_Details = result_details;
                                        _refundInfoService.Update(refundInfo);

                                        ///通知
                                        var orderRefundedStoreOwnerNotificationQueuedEmailId = _workflowMessageService.SendOrderRefundedStoreOwnerNotification(order, AmountToRefund, _localizationSettings.DefaultAdminLanguageId);
                                        if (orderRefundedStoreOwnerNotificationQueuedEmailId.Count > 0 && orderRefundedStoreOwnerNotificationQueuedEmailId[0] > 0)
                                        {
                                            order.OrderNotes.Add(new OrderNote
                                            {
                                                Note = string.Format("\"订单退款\" email (to store owner) has been queued. Queued email identifier: {0}.", orderRefundedStoreOwnerNotificationQueuedEmailId),
                                                DisplayToCustomer = false,
                                                CreatedOnUtc      = DateTime.UtcNow
                                            });
                                            _orderService.UpdateOrder(order);
                                        }
                                        var orderRefundedCustomerNotificationQueuedEmailId = _workflowMessageService.SendOrderRefundedCustomerNotification(order, AmountToRefund, order.CustomerLanguageId);
                                        if (orderRefundedCustomerNotificationQueuedEmailId.Count > 0 && orderRefundedCustomerNotificationQueuedEmailId[0] > 0)
                                        {
                                            order.OrderNotes.Add(new OrderNote
                                            {
                                                Note = string.Format("\"订单退款\" email (to customer) has been queued. Queued email identifier: {0}.", orderRefundedCustomerNotificationQueuedEmailId),
                                                DisplayToCustomer = false,
                                                CreatedOnUtc      = DateTime.UtcNow
                                            });
                                            _orderService.UpdateOrder(order);
                                        }

                                        //已退款事件
                                        _eventPublisher.Publish(new OrderRefundedEvent(order, AmountToRefund));
                                        return(Content("success"));

                                        #endregion
                                    }
                                    else
                                    {
                                        #region 错误
                                        //退款异常
                                        refundInfo.RefundStatusId = (int)RefundStatus.error;
                                        _refundInfoService.Update(refundInfo);
                                        order.OrderNotes.Add(new OrderNote
                                        {
                                            Note = string.Format("支付宝退款异常,退款编号:{0},退款金额:{1},交易号:{2},说明:{3}", batch_no, AmountToRefund, out_Trade_No, "退款金额错误"),
                                            DisplayToCustomer = false,
                                            CreatedOnUtc      = DateTime.UtcNow
                                        });
                                        _orderService.UpdateOrder(order);
                                        return(Content("success"));

                                        #endregion
                                    }
                                }
                            }
                        }
                        throw new Exception(string.Format("支付宝退款通知异常,退款编号:{0},退款金额:{1},交易号:{2},说明:{3}", batch_no, refundInfo.AmountToRefund, refundInfo.Out_Trade_No, "非正常处理"));
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex.Message);
                        return(Content("fail"));
                    }
                    //↑↑↑↑↑↑↑↑↑↑↑↑↑↑业务处理↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
                    ///结束业务处理
                    return(Content("success"));//请不要修改或删除
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                }
                else//验证失败
                {
                    return(Content("fail"));
                }
            }
            else
            {
                return(Content("无通知参数"));
            }
            return(Content(""));
        }
        //[NonAction]
        //public override IList<string> ValidatePaymentForm(IFormCollection form)
        //{
        //    var warnings = new List<string>();

        //    return warnings;
        //}

        //[NonAction]
        //public override ProcessPaymentRequest GetPaymentInfo(IFormCollection form)
        //{
        //    var paymentInfo = new ProcessPaymentRequest();

        //    return paymentInfo;
        //}
        #endregion

        #region 支付请求
        /// <summary>
        /// 接收支付宝支付通知
        /// </summary>
        public ActionResult Notify(FormCollection form)
        {
            if (!(_paymentPluginManager.LoadPluginBySystemName("Nop.Plugin.Payments.AliPay") is AliPayPaymentProcessor processor) || !_paymentPluginManager.IsPluginActive(processor))
            {
                throw new NopException("插件无法加载");
            }
            var aliPayPaymentSettings = _settingService.LoadSetting <AliPayPaymentSettings>(_storeContext.CurrentStore.Id);
            var partner = aliPayPaymentSettings.Partner;

            if (string.IsNullOrEmpty(partner))
            {
                throw new Exception("合作身份者ID 不能为空");
            }
            var key = aliPayPaymentSettings.Key;

            if (string.IsNullOrEmpty(key))
            {
                throw new Exception("MD5密钥不能为空");
            }
            var sellerEmail = aliPayPaymentSettings.SellerEmail;

            if (string.IsNullOrEmpty(sellerEmail))
            {
                throw new Exception("卖家Email 不能为空");
            }
            ///↓↓↓↓↓↓↓ 获取支付宝POST过来通知消息,并以“参数名 = 参数值”的形式组成数组↓↓↓↓↓↓↓↓
            int i;
            var coll      = Request.Form;
            var sortedStr = coll.Keys.ToList();

            SortedDictionary <string, string> sPara = new SortedDictionary <string, string>();

            for (i = 0; i < sortedStr.Count; i++)
            {
                sPara.Add(sortedStr[i], Request.Form[sortedStr[i]]);
            }
            ///↑↑↑↑↑↑↑ 获取支付宝POST过来通知消息,并以“参数名 = 参数值”的形式组成数组↑↑↑↑↑↑↑↑
            if (sPara.Count > 0)//判断是否有带返回参数
            {
                AlipayNotify aliNotify    = new AlipayNotify(partner: partner, key: key, input_charset: "utf-8", sign_type: sPara["sign_type"]);
                var          sign         = Request.Form["sign"];
                var          notify_id    = Request.Form["notify_id"];
                bool         verifyResult = aliNotify.Verify(sPara, notify_id, sign);
                if (verifyResult)//验证成功
                {
                    //商户订单号

                    string out_trade_no = Request.Form["out_trade_no"];

                    //支付宝交易号

                    string trade_no = Request.Form["trade_no"];

                    //交易状态
                    string trade_status = Request.Form["trade_status"];


                    if (coll["trade_status"] == "TRADE_FINISHED" || coll["trade_status"] == "TRADE_SUCCESS")
                    {
                        int orderId;

                        if (int.TryParse(out_trade_no, out orderId))
                        {
                            var order = _orderService.GetOrderById(orderId);

                            if (order != null && _orderProcessingService.CanMarkOrderAsPaid(order))
                            {
                                //修改订单状态
                                _orderProcessingService.MarkOrderAsPaid(order);
                                //添加付款信息
                                var paymentInfo = new PaymentInfo()
                                {
                                    OrderId       = orderId,
                                    Name          = processor.PluginDescriptor.SystemName,
                                    PaymentGuid   = Guid.NewGuid(),
                                    Trade_no      = trade_no,
                                    Total         = decimal.Parse(Request.Form["price"]),
                                    Trade_status  = Request.Form["trade_status"],
                                    Buyer_email   = Request.Form["buyer_email"],
                                    Buyer_id      = Request.Form["buyer_id"],
                                    Seller_email  = Request.Form["seller_email"],
                                    Seller_id     = Request.Form["seller_id"],
                                    Note          = Request.Form["subject"],
                                    Out_Trade_No  = Request.Form["trade_no"],
                                    CreateDateUtc = DateTime.Now,
                                };
                                _paymentInfoService.Insert(paymentInfo);
                            }
                        }
                    }
                    return(Content("success")); //请不要修改或删除
                }
                else //验证失败
                {
                    var logStr = string.Format("MD5:notify_id={0},sign={1}", notify_id, sign);
                    _logger.Error(logStr);
                    return(Content("fail"));
                }
            }
            return(Content("无通知参数"));
        }
예제 #13
0
        public string AlipayPayNotify()
        {
            LogHelper.SaveFileLog("AlipayPayNotify支付宝回调", "start");
            Dictionary <string, string> dicParam = GetRequestPost();

            //回调通知参数为空
            if (dicParam.Count == 0)
            {
                LogHelper.SaveFileLog("AlipayPayNotify支付宝回调", "无通知参数");
                return("fail");
            }
            AlipayNotify aliNotify = new AlipayNotify();
            //获取验签结果
            bool verifyResult = aliNotify.Verify(dicParam, dicParam["notify_id"], dicParam["sign"]);

            //验签失败
            if (!verifyResult)
            {
                LogHelper.SaveFileLog("AlipayPayNotify支付宝回调", "验签失败");
                return("fail");
            }

            //商户订单号
            string out_trade_no = dicParam["out_trade_no"];
            //支付宝交易号
            string trade_no = dicParam["trade_no"];
            //交易状态
            string trade_status = dicParam["trade_status"];

            if (trade_status == "TRADE_FINISHED")
            {
                LogHelper.SaveFileLog("AlipayPayNotify支付宝回调", "trade_status:" + trade_status);
                return("success");
                //判断该笔订单是否在商户网站中已经做过处理
                //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                //如果有做过处理,不执行商户的业务程序

                //注意:
                //该种交易状态只在两种情况下出现
                //1、开通了普通即时到账,买家付款成功后。
                //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。
            }
            else if (trade_status == "TRADE_SUCCESS")
            {
                try
                {
                    //OrderService.PayOrderNotify(out_trade_no, trade_no);
                    return("success");
                }
                catch (Exception ex)
                {
                    LogHelper.SaveFileLog("AlipayPayNotify支付宝回调", "更新订单状态失败->Exception:" + ex.Message);
                    return("fail");
                }
            }
            else
            {
                LogHelper.SaveFileLog("AlipayPayNotify支付宝回调", "支付失败->trade_status:" + trade_status);
                return("fail");
            }
        }
예제 #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        SortedDictionary <string, string> sPara = GetRequestGet();

        if (sPara.Count > 0)//判断是否有带返回参数
        {
            AlipayNotify aliNotify    = new AlipayNotify();
            bool         verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]);

            if (verifyResult)//验证成功
            {
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //请在这里加上商户的业务逻辑程序代码


                //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表

                //商户订单号

                string out_trade_no = Request.QueryString["out_trade_no"];

                //支付宝交易号

                string trade_no = Request.QueryString["trade_no"];

                //交易状态
                string trade_status = Request.QueryString["trade_status"];

                OrderInfo orderInfo = OrderHelper.GetOrderInfo(out_trade_no);
                if ((Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS") && orderInfo != null)
                {
                    //判断该笔订单是否在商户网站中已经做过处理
                    //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                    //如果有做过处理,不执行商户的业务程序
                    if (orderInfo.CheckAction(OrderActions.SELLER_CONFIRM_PAY))
                    {
                        if (OrderHelper.ConfirmPay(orderInfo))
                        {
                            Response.Write("<script>alert('订单付款成功');location.href='/Admin/productdl/AgentOrders.aspx'</script>");
                        }
                        else
                        {
                            Response.Write("<script>alert('订单付款失败');location.href='/Admin/productdl/AgentOrders.aspx'</script>");
                        }
                    }
                }
                else
                {
                    Response.Write("trade_status=" + Request.QueryString["trade_status"]);
                }



                //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——

                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
            }
            else//验证失败
            {
                Response.Write("验证失败");
            }
        }
        else
        {
            Response.Write("无返回参数");
        }
    }
예제 #15
0
        // 同步调用,只发生一次
        // GET: Payment/AlipayReturn
        public ActionResult AlipayReturn()
        {
            SortedDictionary <string, string> sPara = GetRequestGet();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                AlipayNotify aliNotify    = new AlipayNotify();
                bool         verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]);

                if (true)//验证成功
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码

                    string notify_time  = Request.QueryString["notify_time"];                  //通知时间
                    string notify_type  = "";                                                  //Request.Form["notify_type"]; //通知类型
                    string notify_id    = Request.QueryString["notify_id"];                    //通知校验ID
                    string sign_type    = Request.QueryString["sign_type"];                    //签名方式
                    string sign         = Request.QueryString["sign"];                         //签名
                    string out_trade_no = Request.QueryString["out_trade_no"];                 //商户订单号
                    string subject      = Request.QueryString["subject"];                      //商品名称
                    string payment_type = Request.QueryString["payment_type"];                 //支付类型
                    string trade_no     = Request.QueryString["trade_no"];                     //支付宝交易号
                    string trade_status = Request.QueryString["trade_status"];                 //交易状态
                    string gmt_create   = DateTime.Now.ToString(CultureInfo.InvariantCulture); //交易创建时间

                    string gmt_payment = DateTime.Now.ToString(CultureInfo.InvariantCulture);  //交易付款时间

                    string gmt_close = DateTime.Now.ToString(CultureInfo.InvariantCulture);    //交易关闭时间

                    string  seller_email       = Request.QueryString["seller_email"];          //卖家支付宝账号
                    string  seller_id          = Request.QueryString["seller_id"];             //卖家支付宝账户号
                    string  buyer_email        = Request.QueryString["buyer_email"];           //买家支付宝账号
                    string  buyer_id           = Request.QueryString["buyer_id"];              //买家支付宝账户号
                    string  total_fee          = Request.QueryString["total_fee"];             //交易金额
                    string  body               = Request.QueryString["body"];                  //商品描述
                    string  discount           = Request.QueryString["discount"];              //折扣
                    string  business_scene     = Request.QueryString["business_scene"];        //是否扫码支付
                    string  extra_common_param = Request.QueryString["extra_common_param"];    //公用回传参数
                    JObject jo      = JObject.Parse(extra_common_param);
                    string  user_id = jo["UserId"].ToString();
                    string  exId    = jo["ExId"].ToString();
                    string  address = jo["Address"].ToString();
                    string  deposit = jo["Deposit"].ToString();
                    string  method  = jo["Method"].ToString();

                    if (subject.IndexOf("兑换订单", StringComparison.Ordinal) > -1)  //兑换订单
                    {
                        //ExchangeConfirm(user_id, exId, address, deposit, method);
                    }
                    else
                    {
                        Recharge(user_id, subject, total_fee, out_trade_no, body);
                    }


                    if (Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS")
                    {
                        //判断该笔订单是否在商户网站中已经做过处理
                        //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                        //如果有做过处理,不执行商户的业务程序
                        string message = "支付成功";
                    }
                    else
                    {
                        string message = "支付失败";
                    }

                    //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——

                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                }
                else//验证失败
                {
                    string message = ("验证失败");
                }
            }
            else
            {
                string message = ("无返回参数");
            }
            return(View());
        }
예제 #16
0
        public ActionResult AlipayNotify()
        {
            SortedDictionary <string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                AlipayNotify aliNotify    = new AlipayNotify();
                bool         verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);
                try
                {
                    if (verifyResult)//验证成功
                    {
                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                        //请在这里加上商户的业务逻辑程序代码


                        //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                        //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表
                        string  extra_common_param = Request.Form["extra_common_param"]; //公用回传参数
                        JObject jo           = JObject.Parse(extra_common_param);
                        string  user_id      = jo["UserId"].ToString();
                        string  exId         = jo["ExId"].ToString();
                        string  address      = jo["Address"].ToString();
                        string  deposit      = jo["Deposit"].ToString();
                        string  method       = jo["Method"].ToString();
                        string  notify_time  = Request.Form["notify_time"];                         //通知时间
                        string  notify_type  = "";                                                  //Request.Form["notify_type"]; //通知类型
                        string  notify_id    = Request.Form["notify_id"];                           //通知校验ID
                        string  sign_type    = Request.Form["sign_type"];                           //签名方式
                        string  sign         = Request.Form["sign"];                                //签名
                        string  out_trade_no = Request.Form["out_trade_no"];                        //商户订单号
                        string  subject      = Request.Form["subject"];                             //商品名称
                        string  payment_type = Request.Form["payment_type"];                        //支付类型
                        string  trade_no     = Request.Form["trade_no"];                            //支付宝交易号
                        string  trade_status = Request.Form["trade_status"];                        //交易状态
                        string  gmt_create   = DateTime.Now.ToString(CultureInfo.InvariantCulture); //交易创建时间

                        string gmt_payment = DateTime.Now.ToString(CultureInfo.InvariantCulture);   //交易付款时间

                        string gmt_close = DateTime.Now.ToString(CultureInfo.InvariantCulture);     //交易关闭时间

                        string seller_email   = Request.Form["seller_email"];                       //卖家支付宝账号
                        string seller_id      = Request.Form["seller_id"];                          //卖家支付宝账户号
                        string buyer_email    = Request.Form["buyer_email"];                        //买家支付宝账号
                        string buyer_id       = Request.Form["buyer_id"];                           //买家支付宝账户号
                        string total_fee      = Request.Form["total_fee"];                          //交易金额
                        string body           = Request.Form["body"];                               //商品描述
                        string discount       = Request.Form["discount"];                           //折扣
                        string business_scene = Request.Form["business_scene"];                     //是否扫码支付


                        Transactions transactions = new Transactions
                        {
                            UserId           = user_id,
                            NotifyTime       = Convert.ToDateTime(notify_time),
                            NotifyType       = notify_type,
                            NotifyId         = notify_id,
                            SignType         = sign_type,
                            Sign             = sign,
                            OutTradeNo       = out_trade_no,
                            Subject          = subject,
                            PaymentType      = payment_type,
                            TradeNo          = trade_no,
                            TradeStatus      = trade_status,
                            GmtCreate        = Convert.ToDateTime(gmt_create),
                            GmtPayment       = Convert.ToDateTime(gmt_payment),
                            GmtClose         = Convert.ToDateTime(gmt_close),
                            SellerEmail      = seller_email,
                            SellerId         = seller_id,
                            BuyerEmail       = buyer_email,
                            BuyerId          = buyer_id,
                            TotalFee         = total_fee,
                            Body             = body,
                            Discount         = discount,
                            BusinessScene    = business_scene,
                            ExtraCommonParam = extra_common_param,
                            Status           = 1
                        };
                        _transactionsService.Add(transactions);


                        if (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "TRADE_SUCCESS")  //在指定时间段内未支付时关闭的交易;在交易完成全额退款成功时关闭的交易。//交易成功,且可对该交易做操作,如:多级分润、退款等。
                        {
                            //判断该笔订单是否在商户网站中已经做过处理
                            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                            //如果有做过处理,不执行商户的业务程序

                            //注意:
                            //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。
                            if (subject.IndexOf("兑换订单", StringComparison.Ordinal) > -1)  //兑换订单
                            {
                                ExchangeConfirm(user_id, exId, address, deposit, method, total_fee);
                            }
                            if (subject.IndexOf("租借订单", StringComparison.Ordinal) > -1)  //租借订单
                            {
                                RentedConfirm(user_id, exId, address, deposit, method);
                            }
                            else
                            {
                                Recharge(user_id, subject, total_fee, out_trade_no, body);
                            }
                        }
                        else
                        {
                            Com.Cos.Common.Alipay.AlipayCore.LogResult("错误:支付失败");
                        }

                        //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——

                        Response.Write("success");  //请不要修改或删除

                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    }
                    else//验证失败
                    {
                        Com.Cos.Common.Alipay.AlipayCore.LogResult("错误:验证失败");
                        Response.Write("fail");
                    }
                }
                catch (Exception ex)
                {
                    Com.Cos.Common.Alipay.AlipayCore.LogResult("错误:" + ex.Message);
                }
            }
            else
            {
                Com.Cos.Common.Alipay.AlipayCore.LogResult("错误:无通知参数");
                Response.Write("无通知参数");
            }

            return(View("AlipayNotify"));
        }