Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary <string, string> sPara = GetRequestGet();

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

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

                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表
                    string  trade_no     = Request.QueryString["trade_no"];                  //支付宝交易号
                    int     order_no     = Int32.Parse(Request.QueryString["out_trade_no"]); //获取订单号
                    decimal total_fee    = decimal.Parse(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 (Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS")
                    {
                        string retunstr = new PayReturnSendEticketData().PayReturnSendEticket(trade_no, order_no, total_fee, trade_status);

                        //对分销充值订单支付返回,对绑定订单进行处理确认
                        var handdata = OrderJsonData.agentorderpay_Hand(order_no);

                        diveticketcode.InnerText = ("您已成功支付" + total_fee.ToString() + "元!");
                    }
                    else
                    {
                        diveticketcode.InnerText = ("支付返回错误:" + Request.QueryString["trade_status"]);
                    }
                }
                else
                {
                    //支付宝验证失败,应该是微信支付返回成功
                    int     out_trade_no = Request["out_trade_no"].ConvertTo <int>(0);
                    B2b_pay wxpay        = new B2bPayData().GetSUCCESSPayById(out_trade_no);
                    if (wxpay != null)
                    {
                        diveticketcode.InnerText = ("您已成功支付" + wxpay.Total_fee + "元!");
                    }
                }
            }
            else
            {
                diveticketcode.InnerText = ("无返回参数");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //获取访问的商户COMID
            if (Domain_def.Domain_yanzheng(RequestUrl))//如果符合shop101.etown.cn的格式,则从多微信商户基本信息表中获取comid
            {
                comid = Int32.Parse(Domain_def.Domain_Huoqu(RequestUrl));
            }
            else
            {
                B2b_company_info companyinfo = B2bCompanyData.GetComId(RequestUrl);
                if (companyinfo != null)
                {
                    comid = companyinfo.Com_id;
                }
            }
            #region 获得财付通支付参数 tenpay_id,tenpay_key
            //根据产品判断商家是否含有自己的财付通支付:
            //a.含有的话支付到商家;
            //b.没有的话支付到平台财付通账户(易城账户,公司id=106)
            string tenpay_id          = "";
            string tenpay_key         = "";
            B2b_finance_paytype model = new B2b_finance_paytypeData().GetFinancePayTypeByComid(comid);
            if (model != null)
            {
                //商家财付通支付的所有参数都存在
                if (model.Tenpay_id != "" && model.Tenpay_key != "")
                {
                    tenpay_id  = model.Tenpay_id;
                    tenpay_key = model.Tenpay_key;
                }
                else
                {
                    model = new B2b_finance_paytypeData().GetFinancePayTypeByComid(106);
                    if (model == null)
                    {
                        Response.Write("商户财付通信息设置不完全!");
                        Response.End();
                        return;
                    }
                    else
                    {
                        //商家财付通支付的所有参数都存在
                        if (model.Tenpay_id != "" && model.Tenpay_key != "")
                        {
                            tenpay_id  = model.Tenpay_id;
                            tenpay_key = model.Tenpay_key;
                        }
                        else
                        {
                            Response.Write("商户财付通信息设置不完全!!");
                            Response.End();
                            return;
                        }
                    }
                }
            }
            else
            {
                model = new B2b_finance_paytypeData().GetFinancePayTypeByComid(106);
                if (model == null)
                {
                    Response.Write("商户财付通信息设置不完全!");
                    Response.End();
                    return;
                }
                else
                {
                    //商家财付通支付的所有参数都存在
                    if (model.Tenpay_id != "" && model.Tenpay_key != "")
                    {
                        tenpay_id  = model.Tenpay_id;
                        tenpay_key = model.Tenpay_key;
                    }
                    else
                    {
                        Response.Write("商户财付通信息设置不完全!!");
                        Response.End();
                        return;
                    }
                }
            }

            #endregion


            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(Context);
            resHandler.setKey(tenpay_key);

            //判断签名
            if (resHandler.isTenpaySign())
            {
                ///通知id
                string notify_id = resHandler.getParameter("notify_id");
                //通过通知ID查询,确保通知来至财付通
                //创建查询请求
                RequestHandler queryReq = new RequestHandler(Context);
                queryReq.init();
                queryReq.setKey(tenpay_key);
                queryReq.setGateUrl("https://gw.tenpay.com/gateway/simpleverifynotifyid.xml");
                queryReq.setParameter("partner", tenpay_id);
                queryReq.setParameter("notify_id", notify_id);

                //通信对象
                TenpayHttpClient httpClient = new TenpayHttpClient();
                httpClient.setTimeOut(5);
                //设置请求内容
                httpClient.setReqContent(queryReq.getRequestURL());
                //后台调用
                if (httpClient.call())
                {
                    //设置结果参数
                    ClientResponseHandler queryRes = new ClientResponseHandler();
                    queryRes.setContent(httpClient.getResContent());
                    queryRes.setKey(tenpay_key);
                    //判断签名及结果
                    //只有签名正确,retcode为0,trade_state为0才是支付成功
                    if (queryRes.isTenpaySign())
                    {
                        //取结果参数做业务处理
                        string out_trade_no = queryRes.getParameter("out_trade_no");
                        //财付通订单号
                        string transaction_id = queryRes.getParameter("transaction_id");
                        //金额,以分为单位
                        string total_fee = queryRes.getParameter("total_fee");
                        //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
                        string discount = queryRes.getParameter("discount");
                        //支付结果
                        string trade_state = resHandler.getParameter("trade_state");
                        //交易模式,1即时到帐 2中介担保
                        string trade_mode = resHandler.getParameter("trade_mode");
                        #region
                        //判断签名及结果
                        if ("0".Equals(queryRes.getParameter("retcode")))
                        {
                            //Response.Write("id验证成功");

                            if ("1".Equals(trade_mode))
                            {       //即时到账
                                if ("0".Equals(trade_state))
                                {
                                    //------------------------------
                                    //即时到账处理业务开始
                                    //------------------------------

                                    //处理数据库逻辑
                                    //注意交易单不要重复处理
                                    //注意判断返回金额

                                    //------------------------------
                                    //即时到账处理业务完毕
                                    //------------------------------
                                    string retunstr = new PayReturnSendEticketData().PayReturnSendEticket(notify_id, Int32.Parse(out_trade_no), total_fee.ConvertTo <decimal>(), "TRADE_SUCCESS");

                                    //对分销充值订单支付返回,对绑定订单进行处理确认
                                    var handdata = OrderJsonData.agentorderpay_Hand(Int32.Parse(out_trade_no));


                                    //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                    Response.Write("success");
                                }
                                else
                                {
                                    Response.Write("即时到账支付失败");
                                }
                            }
                            else if ("2".Equals(trade_mode))
                            { //中介担保
                              //------------------------------
                              //中介担保处理业务开始
                              //------------------------------
                              //处理数据库逻辑
                              //注意交易单不要重复处理
                              //注意判断返回金额

                                int iStatus = Convert.ToInt32(trade_state);
                                switch (iStatus)
                                {
                                case 0:                 //付款成功

                                    break;

                                case 1:                 //交易创建

                                    break;

                                case 2:                 //收获地址填写完毕

                                    break;

                                case 4:                 //卖家发货成功

                                    break;

                                case 5:                 //买家收货确认,交易成功

                                    break;

                                case 6:                 //交易关闭,未完成超时关闭

                                    break;

                                case 7:                 //修改交易价格成功

                                    break;

                                case 8:                 //买家发起退款

                                    break;

                                case 9:                 //退款成功

                                    break;

                                case 10:        //退款关闭

                                    break;
                                }


                                //------------------------------
                                //中介担保处理业务开始
                                //------------------------------


                                //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                                Response.Write("success");
                            }
                        }
                        else
                        {
                            //错误时,返回结果可能没有签名,写日志trade_state、retcode、retmsg看失败详情。
                            //通知财付通处理失败,需要重新通知
                            Response.Write("查询验证签名失败或id验证失败");
                            Response.Write("retcode:" + queryRes.getParameter("retcode"));
                        }
                        #endregion
                    }
                    else
                    {
                        Response.Write("通知ID查询签名验证失败");
                    }
                }
                else
                {
                    //通知财付通处理失败,需要重新通知
                    Response.Write("后台调用通信失败");
                    //写错误日志
                    Response.Write("call err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>");
                }
            }
            else
            {
                Response.Write("签名验证失败");
            }
            Response.End();
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ResponseHandler resHandler = new ResponseHandler(Context);

            resHandler.init();

            string RequestUrl = Request.ServerVariables["SERVER_NAME"].ToLower();

            string u = Request.ServerVariables["HTTP_USER_AGENT"];

            //bool bo = detectmobilebrowser.HttpUserAgent(u);//判断是否是手机访问
            //if (bo)
            //{
            if (Domain_def.Domain_yanzheng(RequestUrl))//如果符合shop101.etown.cn的格式
            {
                //先通过正则表达式获取COMid
                int comid = Int32.Parse(Domain_def.Domain_Huoqu(RequestUrl).ToString());
                B2b_finance_paytype modelfinance = new B2b_finance_paytypeData().GetFinancePayTypeByComid(comid);
                resHandler.setKey(modelfinance.Wx_partnerkey, modelfinance.Wx_paysignkey);
            }
            else
            {
                Response.Write("获取商家支付参数失败");
                return;
            }
            //}



            //判断签名
            if (resHandler.isTenpaySign())
            {
                if (resHandler.isWXsign())
                {
                    //商户在收到后台通知后根据通知ID向财付通发起验证确认,采用后台系统调用交互模式
                    string notify_id = resHandler.getParameter("notify_id");
                    //取结果参数做业务处理
                    string out_trade_no = resHandler.getParameter("out_trade_no");
                    //财付通订单号
                    string transaction_id = resHandler.getParameter("transaction_id");
                    //金额,以分为单位
                    string total_fee = resHandler.getParameter("total_fee");
                    //如果有使用折扣券,discount有值,total_fee+discount=原请求的total_fee
                    string discount = resHandler.getParameter("discount");
                    //支付结果
                    string trade_state = resHandler.getParameter("trade_state");

                    //即时到账
                    if ("0".Equals(trade_state))
                    {
                        //------------------------------
                        //处理业务开始
                        //------------------------------
                        string retunstr = new PayReturnSendEticketData().PayReturnSendEticket(notify_id, int.Parse(out_trade_no), decimal.Parse(total_fee) / 100, "TRADE_SUCCESS", transaction_id);


                        //对分销充值订单支付返回,对绑定订单进行处理确认
                        var handdata = OrderJsonData.agentorderpay_Hand(int.Parse(out_trade_no));


                        //处理数据库逻辑
                        //注意交易单不要重复处理
                        //注意判断返回金额

                        //------------------------------
                        //处理业务完毕
                        //------------------------------

                        //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                        Response.Write("success 后台通知成功");
                    }
                    else
                    {
                        Response.Write("支付失败");
                        return;
                    }
                    //回复服务器处理成功
                    Response.Write("success");
                }

                else
                {//SHA1签名失败
                    Response.Write("fail -SHA1 failed");
                    Response.Write(resHandler.getDebugInfo());
                    return;
                }
            }

            else
            {//md5签名失败
                Response.Write("fail -md5 failed");
                Response.Write(resHandler.getDebugInfo());
                return;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary <string, string> sPara = GetRequestGet();

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

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

                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表
                    string  trade_no     = Request.QueryString["trade_no"];                  //支付宝交易号
                    int     order_no     = Int32.Parse(Request.QueryString["out_trade_no"]); //获取订单号
                    decimal total_fee    = decimal.Parse(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"];              //交易状态



                    //获取访问的商户COMID
                    if (Domain_def.Domain_yanzheng(RequestUrl)) //如果符合shop101.etown.cn的格式,则从多微信商户基本信息表中获取comid
                    {
                        comid = Int32.Parse(Domain_def.Domain_Huoqu(RequestUrl));
                    }
                    else
                    {
                        B2b_company_info companyinfo = B2bCompanyData.GetComId(RequestUrl);
                        if (companyinfo != null)
                        {
                            comid = companyinfo.Com_id;
                        }
                    }


                    //获取电话
                    B2b_order orderdate = new B2bOrderData().GetOrderById(order_no);
                    if (orderdate != null)
                    {
                        var saleset = B2bCompanySaleSetData.GetDirectSellByComid(orderdate.Comid.ToString());
                        if (saleset != null)
                        {
                            phone = saleset.Service_Phone;
                        }

                        var comdata = B2bCompanyData.GetCompany(orderdate.Comid);
                        if (saleset != null)
                        {
                            comname = comdata.Com_name;
                        }
                    }


                    if (Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS")
                    {
                        string retunstr = new PayReturnSendEticketData().PayReturnSendEticket(trade_no, order_no, total_fee, trade_status);
                        //对分销充值订单支付返回,对绑定订单进行处理确认
                        var handdata = OrderJsonData.agentorderpay_Hand(order_no);


                        title = ("您已成功支付" + total_fee.ToString() + "元!");
                    }
                    else
                    {
                        title = ("支付返回错误:" + Request.QueryString["trade_status"]);
                    }
                }
                else
                {
                    title = ("验证错误");
                }
            }
            else
            {
                title = ("无返回参数");
            }
        }
Exemple #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string u = Request.ServerVariables["HTTP_USER_AGENT"];

            bo = detectmobilebrowser.HttpUserAgent(u);


            Dictionary <string, string> sPara = GetRequestGet();

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

                string trade_no = Request["trade_no"];                  //支付宝交易号
                int    order_no = Int32.Parse(Request["out_trade_no"]); //获取订单号
                orderid = order_no;
                decimal total_fee = 0;                                  //获取总金额
                if (verifyResult)                                       //验证成功
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码


                    //获取访问的商户COMID
                    if (Domain_def.Domain_yanzheng(RequestUrl))//如果符合shop101.etown.cn的格式,则从多微信商户基本信息表中获取comid
                    {
                        comid = Int32.Parse(Domain_def.Domain_Huoqu(RequestUrl));
                    }
                    else
                    {
                        B2b_company_info companyinfo = B2bCompanyData.GetComId(RequestUrl);
                        if (companyinfo != null)
                        {
                            comid = companyinfo.Com_id;
                        }
                    }



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

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

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

                    B2bPayData datapay    = new B2bPayData();
                    B2b_pay    modelb2pay = datapay.GetPayByoId(order_no);

                    md5 = EncryptionHelper.ToMD5(order_no.ToString() + "lixh1210", "UTF-8");

                    B2b_order orderdate = new B2bOrderData().GetOrderById(order_no);
                    if (orderdate != null)
                    {
                        order_type = orderdate.Order_type;

                        var saleset = B2bCompanySaleSetData.GetDirectSellByComid(orderdate.Comid.ToString());
                        if (saleset != null)
                        {
                            phone = saleset.Service_Phone;
                        }

                        var comdata = B2bCompanyData.GetCompany(orderdate.Comid);
                        if (saleset != null)
                        {
                            comname = comdata.Com_name;
                        }


                        //根据产品id得到产品信息
                        B2bComProData datapro     = new B2bComProData();
                        B2b_com_pro   modelcompro = datapro.GetProById(orderdate.Pro_id.ToString(), orderdate.Speciid, orderdate.channelcoachid);

                        if (modelcompro != null)
                        {
                            servertype = modelcompro.Server_type;
                        }
                    }

                    if (modelb2pay != null)
                    {
                        total_fee = modelb2pay.Total_fee;
                    }

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


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

                    //打印页面
                    //Response.Write("验证成功<br />");订单支付 成功!
                    string retunstr = new PayReturnSendEticketData().PayReturnSendEticket(trade_no, order_no, total_fee, result);
                    title = "订单支付 成功!";

                    //对分销充值订单支付返回,对绑定订单进行处理确认
                    var handdata = OrderJsonData.agentorderpay_Hand(order_no);

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

                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                }
                else//验证失败
                {
                    //Response.Write("验证失败");
                    title = "订单支付 出现错误";
                }
            }
            else
            {
                //Response.Write("无返回参数");
                title = "订单 没有 支付";
            }
        }
        public void ProcessNotify(WxPayConfig config, B2b_finance_paytype model)
        {
            WxPayData notifyData = new Notify(this).GetNotifyData(config);

            Log.Info(this.GetType().ToString(), "The Pay ResultXml:" + notifyData.ToXml(config));

            //检查支付结果中transaction_id是否存在
            if (!notifyData.IsSet("transaction_id"))
            {
                //若transaction_id不存在,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "支付结果中微信订单号不存在");
                Log.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml(config), config);
                Response.Write(res.ToXml(config));
                Response.End();
            }

            string transaction_id = notifyData.GetValue("transaction_id").ToString();
            string notify_id      = "1";
            string out_trade_no   = notifyData.GetValue("out_trade_no").ToString();
            string total_fee      = notifyData.GetValue("total_fee").ToString();

            //查询订单,判断订单真实性
            if (!QueryOrder(transaction_id, config))
            {
                //若订单查询失败,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "订单查询失败");
                Log.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml(config), config);
                Response.Write(res.ToXml(config));
                Response.End();
            }
            //查询订单成功
            else
            {
                //订单支付信息如果没有,则添加支付信息
                B2b_pay   modelb2pay    = new B2bPayData().GetPayByoId(out_trade_no.ConvertTo <int>(0));
                B2b_order modelb2border = new B2bOrderData().GetOrderById(out_trade_no.ConvertTo <int>(0));
                string    Pay_name      = "";
                string    Pay_phone     = "";
                if (modelb2border != null)
                {
                    Pay_name  = modelb2border.U_name;
                    Pay_phone = modelb2border.U_phone;
                }

                #region 订单提交支付信息

                if (modelb2pay == null)
                {
                    B2b_pay eticket = new B2b_pay()
                    {
                        Id           = 0,
                        Oid          = out_trade_no.ConvertTo <int>(0),
                        Pay_com      = "wx",
                        Pay_name     = Pay_name,
                        Pay_phone    = Pay_phone,
                        Total_fee    = decimal.Parse(total_fee) / 100,
                        Trade_no     = "",
                        Trade_status = "trade_pendpay",
                        Uip          = "",
                        comid        = model.Com_id
                    };
                    int payid = new B2bPayData().InsertOrUpdate(eticket);
                }
                else
                {
                    //对已完成支付的,再次提交支付,跳转到订单也或显示此订单已支付
                    if (modelb2pay.Trade_status != "TRADE_SUCCESS")
                    {
                        //防止金额有所改动
                        modelb2pay.comid     = model.Com_id;
                        modelb2pay.Pay_com   = "wx";
                        modelb2pay.Total_fee = decimal.Parse(total_fee) / 100;
                        new B2bPayData().InsertOrUpdate(modelb2pay);
                    }
                }
                #endregion
                //------------------------------
                //处理业务开始
                //------------------------------
                string retunstr = new PayReturnSendEticketData().PayReturnSendEticket(notify_id, int.Parse(out_trade_no), decimal.Parse(total_fee) / 100, "TRADE_SUCCESS", transaction_id);

                //对分销充值订单支付返回,对绑定订单进行处理确认
                var handdata = OrderJsonData.agentorderpay_Hand(int.Parse(out_trade_no));

                // 赠送保险
                OrderJsonData.ZengsongBaoxian(int.Parse(out_trade_no));

                //给财付通系统发送成功信息,财付通系统收到此结果后不再进行后续通知
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "SUCCESS");
                res.SetValue("return_msg", "OK");
                Log.Info(this.GetType().ToString(), "order query success : " + res.ToXml(config), config);
                Response.Write(res.ToXml(config));
                Response.End();
            }
        }
