コード例 #1
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (!IsPostBack)
            {
                Dictionary <string, string> sPara = GetRequestPost();

                if (sPara.Count > 0)//判断是否有带返回参数
                {
                    bool verifyResult = false;

                    AlipayNotify aliNotify = new AlipayNotify();
                    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 trade_status      = xmlDoc.SelectSingleNode("/notify/trade_status").InnerText;
                            AliWapPayNotifyInfo info = new AliWapPayNotifyInfo();
                            info.trade_status = trade_status;
                            info.subject      = xmlDoc.SelectSingleNode("/notify/subject").InnerText;
                            info.trade_no     = xmlDoc.SelectSingleNode("/notify/trade_no").InnerText;
                            info.buyer_email  = xmlDoc.SelectSingleNode("/notify/buyer_email").InnerText;
                            info.gmt_create   = xmlDoc.SelectSingleNode("/notify/gmt_create").InnerText;
                            info.quantity     = xmlDoc.SelectSingleNode("/notify/quantity").InnerText;
                            info.out_trade_no = xmlDoc.SelectSingleNode("/notify/out_trade_no").InnerText;
                            info.notify_time  = xmlDoc.SelectSingleNode("/notify/notify_time").InnerText;
                            info.seller_id    = xmlDoc.SelectSingleNode("/notify/seller_id").InnerText;
                            info.total_fee    = xmlDoc.SelectSingleNode("/notify/total_fee").InnerText;
                            info.seller_email = xmlDoc.SelectSingleNode("/notify/seller_email").InnerText;
                            info.price        = xmlDoc.SelectSingleNode("/notify/price").InnerText;
                            //info.gmt_payment = xmlDoc.SelectSingleNode("/notify/gmt_payment").InnerText;
                            info.buyer_id   = xmlDoc.SelectSingleNode("/notify/buyer_id").InnerText;
                            info.notify_id  = xmlDoc.SelectSingleNode("/notify/notify_id").InnerText;
                            info.use_coupon = xmlDoc.SelectSingleNode("/notify/use_coupon").InnerText;
                            if (xmlDoc.SelectSingleNode("/notify/gmt_payment") != null)
                            {
                                info.gmt_payment = xmlDoc.SelectSingleNode("/notify/gmt_payment").InnerText;
                            }

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

                                //注意:
                                //该种交易状态只在两种情况下出现
                                //1、开通了普通即时到账,买家付款成功后。
                                //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。

                                //微商易业务逻辑
                                OnPaySucceed(info);

                                Response.Write("success");  //请不要修改或删除
                            }
                            else if (trade_status == "TRADE_SUCCESS")
                            {
                                //判断该笔订单是否在商户网站中已经做过处理
                                //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                                //如果有做过处理,不执行商户的业务程序

                                //注意:
                                //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。

                                //微商易业务逻辑
                                OnPaySucceed(info);

                                Response.Write("success");  //请不要修改或删除
                            }
                            else
                            {
                                Response.Write(trade_status);
                            }
                        }
                        catch (Exception exc)
                        {
                            Response.Write(exc.ToString());
                        }



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

                        /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    }
                    else//验证失败
                    {
                        Response.Write("fail");
                    }
                }
                else
                {
                    Response.Write("无通知参数");
                }
            }
        }
コード例 #2
0
 public abstract void OnPaySucceed(AliWapPayNotifyInfo info);