Ejemplo n.º 1
0
        public void AddPayLog(bool isNotify)
        {
            PayLog log = new PayLog();

            log.ID      = DataHelper.GetSystemID();
            log.OrderNo = Request.QueryString["out_trade_no"];
            if (isNotify)
            {
                log.Message = Request.Form.ToString();
            }
            else
            {
                log.Message = Request.Url.ToString();;
            }
            log.LogTime = DateTime.Now;
            PayLogService ps = new PayLogService();

            ps.Add(log);
        }
Ejemplo n.º 2
0
        public ActionResult AlipayNotify()
        {
            try
            {
                AddPayLog(true);
            }
            catch (Exception e)
            {
                PayLogService ps = new PayLogService();
                PayLog        pl = new PayLog();
                pl         = new PayLog();
                pl.ID      = DataHelper.GetSystemID();
                pl.LogTime = DateTime.Now;
                pl.Message = e.Message;
                ps.Add(pl);
            }
            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)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                            //如果有做过处理,不执行商户的业务程序
                            psv.FinishOrder(out_trade_no, trade_no, FeeType.ALiPay);
                            //注意:
                            //该种交易状态只在两种情况下出现
                            //1、开通了普通即时到账,买家付款成功后。
                            //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。

                            return(Content("success"));  //请不要修改或删除
                        }
                        else if (trade_status == "TRADE_SUCCESS")
                        {
                            //判断该笔订单是否在商户网站中已经做过处理
                            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                            //如果有做过处理,不执行商户的业务程序
                            psv.FinishOrder(out_trade_no, trade_no, FeeType.ALiPay);
                            //注意:
                            //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。


                            return(Content("success"));  //请不要修改或删除
                        }
                        else
                        {
                            return(Content(trade_status));
                        }
                    }
                    catch (Exception exc)
                    {
                        return(Content(exc.ToString()));
                    }
                }
                else//验证失败
                {
                    return(Content("fail"));
                }
            }
            else
            {
                return(Content("无通知参数"));
            }
        }