Exemple #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary <string, string> sPara = GetRequestPost();

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

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

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

                    if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
                    {
                        //判断该笔订单是否在商户网站中已经做过处理
                        //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                        //如果有做过处理,不执行商户的业务程序
                        #region
                        //查询支付,并修改为支付成功
                        //B2bPayData datapay = new B2bPayData();
                        //B2b_pay modelb2pay = datapay.GetPayByoId(order_no);

                        //if (modelb2pay.Trade_status != "TRADE_SUCCESS")//判断原状态是否为不成功
                        //{
                        //    if (modelb2pay.Total_fee == total_fee)//判断支付金额是否相同
                        //    {
                        //        //B2b_pay payinfo = new B2b_pay()
                        //        //{
                        //        //    Id = modelb2pay.Id,
                        //        //    Trade_no = trade_no,
                        //        //    Trade_status = "TRADE_SUCCESS",
                        //        //};

                        //        modelb2pay.Trade_no = trade_no;
                        //        modelb2pay.Trade_status = "TRADE_SUCCESS";
                        //        int payid = datapay.InsertOrUpdate(modelb2pay);//修改支付状态


                        //        //根据订单id得到订单信息
                        //        B2bOrderData dataorder = new B2bOrderData();
                        //        B2b_order modelb2border = dataorder.GetOrderById(order_no);

                        //        //---------------新增1begin--------------//
                        //        modelb2border.Pay_state = (int)PayStatus.HasPay;
                        //        modelb2border.Order_state = (int)OrderStatus.HasPay;
                        //        //修改此订单的支付状态为“支付成功” ,订单状态为“已付款”
                        //        dataorder.InsertOrUpdate(modelb2border);
                        //        //---------------新增1end--------------//

                        //        //根据产品id得到产品信息
                        //        B2bComProData datapro = new B2bComProData();
                        //        B2b_com_pro modelcompro = datapro.GetProById(modelb2border.Pro_id.ToString());

                        //        //得到商家信息,账户余额
                        //        B2b_company modelcom = B2bCompanyData.GetCompany(modelcompro.Com_id);
                        //        decimal Over_money = modelcom.Imprest + total_fee;

                        //        //得到支付方式,如果是支付到自己的支付宝账户则需要增加退出记录
                        //        B2bFinanceData datefin = new B2bFinanceData();
                        //        B2b_Finance modelfin = datefin.FinancePayType(modelcompro.Com_id);
                        //        int Paytype_int = 1;//支付款到 易城=1 支付到自己=2

                        //        if (modelfin != null)
                        //        {
                        //            Paytype_int = modelfin.Paytype;
                        //        }


                        //        //增加财务记录
                        //        B2bFinanceData Financed = new B2bFinanceData();
                        //        B2b_Finance Financeinfo = new B2b_Finance()
                        //        {

                        //            Id = 0,
                        //            Com_id = modelcompro.Com_id,
                        //            Agent_id = 0,           //分销编号(默认为0)
                        //            Eid = 0,                //易城账户(默认为0,0=没有交易,1=和易城交易)
                        //            Order_id = modelcompro.Id,           //订单号(默认为0)
                        //            Servicesname = modelcompro.Pro_name,       //交易名称/内容
                        //            SerialNumber = DateTime.Now.ToString("yyyyMMddhhmmssfff"),       //财务流水号
                        //            Money = total_fee,              //金额
                        //            Payment = 0,            //收支(0=收款,1=支出)
                        //            Payment_type = "直销收款",       //类型(充值,商家提现,直销收款,消费(验票),商家退款,直销退票,手续费,商家返点)
                        //            Money_come = "支付宝",         //资金来源(网上支付,银行收款等)
                        //            Over_money = Over_money,       //余额(根据商家,分销,易城,编号显示相应余额)
                        //            Paytype = Paytype_int

                        //        };
                        //        int finaceid = Financed.InsertOrUpdate(Financeinfo);


                        //        //如果是支付到商户的支付宝则增加一笔支出操作与上面做平
                        //        if (Paytype_int == 2)
                        //        {
                        //            B2b_Finance Financebackinfo = new B2b_Finance()
                        //            {
                        //                Id = 0,
                        //                Com_id = modelcompro.Com_id,
                        //                Agent_id = 0,           //分销编号(默认为0)
                        //                Eid = 0,                //易城账户(默认为0,0=没有交易,1=和易城交易)
                        //                Order_id = modelcompro.Id,           //订单号(默认为0)
                        //                Servicesname = modelcompro.Pro_name,       //交易名称/内容
                        //                SerialNumber = DateTime.Now.ToString("yyyyMMddhhmmssfff"),       //财务流水号
                        //                Money = 0 - total_fee,              //金额
                        //                Payment = 1,            //收支(0=收款,1=支出)
                        //                Payment_type = "提现-商家支付宝",       //类型(充值,商家提现,直销收款,消费(验票),商家退款,直销退票,手续费,商家返点)
                        //                Money_come = "支付宝",         //资金来源(网上支付,银行收款等)
                        //                Over_money = Over_money - total_fee       //余额(根据商家,分销,易城,编号显示相应余额)
                        //            };
                        //            int finacebackid = Financed.InsertOrUpdate(Financebackinfo);

                        //        }

                        //        //---------------------------生成电子票并发送-------------------------------
                        //        //如果订单“已付款”则执行发码操作,否则跳过
                        //        if ((int)modelb2border.Order_state == (int)OrderStatus.HasPay)
                        //        {

                        //            //生成电子码
                        //            int u_num = modelb2border.U_num;
                        //            int comid = modelcompro.Com_id;
                        //            RandomCodeData datarandomcode = new RandomCodeData();
                        //            RandomCode modelrandomcode = datarandomcode.GetRandomCode();//得到未用随机码对象


                        //            //设置取出的电子码状态为1(已使用)
                        //            modelrandomcode.State = 1;
                        //            int randomcodeid = datarandomcode.InsertOrUpdate(modelrandomcode);
                        //            string eticketcode = "9" + comid.ToString() + modelrandomcode.Code.ToString();
                        //            string sendstr = "";

                        //            //录入电子票列表
                        //            B2bEticketData eticketdata = new B2bEticketData();
                        //            B2b_eticket eticket = new B2b_eticket()
                        //            {

                        //                Id = 0,
                        //                Com_id = comid,
                        //                Pro_id = modelcompro.Id,
                        //                Agent_id = 0,//直销
                        //                Pno = eticketcode,
                        //                E_type = (int)EticketCodeType.ShuZiMa,
                        //                Pnum = modelb2border.U_num,
                        //                Use_pnum = modelb2border.U_num,
                        //                E_proname = modelcompro.Pro_name,
                        //                E_face_price = modelcompro.Face_price,
                        //                E_sale_price = modelcompro.Advise_price,
                        //                E_cost_price = modelcompro.Agentsettle_price,
                        //                V_state = (int)EticketCodeStatus.NotValidate,
                        //                Send_state = (int)EticketCodeSendStatus.NotSend,
                        //                Subdate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
                        //            };
                        //            int eticketid = eticketdata.InsertOrUpdate(eticket);
                        //            if (eticketid > 0)
                        //            {
                        //                //生成电子码短信,稍后可单独写类或写到数据库中
                        //                //diveticketcode.InnerText = "电子码生成成功:" + eticketcode;
                        //                sendstr = "感谢您订购" + modelcompro.Pro_name + modelb2border.U_num + "张" + ",电子码:" + eticketcode + " 有效期至:" + modelcompro.Pro_end.ToString("yyyy-MM-dd") + "二维码:http://" + RequestUrl + "/qr.ashx?p=" + eticketcode + "【微旅行】";

                        //                //电子票发送日志表,创建发送记录
                        //                B2bEticketSendLogData eticketsnedlog = new B2bEticketSendLogData();
                        //                B2b_eticket_send_log eticketlog = new B2b_eticket_send_log()
                        //                {
                        //                    Id = 0,
                        //                    Eticket_id = eticketid,
                        //                    Pnotext = sendstr,
                        //                    Phone = modelb2border.U_phone,
                        //                    Sendstate = 0,
                        //                    Sendtype = 1,
                        //                    Senddate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
                        //                };
                        //                int insertsendEticketid = eticketsnedlog.InsertOrUpdate(eticketlog);


                        //                //发送电子码
                        //                string msg = "";
                        //                int sendstate = 0;//发送状态 1=成功,2=失败 0=未发送
                        //                int sendback = SendSmsHelper.SendSms(modelb2border.U_phone, sendstr, out msg);
                        //                if (sendback > 0)
                        //                {
                        //                    //labelmsg.InnerText = "发送成功" + sendback;
                        //                    sendstate = 1;
                        //                    //修改电子票发送日志表的发码状态为成功
                        //                    B2b_eticket_send_log eticketlogup = new B2b_eticket_send_log()
                        //                    {
                        //                        Id = insertsendEticketid,
                        //                        Sendstate = 1,
                        //                        Senddate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
                        //                    };
                        //                    int upsendEticket = eticketsnedlog.InsertOrUpdate(eticketlogup);
                        //                    //-----------------新增2 begin-------------------------//
                        //                    modelb2border.Send_state = (int)SendCodeStatus.HasSend;
                        //                    modelb2border.Order_state = (int)OrderStatus.HasSendCode;
                        //                    modelb2border.Ticketcode = eticketid;
                        //                    //修改订单中发码状态为“已发码”,订单状态为"已发码",电子码id输入
                        //                    dataorder.InsertOrUpdate(modelb2border);
                        //                    //------------------新增2 end---------------------------//
                        //                }
                        //                else
                        //                {
                        //                    //labelmsg.InnerText = "发送错误" + msg;

                        //                    sendstate = 2;
                        //                }

                        //                //记录短信日志表
                        //                B2bSmsMobileSendDate smsmobilelog = new B2bSmsMobileSendDate();
                        //                B2b_smsmobilesend smslog = new B2b_smsmobilesend()
                        //                {
                        //                    Mobile = modelb2border.U_phone,
                        //                    Content = sendstr,
                        //                    Flag = sendstate,
                        //                    Text = msg,
                        //                    Delaysendtime = "",
                        //                    Realsendtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")),
                        //                    Smsid = sendback,
                        //                    Sendeticketid = insertsendEticketid
                        //                };
                        //                int insertsendmobileid = smsmobilelog.InsertOrUpdate(smslog);

                        //            }
                        //            else
                        //            {
                        //                //diveticketcode.InnerText = "电子码生成ERROR";

                        //            }

                        //        }



                        //    }

                        //}
                        #endregion


                        string retunstr = new PayReturnSendEticketData().PayReturnSendEticket(trade_no, order_no, total_fee, trade_status);

                        //对分销充值订单支付返回,对绑定订单进行处理确认
                        var handdata = OrderJsonData.agentorderpay_Hand(order_no);
                    }


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

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

                    #region 赠送保险
                    OrderJsonData.ZengsongBaoxian(order_no);
                    #endregion

                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                }
                else//验证失败
                {
                    Response.Write("fail");
                }
            }
            else
            {
                Response.Write("无通知参数");
            }
        }