示例#1
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, DTRequest.GetString("notify_id"), DTRequest.GetString("sign"));

                //写日志
                //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "验证结果:" + verifyResult.ToString() + "\n", System.Text.Encoding.UTF8);

                if (verifyResult)//验证成功
                {
                    string trade_no = DTRequest.GetString("trade_no");                  //支付宝交易号
                    string order_no = DTRequest.GetString("out_trade_no").ToUpper();    //获取订单号
                    string total_fee = DTRequest.GetString("total_fee");                //获取总金额
                    string trade_status = DTRequest.GetString("trade_status");          //交易状态

                    //写日志
                    //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "接口类型:" + Config.Type + "\n", System.Text.Encoding.UTF8);

                    if (Config.Type == "1") //即时到帐接口处理方法
                    {
                        //写日志
                        //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "即时到帐返回交易状态:" + trade_status + "\n", System.Text.Encoding.UTF8);

                        if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
                        {
                            if (order_no.StartsWith("R")) //充值订单
                            {
                                BLL.user_amount_log bll = new BLL.user_amount_log();
                                Model.user_amount_log model = bll.GetModel(order_no);
                                if (model == null)
                                {
                                    Response.Write("该订单号不存在");
                                    return;
                                }
                                if (model.status == 1) //已成功
                                {
                                    Response.Write("success");
                                    return;
                                }
                                if (model.value != decimal.Parse(total_fee))
                                {
                                    Response.Write("订单金额和支付金额不相符");
                                    return;
                                }
                                model.trade_no = trade_no;
                                model.status = 1;
                                model.complete_time = DateTime.Now;
                                bool result = bll.Update(model);
                                if (!result)
                                {
                                    Response.Write("修改订单状态失败");
                                    return;
                                }
                            }
                            else if (order_no.StartsWith("B")) //商品订单
                            {
                                //写日志
                                //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "商品订单\n", System.Text.Encoding.UTF8);

                                BLL.orders bll = new BLL.orders();
                                Model.orders model = bll.GetModel(order_no);
                                if (model == null)
                                {
                                    //写日志
                                    //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "订单号:" + order_no + "不存在\n", System.Text.Encoding.UTF8);
                                    Response.Write("该订单号不存在");
                                    return;
                                }
                                if (model.payment_status == 2) //已付款
                                {
                                    //写日志
                                    //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "订单号:" + order_no + "已付款\n", System.Text.Encoding.UTF8);
                                    Response.Write("success");
                                    return;
                                }
                                if (model.order_amount != decimal.Parse(total_fee))
                                {
                                    //写日志
                                    //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "订单号:" + order_no + "订单金额" + model.order_amount + "和支付金额" + total_fee + "不相符\n", System.Text.Encoding.UTF8);
                                    Response.Write("订单金额和支付金额不相符");
                                    return;
                                }
                                bool result = bll.UpdateField(order_no, "trade_no='" + trade_no + "',status=2,payment_status=2,payment_time='" + DateTime.Now + "'");
                                if (!result)
                                {
                                    Response.Write("修改订单状态失败");
                                    return;
                                }
                                //写日志
                                //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "修改订单状态:" + result.ToString() + "\n", System.Text.Encoding.UTF8);

                                //扣除积分
                                if (model.point < 0)
                                {
                                    new BLL.user_point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no, false);
                                }
                            }
                        }
                    }
                    else //担保交易接口处理方法
                    {
                        if (trade_status == "WAIT_SELLER_SEND_GOODS") //付款成功
                        {
                            if (order_no.StartsWith("R")) //充值订单
                            {
                                BLL.user_amount_log bll = new BLL.user_amount_log();
                                Model.user_amount_log model = bll.GetModel(order_no);
                                if (model == null)
                                {
                                    Response.Write("该订单号不存在");
                                    return;
                                }
                                if (model.status == 1) //已成功
                                {
                                    Response.Write("success");
                                    return;
                                }
                                if (model.value != decimal.Parse(total_fee))
                                {
                                    Response.Write("订单金额和支付金额不相符");
                                    return;
                                }
                                model.trade_no = trade_no;
                                model.status = 1;
                                model.complete_time = DateTime.Now;
                                bool result = bll.Update(model);
                                if (!result)
                                {
                                    Response.Write("修改订单状态失败");
                                    return;
                                }
                                //自动发货
                                result = new Service().Send_goods_confirm_by_platform(trade_no, "EXPRESS", "", "DIRECT");
                                if (!result)
                                {
                                    Response.Write("自动发货失败");
                                    return;
                                }
                            }
                            else if (order_no.StartsWith("B")) //商品订单
                            {
                                BLL.orders bll = new BLL.orders();
                                Model.orders model = bll.GetModel(order_no);
                                if (model == null)
                                {
                                    Response.Write("该订单号不存在");
                                    return;
                                }
                                if (model.payment_status == 2) //已付款
                                {
                                    Response.Write("success");
                                    return;
                                }
                                if (model.order_amount != decimal.Parse(total_fee))
                                {
                                    Response.Write("订单金额和支付金额不相符");
                                    return;
                                }
                                bool result = bll.UpdateField(order_no, "trade_no='" + trade_no + "',status=2,payment_status=2,payment_time='" + DateTime.Now + "'");
                                if (!result)
                                {
                                    Response.Write("修改订单状态失败");
                                    return;
                                }
                                //扣除积分
                                if (model.point < 0)
                                {
                                    new BLL.user_point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no, false);
                                }
                            }
                        }
                        else if (trade_status == "TRADE_FINISHED") //确认收货交易完成
                        {
                            if (order_no.StartsWith("B")) //商品订单
                            {
                                BLL.orders bll = new BLL.orders();
                                Model.orders model = bll.GetModel(order_no);
                                if (model == null)
                                {
                                    Response.Write("该订单号不存在");
                                    return;
                                }
                                if (model.status > 2) //订单状态已经完成结束
                                {
                                    Response.Write("success");
                                    return;
                                }
                                if (model.order_amount != decimal.Parse(total_fee))
                                {
                                    Response.Write("订单金额和支付金额不相符");
                                    return;
                                }
                                bool result = bll.UpdateField(order_no, "status=3,complete_time='" + DateTime.Now + "'");
                                if (!result)
                                {
                                    Response.Write("修改订单状态失败");
                                    return;
                                }
                                //给会员增加积分检查升级
                                if (model.user_id > 0 && model.point > 0)
                                {
                                    new BLL.user_point_log().Add(model.user_id, model.user_name, model.point, "购物获得积分,订单号:" + model.order_no, true);
                                }
                            }
                        }
                    }

                    Response.Write("success");  //请不要修改或删除
                }
                else//验证失败
                {
                    Response.Write("fail");
                }
            }
            else
            {
                Response.Write("无通知参数");
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //读取站点配置信息
            Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig();

            //=============================获得订单信息================================
            string order_no = DTRequest.GetFormString("pay_order_no").ToUpper();
            decimal order_amount = DTRequest.GetFormDecimal("pay_order_amount", 0);
            string user_name = DTRequest.GetFormString("pay_user_name");
            string subject = DTRequest.GetFormString("pay_subject");
            //以下收货人信息
            string receive_name = string.Empty; //收货人姓名
            string receive_address = string.Empty; //收货人地址
            string receive_zip = string.Empty; //收货人邮编
            string receive_phone = string.Empty; //收货人电话
            string receive_mobile = string.Empty; //收货人手机
            //检查参数是否正确
            if (order_no == "" || order_amount == 0)
            {
                Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您提交的参数有误!")));
                return;
            }
            if (order_no.StartsWith("R")) //R开头为在线充值订单
            {
                Model.user_amount_log model = new BLL.user_amount_log().GetModel(order_no);
                if (model == null)
                {
                    Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您充值的订单号不存在或已删除!")));
                    return;
                }
                if (model.value != order_amount)
                {
                    Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您充值的订单金额与实际金额不一致!")));
                    return;
                }
                //取得用户信息
                Model.users userModel = new BLL.users().GetModel(model.user_id);
                if (userModel == null)
                {
                    Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,用户账户不存在或已删除!")));
                    return;
                }
                receive_name = userModel.nick_name;
                receive_address = userModel.address;
                receive_phone = userModel.telphone;
                receive_mobile = userModel.mobile;
            }
            else //B开头为商品订单
            {
                Model.orders model = new BLL.orders().GetModel(order_no);
                if (model == null)
                {
                    Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您支付的订单号不存在或已删除!")));
                    return;
                }
                if (model.order_amount != order_amount)
                {
                    Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您支付的订单金额与实际金额不一致!")));
                    return;
                }
                receive_name = model.accept_name;
                receive_address = model.address;
                receive_zip = model.post_code;
                receive_phone = model.telphone;
                receive_mobile = model.mobile;
            }
            if (user_name != "")
            {
                user_name = "支付会员:" + user_name;
            }
            else
            {
                user_name = "匿名用户";
            }

            //===============================请求参数==================================

            //把请求参数打包成数组
            SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>();
            sParaTemp.Add("payment_type", "1"); //收款类型1商品购买
            sParaTemp.Add("show_url", siteConfig.weburl); //商品展示地址
            sParaTemp.Add("out_trade_no", order_no); //网站订单号
            sParaTemp.Add("subject", siteConfig.webname + "-" + subject); //订单名称
            sParaTemp.Add("body", user_name); //订单描述
            sParaTemp.Add("total_fee", order_amount.ToString()); //订单总金额
            sParaTemp.Add("paymethod", ""); //默认支付方式
            sParaTemp.Add("defaultbank", ""); //默认网银代号
            sParaTemp.Add("anti_phishing_key", ""); //防钓鱼时间戳
            sParaTemp.Add("exter_invoke_ip", DTRequest.GetIP()); ////获取客户端的IP地址
            sParaTemp.Add("buyer_email", ""); //默认买家支付宝账号
            sParaTemp.Add("royalty_type", "");
            sParaTemp.Add("royalty_parameters", "");

            //构造即时到帐接口表单提交HTML数据,无需修改
            Service ali = new Service();
            string sHtmlText = ali.Create_direct_pay_by_user(sParaTemp);
            Response.Write(sHtmlText);
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //读取站点配置信息
            Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig();

            //=============================获得订单信息================================
            string action = DTRequest.GetQueryString("action");
            string order_type = "";
            string order_no = "";
            decimal order_amount = 0;
            string user_name = "";
            string subject = "";
            if (action == "pay")
            {
                //获得订单信息
                order_type = DTRequest.GetQueryString("pay_order_type"); //订单类型
                order_no = DTRequest.GetQueryString("pay_order_no");
                order_amount = DTRequest.GetQueryDecimal("pay_order_amount", 0);
                user_name = DTRequest.GetQueryString("pay_user_name");
                subject = DTRequest.GetQueryString("pay_subject");
            }
            else
            {
                //获得订单信息
                order_type = DTRequest.GetFormString("pay_order_type"); //订单类型
                order_no = DTRequest.GetFormString("pay_order_no");
                order_amount = DTRequest.GetFormDecimal("pay_order_amount", 0);
                user_name = DTRequest.GetFormString("pay_user_name");
                subject = DTRequest.GetFormString("pay_subject");
            }
            //以下收货人信息
            string receive_name = string.Empty; //收货人姓名
            string receive_address = string.Empty; //收货人地址
            string receive_zip = string.Empty; //收货人邮编
            string receive_phone = string.Empty; //收货人电话
            string receive_mobile = string.Empty; //收货人手机
            //检查参数是否正确
            if (order_no == "" || order_amount == 0)
            {
                Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您提交的参数有误!")));
                return;
            }
            if (order_no.StartsWith("R")) //R开头为在线充值订单
            {
                Model.user_amount_log model = new BLL.user_amount_log().GetModel(order_no);
                if (model == null)
                {
                    Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您充值的订单号不存在或已删除!")));
                    return;
                }
                if (model.value != order_amount)
                {
                    Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您充值的订单金额与实际金额不一致!")));
                    return;
                }
                //取得用户信息
                Model.users userModel = new BLL.users().GetModel(model.user_id);
                if (userModel == null)
                {
                    Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,用户账户不存在或已删除!")));
                    return;
                }
                receive_name = userModel.nick_name;
                receive_address = userModel.address;
                receive_phone = userModel.telphone;
                receive_mobile = userModel.mobile;
            }
            else //B开头为商品订单
            {
                Model.orders model = new BLL.orders().GetModel(order_no);
                if (model == null)
                {
                    Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您支付的订单号不存在或已删除!")));
                    return;
                }
                if (model.order_amount != order_amount)
                {
                    Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您支付的订单金额与实际金额不一致!")));
                    return;
                }
                receive_name = model.accept_name;
                receive_address = model.address;
                receive_zip = model.post_code;
                receive_phone = model.telphone;
                receive_mobile = model.mobile;
            }
            if (user_name != "")
            {
                user_name = "支付会员:" + user_name;
            }
            else
            {
                user_name = "匿名用户";
            }

            //===============================请求参数==================================

            //判断担保或是即时到帐接口
            if (Config.Type == "1") //即时到帐
            {
                //把请求参数打包成数组
                SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>();
                sParaTemp.Add("payment_type", "1"); //收款类型1商品购买
                sParaTemp.Add("show_url", siteConfig.weburl); //商品展示地址
                sParaTemp.Add("out_trade_no", order_no); //网站订单号
                sParaTemp.Add("subject", siteConfig.webname + "-" + subject); //订单名称
                sParaTemp.Add("body", user_name); //订单描述
                sParaTemp.Add("total_fee", order_amount.ToString()); //订单总金额
                sParaTemp.Add("paymethod", ""); //默认支付方式
                sParaTemp.Add("defaultbank", ""); //默认网银代号
                sParaTemp.Add("anti_phishing_key", ""); //防钓鱼时间戳
                sParaTemp.Add("exter_invoke_ip", DTRequest.GetIP()); ////获取客户端的IP地址
                sParaTemp.Add("buyer_email", ""); //默认买家支付宝账号
                sParaTemp.Add("royalty_type", "");
                sParaTemp.Add("royalty_parameters", "");

                //构造即时到帐接口表单提交HTML数据,无需修改
                Service ali = new Service();
                string sHtmlText = ali.Create_direct_pay_by_user(sParaTemp);
                Response.Write(sHtmlText);
            }
            else //担保交易
            {
                //把请求参数打包成数组
                SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>();
                sParaTemp.Add("payment_type", "1"); //收款类型1商品购买
                sParaTemp.Add("out_trade_no", order_no); //网站订单号
                sParaTemp.Add("subject", siteConfig.webname + "-" + subject); //订单名称
                sParaTemp.Add("price", order_amount.ToString()); //付款金额
                sParaTemp.Add("quantity", "1"); //建议默认为1,不改变值,把一次交易看成是一次下订单而非购买一件商品
                sParaTemp.Add("logistics_fee", "0.00"); //物流费用
                sParaTemp.Add("logistics_type", "EXPRESS"); //物流类型,EXPRESS(快递)、POST(平邮)、EMS(EMS)
                sParaTemp.Add("logistics_payment", "SELLER_PAY"); //物流支付方式,SELLER_PAY(卖家承担运费)、BUYER_PAY(买家承担运费)
                sParaTemp.Add("body", user_name); //订单描述
                sParaTemp.Add("show_url", siteConfig.weburl); //商品展示地址
                sParaTemp.Add("receive_name", receive_name); //收货人姓名
                sParaTemp.Add("receive_address", receive_address); //收货人地址
                sParaTemp.Add("receive_zip", receive_zip); //收货人邮编
                sParaTemp.Add("receive_phone", receive_phone); //收货人电话号码
                sParaTemp.Add("receive_mobile", receive_mobile); //收货人手机号码
                //构造即时到帐接口表单提交HTML数据,无需修改
                Service ali = new Service();
                string sHtmlText = ali.Create_partner_trade_by_buyer(sParaTemp);
                Response.Write(sHtmlText);
            }
        }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //读取站点配置信息
            Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(DTKeys.FILE_SITE_XML_CONFING);

            //获得订单信息
            string order_type = DTRequest.GetFormString("pay_order_type"); //订单类型
            string order_no = DTRequest.GetFormString("pay_order_no");
            decimal order_amount = DTRequest.GetFormDecimal("pay_order_amount", 0);
            string user_name = DTRequest.GetFormString("pay_user_name");
            string subject = DTRequest.GetFormString("pay_subject");
            if (order_type == "" || order_no == "" || order_amount == 0 || user_name == "")
            {
                Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("对不起,您提交的参数有误!"));
                return;
            }

            ////////////////////////////////////////////请求参数////////////////////////////////////////////

            //必填参数//

            //请与贵网站订单系统中的唯一订单号匹配
            string out_trade_no = order_no;
            //订单名称,显示在支付宝收银台里的“商品名称”里,显示在支付宝的交易管理的“商品名称”的列表里。
            string _subject = siteConfig.webname + "-" + subject;
            //订单描述、订单详细、订单备注,显示在支付宝收银台里的“商品描述”里
            string body = "支付会员:" + user_name;
            //订单总金额,显示在支付宝收银台里的“应付总额”里
            string total_fee = order_amount.ToString();

            //扩展功能参数——默认支付方式//

            //默认支付方式,代码见“即时到帐接口”技术文档
            string paymethod = "";
            //默认网银代号,代号列表见“即时到帐接口”技术文档“附录”→“银行列表”
            string defaultbank = "";

            //扩展功能参数——防钓鱼//

            //防钓鱼时间戳
            string anti_phishing_key = "";
            //获取客户端的IP地址,建议:编写获取客户端IP地址的程序
            string exter_invoke_ip = "";

            //扩展功能参数——其他//

            //商品展示地址,要用http:// 格式的完整路径,不允许加?id=123这类自定义参数
            string show_url = siteConfig.weburl;
            //自定义参数,可存放任何内容(除=、&等特殊字符外),不会显示在页面上
            string extra_common_param = order_type;
            //默认买家支付宝账号
            string buyer_email = "";
            string royalty_type = "";
            string royalty_parameters = "";

            ////////////////////////////////////////////////////////////////////////////////////////////////

            //把请求参数打包成数组
            SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>();
            sParaTemp.Add("payment_type", "1");
            sParaTemp.Add("show_url", show_url);
            sParaTemp.Add("out_trade_no", out_trade_no);
            sParaTemp.Add("subject", _subject);
            sParaTemp.Add("body", body);
            sParaTemp.Add("total_fee", total_fee);
            sParaTemp.Add("paymethod", paymethod);
            sParaTemp.Add("defaultbank", defaultbank);
            sParaTemp.Add("anti_phishing_key", anti_phishing_key);
            sParaTemp.Add("exter_invoke_ip", exter_invoke_ip);
            sParaTemp.Add("extra_common_param", extra_common_param);
            sParaTemp.Add("buyer_email", buyer_email);
            sParaTemp.Add("royalty_type", royalty_type);
            sParaTemp.Add("royalty_parameters", royalty_parameters);

            //构造即时到帐接口表单提交HTML数据,无需修改
            Service ali = new Service();
            string sHtmlText = ali.Create_direct_pay_by_user(sParaTemp);
            Response.Write(sHtmlText);
        }