Ejemplo n.º 1
0
        /// <summary>
        ///  支付宝回调GET
        /// </summary>
        /// <param name="notifySuccess">支付成功的回调,商户订单号和支付宝交易号回调到调用端</param>
        /// <param name="notifyFail">支付失败的回调</param>
        public void AlipayCallback(AlipayCallBack notifySuccess, Action <string> notifyFail)
        {
            Dictionary <string, string> sPara = GetRequestGet();

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

                if (verifyResult)//验证成功
                {
                    //商户订单号
                    string out_trade_no = Request.QueryString["out_trade_no"];
                    //支付宝交易号
                    string trade_no = Request.QueryString["trade_no"];
                    //交易状态
                    string result = Request.QueryString["result"];
                    Lind.DDD.Logger.LoggerFactory.Instance.Logger_Info("WAP支付宝回调成功,订单号:" + out_trade_no + ",交易号:" + trade_no);
                    StringBuilder str = new StringBuilder();
                    foreach (var item in sPara.Keys)
                    {
                        str.Append(item + "=" + sPara[item] + ",");
                    }
                    Lind.DDD.Logger.LoggerFactory.Instance.Logger_Info(str.ToString());
                    notifySuccess(out_trade_no, trade_no);
                }
                else//验证失败
                {
                    LoggerFactory.Instance.Logger_Info(string.Format("WAP验证失败"));
                    notifyFail("验证失败");
                }
            }
            else
            {
                LoggerFactory.Instance.Logger_Info(string.Format("WAP无返回参数"));
                notifyFail("无返回参数");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 支付宝回调地址POST
        /// </summary>
        /// <param name="notifySuccess">回调成功后的逻辑,商户订单号和支付宝交易号回调到调用端</param>
        public void AlipayNotify(AlipayCallBack notifySuccess)
        {
            string msg = "";
            Dictionary <string, string> sPara = GetRequestPost();

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

                if (verifyResult)//验证成功
                {
                    //解密(如果是RSA签名需要解密,如果是MD5签名则下面一行清注释掉)
                    sPara = aliNotify.Decrypt(sPara);
                    //XML解析notify_data数据
                    try
                    {
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(sPara["notify_data"]);
                        //商户订单号(我们生成的,最好使用日期时间的表式方法,用于成功回调后,修改订单状态)
                        string out_trade_no = xmlDoc.SelectSingleNode("/notify/out_trade_no").InnerText;
                        //支付宝交易号(支付宝生成的)
                        string trade_no = xmlDoc.SelectSingleNode("/notify/trade_no").InnerText;
                        //交易状态
                        string trade_status = xmlDoc.SelectSingleNode("/notify/trade_status").InnerText;

                        if (trade_status == "TRADE_FINISHED")
                        {
                            //判断该笔订单是否在商户网站中已经做过处理
                            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                            //如果有做过处理,不执行商户的业务程序

                            //注意:
                            //该种交易状态只在两种情况下出现
                            //1、开通了普通即时到账,买家付款成功后。
                            //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。
                            Lind.DDD.Logger.LoggerFactory.Instance.Logger_Info("WAP支付宝回调成功,订单号:" + out_trade_no + ",交易号:" + trade_no);

                            notifySuccess(out_trade_no, trade_no);
                            Response.Write("success");
                        }
                        else if (trade_status == "TRADE_SUCCESS")
                        {
                            //判断该笔订单是否在商户网站中已经做过处理
                            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                            //如果有做过处理,不执行商户的业务程序
                            //注意:
                            //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。
                            Lind.DDD.Logger.LoggerFactory.Instance.Logger_Info("WAP支付宝回调成功,订单号:" + out_trade_no + ",交易号:" + trade_no);
                            StringBuilder str = new StringBuilder();
                            foreach (var item in sPara.Keys)
                            {
                                str.Append(item + "=" + sPara[item] + ",");
                            }
                            Lind.DDD.Logger.LoggerFactory.Instance.Logger_Info(str.ToString());
                            notifySuccess(out_trade_no, trade_no);
                            Response.Write("success");
                        }
                        else
                        {
                            Response.Write("fail");
                            LoggerFactory.Instance.Logger_Info(string.Format("WAP支付失败,订单号:{0},状态:{1}", out_trade_no, msg));
                        }
                    }
                    catch (Exception exc)
                    {
                        Response.Write("fail");
                        LoggerFactory.Instance.Logger_Info(string.Format("WAP支付失败,异常信息:{0}", exc.Message));
                    }
                }
                else//验证失败
                {
                    LoggerFactory.Instance.Logger_Info(string.Format("WAP验证失败"));

                    Response.Write("fail");
                }
            }
            else
            {
                Response.Write("fail");
            }
        }