Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string suchtml = "<meta content=\"China TENCENT\" name=\"TENCENT_ONLINE_PAYMENT\">\n"
                             + "<script language=\"javascript\">\n"
                             + "window.location.href='http://" + Request.ServerVariables["Http_Host"] + "/Plugins/Pay/TenPay/Show.aspx';\n"
                             + "</script>";
            string errmsg = "";

            PayConfig payConfig = new PayConfig();
            Md5Pay    md5pay    = new Md5Pay();

            md5pay.Key          = payConfig.BusinessKey; //卖家商户key
            md5pay.Bargainor_id = payConfig.BargainorID;
            //判断签名
            if (md5pay.GetPayValueFromUrl(Request.QueryString, out errmsg))
            {
                //认证签名成功
                //支付判断
                if (md5pay.Pay_Result == Md5Pay.PAYOK)
                {
                    //支付成功,同定单号md5pay.Transaction_id可能会多次通知,请务必注意判断订单是否重复的逻辑
                    //跳转到成功页面,财付通收到<meta content=\"China TENCENT\" name=\"TENCENT_ONLINE_PAYMENT\">,认为通知成功
                    string    orderNumber = md5pay.Sp_billno;
                    OrderInfo order       = OrderBLL.ReadOrderByNumber(orderNumber, 0);
                    if (order.ID > 0)
                    {
                        if (order.OrderStatus == (int)OrderStatus.WaitPay)
                        {
                            order.OrderStatus = (int)OrderStatus.WaitCheck;
                            OrderBLL.UpdateOrder(order);
                            //增加操作记录
                            OrderActionInfo orderAction = new OrderActionInfo();
                            orderAction.OrderID          = order.ID;
                            orderAction.OrderOperate     = (int)OrderOperate.Pay;
                            orderAction.StartOrderStatus = (int)OrderStatus.WaitPay;
                            orderAction.EndOrderStatus   = (int)OrderStatus.WaitCheck;
                            orderAction.Note             = "客户财付通在线支付";
                            orderAction.IP        = ClientHelper.IP;
                            orderAction.Date      = RequestHelper.DateNow;
                            orderAction.AdminID   = 0;
                            orderAction.AdminName = string.Empty;
                            OrderActionBLL.AddOrderAction(orderAction);
                        }
                    }
                    else
                    {
                        UserRechargeInfo userRecharge = UserRechargeBLL.ReadUserRechargeByNumber(orderNumber, 0);
                        if (userRecharge.ID > 0 && userRecharge.IsFinish == (int)BoolType.False)
                        {
                            userRecharge.IsFinish = (int)BoolType.True;
                            UserRechargeBLL.UpdateUserRecharge(userRecharge);
                            //账户记录
                            string note = "财付通在线冲值:" + userRecharge.Number;
                            UserAccountRecordBLL.AddUserAccountRecord(userRecharge.Money, 0, note, userRecharge.UserID, userRecharge.UserName);
                        }
                    }
                    //StreamWriter sw = File.AppendText(Server.MapPath("log.txt"));
                    //sw.WriteLine(DateTime.Now.ToString() + orderNumber);
                    //sw.Flush();
                    //sw.Close();
                    Response.Write(suchtml);
                }
                else
                {
                    //支付失败,请不要按成功处理
                    Response.Write("支付失败" + errmsg);
                }
            }
            else
            {
                //认证签名失败
                Response.Write("认证签名失败");
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            PayConfig payConfig       = new PayConfig();
            string    alipayNotifyURL = "https://www.alipay.com/cooperate/gateway.do?";
            string    key             = payConfig.SecurityKey; //partner 的对应交易安全校验码(必须填写)
            string    partner         = payConfig.Partner;     //partner合作伙伴id(必须填写)

            alipayNotifyURL = alipayNotifyURL + "service=notify_verify" + "&partner=" + partner + "&notify_id=" + Request.Form["notify_id"];
            //获取支付宝ATN返回结果,true是正确的订单信息,false 是无效的
            string responseTxt = Get_Http(alipayNotifyURL, 120000000);
            int    i;
            NameValueCollection coll = Request.Form;

            String[] requestarr = coll.AllKeys;
            //进行排序;
            string[] Sortedstr = BubbleSort(requestarr);
            //构造待md5摘要字符串 ;
            string prestr = "";

            for (i = 0; i < Sortedstr.Length; i++)
            {
                if (Request.Form[Sortedstr[i]] != "" && Sortedstr[i] != "sign" && Sortedstr[i] != "sign_type")
                {
                    if (i == Sortedstr.Length - 1)
                    {
                        prestr = prestr + Sortedstr[i] + "=" + Request.Form[Sortedstr[i]];
                    }
                    else
                    {
                        prestr = prestr + Sortedstr[i] + "=" + Request.Form[Sortedstr[i]] + "&";
                    }
                }
            }
            prestr = prestr + key;
            //生成Md5摘要;
            string mysign = GetMD5(prestr);
            string sign   = Request.Form["sign"];

            //StreamWriter sw = File.AppendText(Server.MapPath("log.txt"));
            //sw.WriteLine(DateTime.Now.ToString() + "返回页面:" + RequestHelper.GetStringForm("out_trade_no") + ":" + Request.Form["trade_status"]);
            //sw.WriteLine("mysign:" + mysign + ";sign:" + sign + ";responseTxt:" + responseTxt);
            //sw.Flush();
            //sw.Close();

            if (mysign == sign && responseTxt == "true")   //验证支付发过来的消息,签名是否正确
            {
                //sw = File.AppendText(Server.MapPath("log.txt"));
                //sw.WriteLine(DateTime.Now.ToString() + "验证成功:" + RequestHelper.GetStringForm("out_trade_no") +":"+ Request.Form["trade_status"]);
                //sw.Flush();
                //sw.Close();

                if (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "WAIT_SELLER_SEND_GOODS")//   判断支付状态TRADE_FINISHED(文档中有枚举表可以参考)
                {
                    //更新数据库的订单语句
                    string    orderNumber = RequestHelper.GetForm <string>("out_trade_no");
                    OrderInfo order       = OrderBLL.ReadOrderByNumber(orderNumber, 0);
                    if (order.ID > 0)
                    {
                        if (order.OrderStatus == (int)OrderStatus.WaitPay)
                        {
                            order.OrderStatus = (int)OrderStatus.WaitCheck;
                            OrderBLL.UpdateOrder(order);
                            //增加操作记录
                            OrderActionInfo orderAction = new OrderActionInfo();
                            orderAction.OrderID          = order.ID;
                            orderAction.OrderOperate     = (int)OrderOperate.Pay;
                            orderAction.StartOrderStatus = (int)OrderStatus.WaitPay;
                            orderAction.EndOrderStatus   = (int)OrderStatus.WaitCheck;
                            orderAction.Note             = "客户支付宝在线支付";
                            orderAction.IP        = ClientHelper.IP;
                            orderAction.Date      = RequestHelper.DateNow;
                            orderAction.AdminID   = 0;
                            orderAction.AdminName = string.Empty;
                            OrderActionBLL.AddOrderAction(orderAction);
                        }
                    }
                    else
                    {
                        UserRechargeInfo userRecharge = UserRechargeBLL.ReadUserRechargeByNumber(orderNumber, 0);
                        if (userRecharge.ID > 0 && userRecharge.IsFinish == (int)BoolType.False)
                        {
                            userRecharge.IsFinish = (int)BoolType.True;
                            UserRechargeBLL.UpdateUserRecharge(userRecharge);
                            //账户记录
                            string note = "支付宝在线冲值:" + userRecharge.Number;
                            UserAccountRecordBLL.AddUserAccountRecord(userRecharge.Money, 0, note, userRecharge.UserID, userRecharge.UserName);
                        }
                    }
                    Response.Write("success");
                }
                else
                {
                    Response.Write("fail");
                }
            }
            else
            {
                Response.Write("fail");
            }
        }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            PayConfig payConfig       = new PayConfig();
            string    alipayNotifyURL = "https://www.alipay.com/cooperate/gateway.do?";
            string    key             = payConfig.SecurityKey; //partner 的对应交易安全校验码(必须填写)
            string    _input_charset  = "utf-8";
            string    partner         = payConfig.Partner;     //partner合作伙伴id(必须填写)

            alipayNotifyURL = alipayNotifyURL + "service=notify_verify" + "&partner=" + partner + "&notify_id=" + Request.QueryString["notify_id"];
            //获取支付宝ATN返回结果,true是正确的订单信息,false 是无效的
            string responseTxt = Get_Http(alipayNotifyURL, 120000);
            int    i;
            NameValueCollection coll = Request.QueryString;

            String[] requestarr = coll.AllKeys;
            //进行排序;
            string[] Sortedstr = BubbleSort(requestarr);
            //构造待md5摘要字符串 ;
            StringBuilder prestr = new StringBuilder();

            for (i = 0; i < Sortedstr.Length; i++)
            {
                if (Request.Form[Sortedstr[i]] != "" && Sortedstr[i] != "sign" && Sortedstr[i] != "sign_type")
                {
                    if (i == Sortedstr.Length - 1)
                    {
                        prestr.Append(Sortedstr[i] + "=" + Request.QueryString[Sortedstr[i]]);
                    }
                    else
                    {
                        prestr.Append(Sortedstr[i] + "=" + Request.QueryString[Sortedstr[i]] + "&");
                    }
                }
            }
            prestr.Append(key);
            //生成Md5摘要;
            string mysign = GetMD5(prestr.ToString(), _input_charset);
            string sign   = Request.QueryString["sign"];

            if (mysign == sign && responseTxt == "true")   //验证支付发过来的消息,签名是否正确
            {
                //更新数据库的订单语句
                message = "成功付款";
                string    orderNumber = RequestHelper.GetQueryString <string>("out_trade_no");
                OrderInfo order       = OrderBLL.ReadOrderByNumber(orderNumber, 0);
                if (order.ID > 0)
                {
                    if (order.OrderStatus == (int)OrderStatus.WaitPay)
                    {
                        order.OrderStatus = (int)OrderStatus.WaitCheck;
                        OrderBLL.UpdateOrder(order);
                        //增加操作记录
                        OrderActionInfo orderAction = new OrderActionInfo();
                        orderAction.OrderID          = order.ID;
                        orderAction.OrderOperate     = (int)OrderOperate.Pay;
                        orderAction.StartOrderStatus = (int)OrderStatus.WaitPay;
                        orderAction.EndOrderStatus   = (int)OrderStatus.WaitCheck;
                        orderAction.Note             = "客户支付宝在线支付";
                        orderAction.IP        = ClientHelper.IP;
                        orderAction.Date      = RequestHelper.DateNow;
                        orderAction.AdminID   = 0;
                        orderAction.AdminName = string.Empty;
                        OrderActionBLL.AddOrderAction(orderAction);

                        message = "您已经成功支付订单:" + orderNumber;
                    }
                }
                else
                {
                    UserRechargeInfo userRecharge = UserRechargeBLL.ReadUserRechargeByNumber(orderNumber, 0);
                    if (userRecharge.ID > 0 && userRecharge.IsFinish == (int)BoolType.False)
                    {
                        userRecharge.IsFinish = (int)BoolType.True;
                        UserRechargeBLL.UpdateUserRecharge(userRecharge);
                        //账户记录
                        string note = "支付宝在线冲值:" + userRecharge.Number;
                        UserAccountRecordBLL.AddUserAccountRecord(userRecharge.Money, 0, note, userRecharge.UserID, userRecharge.UserName);

                        message = "您的冲值已经成功完成";
                    }
                }
            }
            else
            {
                message = "支付订单出现问题";
            }
        }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            PayConfig payConfig      = new PayConfig();
            string    merchant_key   = payConfig.MerchantKey;                ///商户密钥
            string    merchant_id    = Request["merchant_id"].ToString();    ///获取商户编号
            string    orderid        = Request["orderid"].ToString();        ///获取订单编号
            string    amount         = Request["amount"].ToString();         ///获取订单金额
            string    dealdate       = Request["date"].ToString();           ///获取交易日期
            string    succeed        = Request["succeed"].ToString();        ///获取交易结果,Y成功,N失败
            string    mac            = Request["mac"].ToString();            ///获取安全加密串
            string    merchant_param = Request["merchant_param"].ToString(); ///获取商户私有参数

            string couponid    = Request["couponid"].ToString();             ///获取优惠券编码
            string couponvalue = Request["couponvalue"].ToString();          ///获取优惠券面额

            ///生成加密串,注意顺序
            string SrctStr = "merchant_id=" + merchant_id + "&orderid=" + orderid + "&amount=" + amount + "&date=" + dealdate + "&succeed=" + succeed + "&merchant_key=" + merchant_key;
            string mymac   = FormsAuthentication.HashPasswordForStoringInConfigFile(SrctStr, "MD5");


            if (mac == mymac)
            {
                if (succeed == "Y")
                {
                    //更新数据库的订单语句
                    message = "成功付款";
                    string    orderNumber = orderid;
                    OrderInfo order       = OrderBLL.ReadOrderByNumber(orderNumber, 0);
                    if (order.ID > 0)
                    {
                        if (order.OrderStatus == (int)OrderStatus.WaitPay)
                        {
                            order.OrderStatus = (int)OrderStatus.WaitCheck;
                            OrderBLL.UpdateOrder(order);
                            //增加操作记录
                            OrderActionInfo orderAction = new OrderActionInfo();
                            orderAction.OrderID          = order.ID;
                            orderAction.OrderOperate     = (int)OrderOperate.Pay;
                            orderAction.StartOrderStatus = (int)OrderStatus.WaitPay;
                            orderAction.EndOrderStatus   = (int)OrderStatus.WaitCheck;
                            orderAction.Note             = "客户快钱在线支付";
                            orderAction.IP        = ClientHelper.IP;
                            orderAction.Date      = RequestHelper.DateNow;
                            orderAction.AdminID   = 0;
                            orderAction.AdminName = string.Empty;
                            OrderActionBLL.AddOrderAction(orderAction);

                            message = "您已经成功支付订单:" + orderNumber;
                        }
                    }
                    else
                    {
                        UserRechargeInfo userRecharge = UserRechargeBLL.ReadUserRechargeByNumber(orderNumber, 0);
                        if (userRecharge.ID > 0 && userRecharge.IsFinish == (int)BoolType.False)
                        {
                            userRecharge.IsFinish = (int)BoolType.True;
                            UserRechargeBLL.UpdateUserRecharge(userRecharge);
                            //账户记录
                            string note = "快钱在线冲值:" + userRecharge.Number;
                            UserAccountRecordBLL.AddUserAccountRecord(userRecharge.Money, 0, note, userRecharge.UserID, userRecharge.UserName);

                            message = "您的冲值已经成功完成";
                        }
                    }
                }
                else
                {
                    message = "支付订单失败";
                }
            }
            else
            {
                message = "签名错误";
            }
        }