<%@ Page Language="C#" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Kesion.APPCode" %>
<%@ Import Namespace="Kesion.Components" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="com.unionpay.acp.sdk" %>

<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
    <title>用户管理中心</title>
    <link href="/sysimg/user/css.css" rel="stylesheet" type="text/css" />
    <script src="<%=MyCache.GetCacheConfig(0) %>ks_inc/jquery.js"></script>
    <script src="<%=MyCache.GetCacheConfig(0) %>ks_inc/kesion.common.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="reg_top" style="background: #fff; height: 75px; font-size: 14px; position: relative; z-index: 99; border-bottom: 1px solid #d5d5d5;">
            <div class="mainbox">
                <div style="float: right; line-height: 75px;"><a href="/" target="_blank">返回首页</a> &nbsp; | &nbsp; <a href="javascirpt:void(0)" onclick="window.close()">关闭当前页</a></a></div>
                <div style="float: left; margin-top: 16px;">
                    <a href="<%=MyCache.GetCacheConfig(0) %>" title="进入首页" target="_blank">
                        <img src="<%=MyCache.GetCacheConfig(6)%>" /></a>
                </div>
            </div>

        </div>
        <div class="clear"></div>


        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
        <asp:Label ID="LabHiddenField" runat="server"></asp:Label>



        <div class="clear"></div>
        <div class="copyright" style="text-align: center; padding-top: 10px; border-top: 1px solid #e5e5e5;">
            <%=MyCache.GetCacheConfig(11) %>
        </div>
    </form>
</body>
</html>

<script runat="server" type="text/C#">
    public static int platId = 0;
    public static string AccountID = string.Empty;
    public static string Md5Key = string.Empty;
    public static int RateByUser = 0;
    public static decimal rate = 0;


    public void InitialPage()
    {

        platId = Utils.StrToInt(KSCMS.S("platid"));
        if (platId == 0)
        {
            platId = Utils.StrToInt(KSCMS.S("payId"));
        }
        if (platId == 0)
        {
            platId = Utils.StrToInt(DataFactory.GetOnlyValue("select top 1 id from KS_PaymentPlat where isdefault=1"));
        }
        if (platId == 0) KSCMS.Die("找不到支付接口！");
        SqlParam[] p = new SqlParam[1];
        p[0] = new SqlParam("ID", platId);

        using (DataTable dt = CommonData.GetDataTable("[KS_PaymentPlat]", "AccountID,MD5Key,RateByUser,Rate", p))
        {
            if (dt.Rows.Count >= 0)
            {
                AccountID = dt.Rows[0][0].ToString();
                Md5Key = dt.Rows[0][1].ToString();
                RateByUser = Convert.ToInt16(dt.Rows[0][2].ToString());
                rate = Convert.ToDecimal(dt.Rows[0][3].ToString());
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        InitialPage();
        // KSCMS.Die("aaaa");
        string subject = "";    //标题
        string v_oid = "";                 //订单编号
        string v_amount = "";              //实际支付金额       
        string v_mid = "";                 //商户编号
        string v_url = "";                 //支付动作完成后返回到该url，支付结果以POST方式发送
        string payOnlineKey = "";        //MD5私钥

        decimal vmoney = 0;           //支付金额   
        int payPlatformId = platId;           //支付平台ID
        string md5string;             //订单MD5校验码
        string orderId;              //订单ID
        string userName = "";          //登录用户名
        string paymentNum = "";       //支付序号

        string m_PayOnlineProviderUrl = "";
        string m_HiddenValue = string.Empty;
        string partner = string.Empty;


        orderId = Utils.RemoveXss(Utils.ChkSQL(KSCMS.S("OrderId")));
        if (string.IsNullOrEmpty(orderId))
        {
            orderId = Utils.RemoveXss(Utils.ChkSQL(KSCMS.S("payorderid")));
        }

        userName = (new TemporaryVar()).UserName;
        vmoney = Convert.ToDecimal(Utils.StrToFloat(KSCMS.S("Money"), 0));

        // Utils.WriteLog("vmoney =" + vmoney);

        #region 支付配置
        string from = KSCMS.S("from");
        string itemstr = string.Empty;


        v_oid = orderId;
        v_mid = AccountID;

        payOnlineKey = Md5Key;


        DateTime datatime = DateTime.Now;
        string v_hms = datatime.ToString("HHmmss", System.Globalization.DateTimeFormatInfo.InvariantInfo);
        string v_ymd = datatime.ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);

        StringBuilder strHiddenField = new StringBuilder();
        StringBuilder md5Builder = new StringBuilder();
        StringBuilder v_urlBuilder = new StringBuilder();    //构造返回URL

        string applicationName = KSCMS.GetInstallDir();
        bool isFabrication = false;

        v_urlBuilder.Append(MyCache.GetCacheConfig(5));
        v_urlBuilder.Append(applicationName);

        string v_ShowResultUrl = v_urlBuilder.ToString() + "plus/Pay/PayRecive.aspx?paymentplat=" + payPlatformId + "&userid=" + (new TemporaryVar()).UserID;




        int OrderType = Utils.StrToInt(KSCMS.S("OrderType"), 0);
        string str = "课程";
        if (OrderType == 1)
        {
            using (DataTable dtt = DataFactory.GetDataTable("select top 50 b.cname,a.username,a.userid from ks_cosorder a inner join  ks_cosorderitem b on a.orderid=b.orderid where a.status=0 and  a.courseorder='" + orderId + "'"))
            {
                if (dtt.Rows.Count > 0)
                {
                    foreach (DataRow drr in dtt.Rows)
                    {
                        str += drr["cname"].ToString() + "<br/>";
                        #region     用户名是否为空进行判断以及赋值
                        if (string.IsNullOrEmpty(userName) || new TemporaryVar().UserID <= 0)
                        {
                            userName = drr["UserName"].ToString();
                        }
                        #endregion
                    }
                }
            }
            subject = "购买课程：" + Utils.CutStr(str.Replace("<br/>", " "), 200) + "订单号：" + v_oid; ;

        }
        else if (OrderType == 2)
        {
            subject = "支付套餐包【" + Utils.ChkSQL(KSCMS.S("packname")) + "】订单号：" + v_oid;
            if (string.IsNullOrEmpty(userName) || new TemporaryVar().UserID <= 0)
            {
                userName = DataFactoryUser.GetOnlyValue("select top 1 username From KS_RechargeRecords Where Status = 0 and OrderID = '" + v_oid + "'");
            }
        }
        else if (OrderType == 3)
        {
            #region 单个订单支付
            using (DataTable dt = DataFactory.GetDataTable("select top 1 * from ks_proorder where payorderid='" + orderId + "'"))
            {
                if (dt.Rows.Count <= 0)
                {
                    Utils.ShowError("找不到该订单，无法支付!", 1);
                }
                else
                {
                    DataRow dr = dt.Rows[0];
                    if (Utils.StrToFloat(dr["MoneyReceipt"].ToString()) >= Utils.StrToFloat(dr["OrderTotalPrice"].ToString()))
                    {
                        Utils.ShowError("该订单已支付过了，不需要再支付!", 1);
                    }
                    else if (dr["status"].ToString() == "2")
                    {
                        Utils.ShowError("该订单已结清，不能再支付了!", 1);
                    }
                    else if (dr["status"].ToString() == "3")
                    {
                        Utils.ShowError("该订单已失效，不能再支付了!", 1);
                    }

                    string strSQL = string.Empty;
                    if (dr["orderType"].ToString() == "1")
                    {
                        strSQL = "select top 100  i.subject as title from KS_ProOrderItem o left join KS_ProGroupBuy I on i.id=o.infoid where o.Orderid='" + dr["orderid"].ToString() + "' order by o.itemid";
                    }
                    if (dr["orderType"].ToString() == "2")
                    {
                        strSQL = "select top 100 i.Subject as title  from KS_ProOrderItem o left join KS_ProFightGroup I on i.id=o.infoid where o.Orderid='" + dr["orderid"].ToString() + "' order by o.itemid";

                    }
                    else
                    {
                        strSQL = "select top 100 i.title from KS_ProOrderItem o left join KS_ProductList I on i.infoid=o.infoid where o.Orderid='" + dr["orderid"].ToString() + "' order by o.itemid";

                    }

                    using (DataTable dtt = DataFactory.GetDataTable(strSQL))
                    {
                        if (dtt.Rows.Count > 0)
                        {
                            foreach (DataRow drr in dtt.Rows)
                            {
                                itemstr += drr["title"].ToString() + "<br/>";
                            }
                        }
                    }
                    //   this.LabShopInfo.Text = "<br/><strong>购买商品：</strong><span class='tips'><br/>"+itemstr+"</span>";

                }
            }
            subject = "支付【" + Utils.CutStr(itemstr.Replace("<br/>", " "), 200) + "】订单号：" + orderId;
            #endregion
        }
        else if (OrderType == 5)
        {
            #region 自定义表单的支付
            using (DataTable dt = DataFactory.GetDataTable("Select top 1 * From KS_Form Where FormID=" + Utils.StrToInt(KSCMS.S("formID")) + ""))
            {
                if (dt.Rows.Count <= 0)
                {
                    Utils.ShowError("找不到该表单，无法支付!", 1);
                }
                else
                {
                    DataRow dr = dt.Rows[0];
                    subject = "支付[" + dr["subject"].ToString() + "]费用";
                    using (DataTable dti = DataFactory.GetDataTable("select top 1 recordid From KS_FormRecord" + dr["formid"].ToString() + " Where ispay=1 and Recordid=" + Utils.StrToInt(KSCMS.S("Recordid"))))
                    {
                        if (dti.Rows.Count > 0)
                        {
                            Utils.ShowError("该订单已支付过，不能再支付了!", 1);
                        }
                    }

                }
            }
            #endregion

        }
        else if (OrderType == 6)
        {
            #region  一元购支付

            string orderid = string.Empty;
            using (DataTable dt = DataFactory.GetDataTable("select * from ks_progrouponeorder where payorderid='" + orderId + "'"))
            {
                if (dt.Rows.Count <= 0)
                {
                    Utils.ShowError("找不到该订单，无法支付!", 1);
                }
                else
                {
                    vmoney = 0;
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (Utils.StrToInt(dr["Nowstatus"].ToString()) == 0)
                        {
                            vmoney += Utils.StrToDecimal(dr["OrderNowPrice"].ToString());
                        }

                    }

                }
            }
            #endregion
        }
        else if (OrderType == 7)
        {
            #region 单个课时购买
            orderId = orderId.ToUpper();
            using (DataTable dt = DataFactory.GetDataTable("select top 1 * from ks_CosPeriodPay where Orderid='" + orderId + "'"))
            {
                if (dt.Rows.Count <= 0)
                {
                    Utils.ShowError("找不到该订单，无法支付!", 1);
                }
                else
                {
                    DataRow dr = dt.Rows[0];
                    if (dr["status"].ToString() == "1")
                    {
                        Utils.ShowError("该订单已支付，不能再支付了!", 1);
                    }
                    subject = DataFactory.GetOnlyValue("Select top 1 cbname from KS_CosLiveCombo  Where id= " + dr["acid"].ToString());
                }
            }
            #endregion
        }
        else if (OrderType == 8)
        {
            #region 道具购买

            using (DataTable dt = DataFactory.GetDataTable("select top 1 * from KS_CosLiveacOrder where Orderid='" + orderId + "'"))
            {
                if (dt.Rows.Count <= 0)
                {
                    Utils.ShowError("找不到该订单，无法支付!", 1);
                }
                else
                {
                    DataRow dr = dt.Rows[0];
                    if (dr["status"].ToString() == "1")
                    {
                        Utils.ShowError("该订单已支付，不能再支付了!", 1);
                    }
                    subject = DataFactory.GetOnlyValue("Select top 1 cbname from KS_CosLiveCombo  Where id= " + dr["acid"].ToString());
                }
            }
            #endregion

        }
        else if (OrderType == 9)
        {
            subject = "支付VIP【" + Utils.ChkSQL(KSCMS.S("packname")) + "】订单号：" + v_oid;
        }
        else if (OrderType == 10)   //课程拼团
        {
            #region 课程拼团
            orderId = orderId.ToUpper();
            using (DataTable dt = DataFactory.GetDataTable("SELECT TOP 1 * FROM KS_CosCollageDetail WHERE PayOrder = '" + orderId + "'"))
            {
                if (dt.Rows.Count <= 0)
                {
                    Utils.ShowError("找不到该订单，无法支付!", 1);
                }
                else
                {
                    DataRow dr = dt.Rows[0];
                    if (dr["Status"].ToString() == "1")
                    {
                        Utils.ShowError("该订单已支付，不能再支付了!", 1);
                    }
                    subject = "支付拼团课程[" + dr["Cname"].ToString() + "]订单号：" + v_oid;
                }
            }
            #endregion
            
        }
        else if (OrderType == 11)   //课程砍价
        {
            //获取订单金额
            using (DataTable dt = DataFactory.GetDataTable("SELECT TOP 1 Name,Payment,Status FROM KS_CosBargainDetail WHERE PayOrderID = '" + orderId + "'"))
            {
                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    if (dr["Status"].ToString() == "1")
                    {
                        Utils.ShowError("该订单已支付，不能再支付了!", 1);
                    }
                    else
                    {
                        vmoney =Utils.StrToDecimal(dr["Payment"].ToString());
                        subject = "支付砍价课程【" + dr["Name"].ToString() + "】订单号：" + v_oid;
                    }
                }
            }

        }
        else
        {
            #region 继续完成在线充值
            if (from == "recharge")
            {
                using (DataTable dt = DataFactoryUser.GetDataTable("Select top 1 * From KS_RechargeRecords Where OrderID='" + orderId + "'"))
                {
                    if (dt.Rows.Count <= 0)
                    {
                        Utils.ShowError("找不到该订单，无法支付!", 1);
                    }
                    else
                    {
                        DataRow dr = dt.Rows[0];
                        if (dr["status"].ToString() != "0")
                        {
                            Utils.ShowError("该订单已支付过，不能再支付了!", 1);
                        }
                        vmoney = Convert.ToDecimal(dr["paymoney"].ToString());
                        payPlatformId = Utils.StrToInt(dr["platid"].ToString());
                        subject = dr["remark"].ToString();
                    }
                }
            }
            else
            {
                subject = "【" + MyCache.GetCacheConfig(1) + "】在线充值，订单号：" + v_oid;
            }
            #endregion
        }
        double realmoney = Convert.ToDouble(vmoney);  //实际入账金额,不含手续费
        if (RateByUser == 1 && from != "recharge")
        {
            v_amount = decimal.Round(vmoney + vmoney * rate / 100, 2).ToString();
        }
        else
        {
            // showrate.Visible = false;
            v_amount = decimal.Round(vmoney, 2).ToString();
        }
        vmoney = decimal.Round(vmoney, 2);

        paymentNum = v_oid;

        if (vmoney < 0.01M)
        {
            Utils.ShowError("支付金额太小!", 6);
            return;
        }

        if (from != "recharge")
        {
            addToRechargeRecords(orderId, Convert.ToDouble(v_amount), realmoney, subject, payPlatformId, OrderType);
        }


        #endregion

        switch (payPlatformId)
        {
            case 1:    //网银在线
                m_PayOnlineProviderUrl = "https://pay3.chinabank.com.cn/PayGate";
                //生成MD5校验数据字符串
                md5Builder.Append(v_amount);
                md5Builder.Append("0");
                md5Builder.Append(v_oid);
                md5Builder.Append(v_mid);
                md5Builder.Append(v_ShowResultUrl);
                md5Builder.Append(payOnlineKey);
                md5string = Utils.MD5(md5Builder.ToString()).ToUpper();

                strHiddenField.Append("<input type='hidden' name='v_md5info' value='" + md5string + "'>");
                strHiddenField.Append("<input type='hidden' name='v_mid' value='" + v_mid + "'>");
                strHiddenField.Append("<input type='hidden' name='v_oid' value='" + v_oid + "'>");
                strHiddenField.Append("<input type='hidden' name='v_amount' value='" + v_amount + "'>");
                strHiddenField.Append("<input type='hidden' name='v_moneytype'  value='0'>");
                strHiddenField.Append("<input type='hidden' name='v_url' value='" + v_ShowResultUrl + "'>");
                break;

            case 2://'中国在线支付网
                m_PayOnlineProviderUrl = "http://www.ipay.cn/4.0/bank.shtml";
                v_urlBuilder.Append("PayOnline/PayResultIpay.aspx");
                v_url = v_urlBuilder.ToString();

                md5Builder.Append(v_mid);
                md5Builder.Append(v_oid);
                md5Builder.Append(v_amount);
                md5Builder.Append("test@Ipay.com.cn13800138000");
                md5Builder.Append(payOnlineKey);
                md5string = Utils.MD5(md5Builder.ToString());

                strHiddenField.Append("<input type='hidden' name='v_mid' value='" + v_mid + "'>");
                strHiddenField.Append("<input type='hidden' name='v_oid' value='" + v_oid + "'>");
                strHiddenField.Append("<input type='hidden' name='v_amount' value='" + v_amount + "'>");
                strHiddenField.Append("<input type='hidden' name='v_email' value='test@Ipay.com.cn'>");
                strHiddenField.Append("<input type='hidden' name='v_mobile' value='13800138000'>");
                strHiddenField.Append("<input type='hidden' name='v_md5' value='" + md5string + "'>");
                strHiddenField.Append("<input type='hidden' name='v_url' value='" + v_url + "'>");
                break;

            case 3://上海环迅
                m_PayOnlineProviderUrl = "http://pay.ips.com.cn/ipayment.aspx";
                //m_PayOnlineProviderUrl = "http://pay.ips.net.cn/ipayment.aspx";  //测试接口，配合测试帐号测试
                v_urlBuilder.Append("Plus/Pay/PayResultIps.aspx");
                v_url = v_urlBuilder.ToString();

                md5Builder.Append(v_oid);
                md5Builder.Append(v_amount);
                md5Builder.Append(v_ymd);
                md5Builder.Append("RMB");
                md5Builder.Append(payOnlineKey);
                md5string = Utils.MD5(md5Builder.ToString()).ToLower();

                strHiddenField.Append("<input type='hidden' name='mer_code' value='" + v_mid + "'>");
                strHiddenField.Append("<input type='hidden' name='billNo' value='" + v_oid + "'>");
                strHiddenField.Append("<input type='hidden' name='amount' value='" + v_amount + "'>");
                strHiddenField.Append("<input type='hidden' name='date' value='" + v_ymd + "'>");
                strHiddenField.Append("<input type='hidden' name='lang' value='GB'>");
                strHiddenField.Append("<input type='hidden' name='Gateway_type' value='01'>");
                strHiddenField.Append("<input type='hidden' name='Currency_Type' value='RMB'>");
                strHiddenField.Append("<input type='hidden' name='Merchanturl' value='" + v_url + "'>");
                strHiddenField.Append("<input type='hidden' name='OrderEncodeType' value='2'>");
                strHiddenField.Append("<input type='hidden' name='RetEncodeType' value='12'>");
                strHiddenField.Append("<input type='hidden' name='RetType' value='0'>");
                strHiddenField.Append("<input type='hidden' name='SignMD5' value='" + md5string + "'>");
                strHiddenField.Append("<input type='hidden' name='ServerUrl' value=''>");
                break;
            case 4://西部支付
                m_PayOnlineProviderUrl = "http://www.yeepay.com/Pay/WestPayReceiveOrderFromMerchant.asp";
                v_urlBuilder.Append("Plus/Pay/PayResultYeepay.aspx");
                v_url = v_urlBuilder.ToString();

                strHiddenField.Append("<input type='hidden' name='MerchantID' value='" + v_mid + "'>");
                strHiddenField.Append("<input type='hidden' name='OrderNumber' value='" + v_oid + "'>");
                strHiddenField.Append("<input type='hidden' name='OrderAmount' value='" + v_amount + "'>");
                strHiddenField.Append("<input type='hidden' name='PostBackURL' value='" + v_url + "'>");
                break;

            case 5://易付通
                m_PayOnlineProviderUrl = "http://pay.xpay.cn/Pay.aspx";
                v_urlBuilder.Append("Plus/Pay/PayResultXpay.aspx");
                v_url = v_urlBuilder.ToString();

                md5Builder.Append(payOnlineKey);
                md5Builder.Append(":");
                md5Builder.Append(v_amount);
                md5Builder.Append(",");
                md5Builder.Append(v_oid);
                md5Builder.Append(",");
                md5Builder.Append(v_mid);
                md5Builder.Append(",bank,,sell,,2.0");
                md5string = Utils.MD5(md5Builder.ToString()).ToLower();

                strHiddenField.Append("<input type='hidden' name='Tid' value='" + v_mid + "'>");
                strHiddenField.Append("<input type='hidden' name='Bid' value='" + v_oid + "'>");
                strHiddenField.Append("<input type='hidden' name='Prc' value='" + v_amount + "'>");
                strHiddenField.Append("<input type='hidden' name='url' value='" + v_url + "'>");
                strHiddenField.Append("<input type='hidden' name='Card' value='bank'>");
                strHiddenField.Append("<input type='hidden' name='Scard' value=''>");
                strHiddenField.Append("<input type='hidden' name='ActionCode' value='sell'>");
                strHiddenField.Append("<input type='hidden' name='ActionParameter' value=''>");
                strHiddenField.Append("<input type='hidden' name='Ver' value='2.0'>");
                strHiddenField.Append("<input type='hidden' name='Pdt' value='" + applicationName + "'>");
                strHiddenField.Append("<input type='hidden' name='type' value=''>");
                strHiddenField.Append("<input type='hidden' name='lang' value='gb2312'>");
                strHiddenField.Append("<input type='hidden' name='md' value='" + md5string + "'>");
                break;

            case 6://云网支付
                m_PayOnlineProviderUrl = "https://www.cncard.net/purchase/getorder.asp";
                v_urlBuilder.Append("Plus/Pay/PayResultCncard.aspx");
                v_url = v_urlBuilder.ToString();

                md5Builder.Append(v_mid);
                md5Builder.Append(v_oid);
                md5Builder.Append(v_amount);
                md5Builder.Append(v_ymd);
                md5Builder.Append("01");
                md5Builder.Append(v_url);
                md5Builder.Append("00");
                md5Builder.Append(payOnlineKey);
                md5string = Utils.MD5(md5Builder.ToString()).ToLower();

                strHiddenField.Append("<input type='hidden' name='c_mid' value='" + v_mid + "'>");
                strHiddenField.Append("<input type='hidden' name='c_order' value='" + v_oid + "'>");
                strHiddenField.Append("<input type='hidden' name='c_orderamount' value='" + v_amount + "'>");
                strHiddenField.Append("<input type='hidden' name='c_ymd' value='" + v_ymd + "'>");
                strHiddenField.Append("<input type='hidden' name='c_moneytype' value='0'>");
                strHiddenField.Append("<input type='hidden' name='c_retflag' value='1'>");
                strHiddenField.Append("<input type='hidden' name='c_paygate' value=''>");
                strHiddenField.Append("<input type='hidden' name='c_returl' value='" + v_url + "'>");
                strHiddenField.Append("<input type='hidden' name='c_memo1' value=''>");
                strHiddenField.Append("<input type='hidden' name='c_memo2' value=''>");
                strHiddenField.Append("<input type='hidden' name='c_language' value='0'>");
                strHiddenField.Append("<input type='hidden' name='notifytype' value='0'>");
                strHiddenField.Append("<input type='hidden' name='c_signstr' value='" + md5string + "'>");
                break;
            case 8:   //支付宝即时到帐
                      // m_PayOnlineProviderUrl = "https://www.alipay.com/cooperate/gateway.do?_input_charset=utf-8";

                m_PayOnlineProviderUrl = "https://mapi.alipay.com/gateway.do?_input_charset=utf-8";
                v_urlBuilder.Append("Plus/Pay/AlipayNotify.aspx?from=" + from + "&paymentplat=" + payPlatformId + "&userid=" + (new TemporaryVar()).UserID);
                v_url = v_urlBuilder.ToString();
                if (payOnlineKey.IndexOf("|") > 0)
                {
                    string[] ArrMD5Key = payOnlineKey.Split(new char[] { '|' });
                    payOnlineKey = ArrMD5Key[0];
                    partner = ArrMD5Key[1];
                }
                md5Builder.Append("_input_charset=utf-8");
                md5Builder.Append("&discount=0");
                md5Builder.Append("&extend_param=isv^1827506kx");
                md5Builder.Append("&notify_url=" + v_url);
                md5Builder.Append("&out_trade_no=" + v_oid);
                md5Builder.Append("&partner=" + partner);
                md5Builder.Append("&payment_type=1");
                if (!Utils.IsMobileDevice())  //PC网站支付
                {
                    md5Builder.Append("&price=" + v_amount);
                }
                md5Builder.Append("&quantity=1");
                md5Builder.Append("&return_url=" + v_ShowResultUrl);

                if (Utils.IsMobileDevice())  //手机网站支付
                {
                    md5Builder.Append("&seller_id=" + partner);
                    md5Builder.Append("&service=alipay.wap.create.direct.pay.by.user");
                }
                else
                {
                    md5Builder.Append("&seller_email=" + v_mid);
                    md5Builder.Append("&service=create_direct_pay_by_user");
                }



                md5Builder.Append("&subject=" + subject);
                if (Utils.IsMobileDevice())  //手机网站支付
                {
                    md5Builder.Append("&total_fee=" + v_amount);
                }
                md5Builder.Append(payOnlineKey);
                md5string = AlipayCore.Sign(md5Builder.ToString(), "MD5", "utf-8").ToLower();

                strHiddenField.Append("<input type='hidden' name='_input_charset' value='utf-8'>");
                strHiddenField.Append("<input type='hidden' name='extend_param' value='isv^1827506kx'>");
                strHiddenField.Append("<input type='hidden' name='discount' value='0'>\n");
                strHiddenField.Append("<input type='hidden' name='notify_url' value='" + v_url + "'>\n");
                strHiddenField.Append("<input type='hidden' name='out_trade_no' value='" + v_oid + "'>\n");
                strHiddenField.Append("<input type='hidden' name='payment_type' value='1'>\n");
                strHiddenField.Append("<input type='hidden' name='partner' value='" + partner + "'>\n");
                if (!Utils.IsMobileDevice())  //PC网站支付
                {
                    strHiddenField.Append("<input type='hidden' name='price' value='" + v_amount + "'>\n");
                }
                strHiddenField.Append("<input type='hidden' name='quantity' value='1'>\n");

                if (Utils.IsMobileDevice())  //手机网站支付
                {
                    strHiddenField.Append("<input type='hidden' name='seller_id' value='" + partner + "'>\n");
                    strHiddenField.Append("<input type='hidden' name='service' value='alipay.wap.create.direct.pay.by.user'>\n");
                }
                else
                {
                    strHiddenField.Append("<input type='hidden' name='seller_email' value='" + v_mid + "'>\n");
                    strHiddenField.Append("<input type='hidden' name='service' value='create_direct_pay_by_user'>\n");
                }
                strHiddenField.Append("<input type='hidden' name='subject' value='" + subject + "'>\n");
                strHiddenField.Append("<input type='hidden' name='sign' value='" + md5string + "'>\n");
                strHiddenField.Append("<input type='hidden' name='sign_type' value='MD5'>\n");
                if (Utils.IsMobileDevice())  //手机网站支付
                {
                    strHiddenField.Append("<input type='hidden' name='total_fee' value='" + v_amount + "'>\n");
                }
                strHiddenField.Append("<input type='hidden' name='return_url' value='" + v_ShowResultUrl + "'>\n");
                break;
            case 12:  //支付宝担保交易

                m_PayOnlineProviderUrl = "https://mapi.alipay.com/gateway.do?_input_charset=utf-8";
                v_urlBuilder.Append("Plus/Pay/AlipayNotify1.aspx?from=" + from + "&paymentplat=" + payPlatformId + "&userid=" + (new TemporaryVar()).UserID);
                v_url = v_urlBuilder.ToString();
                if (payOnlineKey.IndexOf("|") > 0)
                {
                    string[] ArrMD5Key = payOnlineKey.Split(new char[] { '|' });
                    payOnlineKey = ArrMD5Key[0];
                    partner = ArrMD5Key[1];
                }
                md5Builder.Append("_input_charset=utf-8");
                md5Builder.Append("&discount=0");
                md5Builder.Append("&extend_param=isv^1827506kx");
                md5Builder.Append("&logistics_fee=0");
                md5Builder.Append("&logistics_payment=SELLER_PAY");
                md5Builder.Append("&logistics_type=EXPRESS");
                md5Builder.Append("&notify_url=" + v_url);
                md5Builder.Append("&out_trade_no=" + v_oid);
                md5Builder.Append("&partner=" + partner);
                md5Builder.Append("&payment_type=1");
                md5Builder.Append("&price=" + v_amount);
                md5Builder.Append("&quantity=1");
                md5Builder.Append("&return_url=" + v_ShowResultUrl);
                md5Builder.Append("&seller_email=" + v_mid);
                md5Builder.Append("&service=create_partner_trade_by_buyer");
                md5Builder.Append("&subject=" + subject);
                md5Builder.Append(payOnlineKey);

                md5string = AlipayCore.Sign(md5Builder.ToString(), "MD5", "utf-8").ToLower();

                strHiddenField.Append("<input type='hidden' name='_input_charset' value='utf-8'>");
                strHiddenField.Append("<input type='hidden' name='discount' value='0'>");
                strHiddenField.Append("<input type='hidden' name='extend_param' value='isv^1827506kx'>");
                strHiddenField.Append("<input type='hidden' name='notify_url' value='" + v_url + "'>");
                strHiddenField.Append("<input type='hidden' name='logistics_fee' value='0'>");
                strHiddenField.Append("<input type='hidden' name='logistics_payment' value='SELLER_PAY'>");
                strHiddenField.Append("<input type='hidden' name='logistics_type' value='EXPRESS'>");
                strHiddenField.Append("<input type='hidden' name='out_trade_no' value='" + v_oid + "'>");
                strHiddenField.Append("<input type='hidden' name='partner' value='" + partner + "'>");
                strHiddenField.Append("<input type='hidden' name='payment_type' value='1'>");
                strHiddenField.Append("<input type='hidden' name='price' value='" + v_amount + "'>");
                strHiddenField.Append("<input type='hidden' name='quantity' value='1'>");
                strHiddenField.Append("<input type='hidden' name='seller_email' value='" + v_mid + "'>");
                strHiddenField.Append("<input type='hidden' name='service' value='create_partner_trade_by_buyer'>");
                strHiddenField.Append("<input type='hidden' name='return_url' value='" + v_ShowResultUrl + "'>\n");
                strHiddenField.Append("<input type='hidden' name='subject' value='" + subject + "'>");
                strHiddenField.Append("<input type='hidden' name='sign' value='" + md5string + "'>");
                strHiddenField.Append("<input type='hidden' name='sign_type' value='MD5'>");

                break;
            case 9:    //支付宝双接口
                m_PayOnlineProviderUrl = "https://mapi.alipay.com/gateway.do?_input_charset=utf-8";
                v_urlBuilder.Append("Plus/Pay/AlipayNotify1.aspx?from=" + from + "&paymentplat=" + payPlatformId + "&userid=" + (new TemporaryVar()).UserID);
                v_url = v_urlBuilder.ToString();


                //订单含有虚拟商品的情况
                if (orderId.Substring(1, 2) == "0P")
                {
                    isFabrication = true;   //会员充值，视为虚拟物品
                }
                else
                {
                    isFabrication = false;   //检测订单中的物品是否含有虚拟物品
                }


                if (payOnlineKey.IndexOf("|") > 0)
                {
                    string[] ArrMD5Key = payOnlineKey.Split(new char[] { '|' });
                    payOnlineKey = ArrMD5Key[0];
                    partner = ArrMD5Key[1];
                }

                if (isFabrication)
                {
                    md5Builder.Append("_input_charset=utf-8");
                    md5Builder.Append("&extend_param=isv^1827506kx");
                    md5Builder.Append("&notify_url=" + v_url);
                    md5Builder.Append("&out_trade_no=" + v_oid);
                    md5Builder.Append("&partner=" + partner);
                    md5Builder.Append("&price=" + v_amount);
                    md5Builder.Append("&quantity=1");
                    md5Builder.Append("&return_url=" + v_ShowResultUrl);
                    md5Builder.Append("&seller_email=" + v_mid);
                    md5Builder.Append("&service=create_digital_goods_trade_p");
                    md5Builder.Append("&subject=" + subject);
                    md5Builder.Append("");
                    md5Builder.Append(payOnlineKey);
                    strHiddenField.Append("<input type='hidden' name='service' value='create_digital_goods_trade_p'>");
                }
                else
                {
                    md5Builder.Append("_input_charset=utf-8");
                    md5Builder.Append("&extend_param=isv^1827506kx");
                    md5Builder.Append("&logistics_fee=0");
                    md5Builder.Append("&logistics_payment=SELLER_PAY");
                    md5Builder.Append("&logistics_type=EXPRESS");
                    md5Builder.Append("&notify_url=" + v_url);
                    md5Builder.Append("&out_trade_no=" + v_oid);
                    md5Builder.Append("&partner=" + partner);
                    md5Builder.Append("&payment_type=1");
                    md5Builder.Append("&price=" + v_amount);
                    md5Builder.Append("&quantity=1");
                    md5Builder.Append("&return_url=" + v_ShowResultUrl);
                    md5Builder.Append("&seller_email=" + v_mid);
                    md5Builder.Append("&service=trade_create_by_buyer");
                    md5Builder.Append("&subject=" + subject);
                    md5Builder.Append(payOnlineKey);
                    strHiddenField.Append("<input type='hidden' name='service' value='trade_create_by_buyer'>");
                    strHiddenField.Append("<input type='hidden' name='logistics_type' value='EXPRESS'>");
                    strHiddenField.Append("<input type='hidden' name='logistics_fee' value='0'>");
                    strHiddenField.Append("<input type='hidden' name='logistics_payment' value='SELLER_PAY'>");
                    strHiddenField.Append("<input type='hidden' name='payment_type' value='1'>");
                }
                md5string = AlipayCore.Sign(md5Builder.ToString(), "MD5", "utf-8").ToLower();
                strHiddenField.Append("<input type='hidden' name='extend_param' value='isv^1827506kx'>");
                strHiddenField.Append("<input type='hidden' name='_input_charset' value='utf-8'>");
                strHiddenField.Append("<input type='hidden' name='seller_email' value='" + v_mid + "'>");
                strHiddenField.Append("<input type='hidden' name='subject' value='" + subject + "'>");
                strHiddenField.Append("<input type='hidden' name='out_trade_no' value='" + v_oid + "'>");
                strHiddenField.Append("<input type='hidden' name='price' value='" + v_amount + "'>");
                strHiddenField.Append("<input type='hidden' name='partner' value='" + partner + "'>");
                strHiddenField.Append("<input type='hidden' name='quantity' value='1'>");
                strHiddenField.Append("<input type='hidden' name='notify_url' value='" + v_url + "'>");
                strHiddenField.Append("<input type='hidden' name='sign' value='" + md5string + "'>");
                strHiddenField.Append("<input type='hidden' name='sign_type' value='MD5'>");
                strHiddenField.Append("<input type='hidden' name='return_url' value='" + v_ShowResultUrl + "'>\n");
                break;
            case 7:      //快钱支付
                m_PayOnlineProviderUrl = "https://www.99bill.com/gateway/recvMerchantInfoAction.htm";
                //生成返回URL
                v_urlBuilder.Append("Plus/Pay/PayResult99bill.aspx");
                v_url = v_urlBuilder.ToString();

                string merchantAcctId = v_mid;   //网关账户号
                string key = payOnlineKey; //网关密钥
                string inputCharset = "3"; //1代表UTF-8; 2代表GBK; 3代表gb2312
                string pageUrl = v_url; //接受支付结果的页面地址
                string bgUrl = ""; //服务器接受支付结果的后台地址
                string version = "v2.0"; //网关版本.固定值
                string language = "1"; //1代表中文；2代表英文
                string signType = "1"; //1代表MD5签名
                string payerName = ""; //支付人姓名
                string payerContactType = ""; //支付人联系方式类型 1代表Email；2代表手机号
                string payerContact = ""; //支付人联系方式,只能选择Email或手机号
                string orderAmount = Convert.ToString(decimal.Ceiling(Convert.ToDecimal(v_amount) * 100)); //订单金额,以分为单位
                string orderTime = v_ymd + v_hms; //订单提交时间,14位数字
                string productName = ""; //商品名称
                string productNum = ""; //商品数量
                string productId = ""; //商品代码
                string productDesc = ""; //商品描述
                string ext1 = ""; //扩展字段1,在支付结束后原样返回给商户
                string ext2 = ""; //扩展字段2
                string payType = "00"; //支付方式,00：组合支付,显示快钱支持的各种支付方式,11：电话银行支付,12：快钱账户支付,13：线下支付,14：B2B支付
                string bankId = ""; //银行代码,实现直接跳转到银行页面去支付,具体代码参见 接口文档银行代码列表,只在payType=10时才需设置参数
                string redoFlag = "1"; //同一订单禁止重复提交标志:1代表同一订单号只允许提交1次,0表示同一订单号在没有支付成功的前提下可重复提交多次
                string pid = ""; //快钱的合作伙伴的账户号

                string signMsgVal = "";
                signMsgVal = AppendParam(signMsgVal, "inputCharset", inputCharset);
                signMsgVal = AppendParam(signMsgVal, "pageUrl", pageUrl);
                signMsgVal = AppendParam(signMsgVal, "bgUrl", bgUrl);
                signMsgVal = AppendParam(signMsgVal, "version", version);
                signMsgVal = AppendParam(signMsgVal, "language", language);
                signMsgVal = AppendParam(signMsgVal, "signType", signType);
                signMsgVal = AppendParam(signMsgVal, "merchantAcctId", merchantAcctId);
                signMsgVal = AppendParam(signMsgVal, "payerName", payerName);
                signMsgVal = AppendParam(signMsgVal, "payerContactType", payerContactType);
                signMsgVal = AppendParam(signMsgVal, "payerContact", payerContact);
                signMsgVal = AppendParam(signMsgVal, "orderId", v_oid);  //商户订单号
                signMsgVal = AppendParam(signMsgVal, "orderAmount", orderAmount);
                signMsgVal = AppendParam(signMsgVal, "orderTime", orderTime);
                signMsgVal = AppendParam(signMsgVal, "productName", productName);
                signMsgVal = AppendParam(signMsgVal, "productNum", productNum);
                signMsgVal = AppendParam(signMsgVal, "productId", productId);
                signMsgVal = AppendParam(signMsgVal, "productDesc", productDesc);
                signMsgVal = AppendParam(signMsgVal, "ext1", ext1);
                signMsgVal = AppendParam(signMsgVal, "ext2", ext2);
                signMsgVal = AppendParam(signMsgVal, "payType", payType);
                signMsgVal = AppendParam(signMsgVal, "bankId", bankId);
                signMsgVal = AppendParam(signMsgVal, "redoFlag", redoFlag);
                signMsgVal = AppendParam(signMsgVal, "pid", pid);
                signMsgVal = AppendParam(signMsgVal, "key", key);

                md5string = Utils.MD5(signMsgVal).ToUpper();

                strHiddenField.Append("<input type='hidden' name='inputCharset' value='" + inputCharset + "'>\n");
                strHiddenField.Append("<input type='hidden' name='bgUrl' value='" + bgUrl + "'>\n");
                strHiddenField.Append("<input type='hidden' name='pageUrl' value='" + pageUrl + "'>\n");
                strHiddenField.Append("<input type='hidden' name='version' value='" + version + "'>\n");
                strHiddenField.Append("<input type='hidden' name='language' value='" + language + "'>\n");
                strHiddenField.Append("<input type='hidden' name='signType' value='" + signType + "'>\n");
                strHiddenField.Append("<input type='hidden' name='signMsg' value='" + md5string + "'>\n");
                strHiddenField.Append("<input type='hidden' name='merchantAcctId' value='" + merchantAcctId + "'>\n");
                strHiddenField.Append("<input type='hidden' name='payerName' value='" + payerName + "'>\n");
                strHiddenField.Append("<input type='hidden' name='payerContactType' value='" + payerContactType + "'>\n");
                strHiddenField.Append("<input type='hidden' name='payerContact' value='" + payerContact + "'>\n");
                strHiddenField.Append("<input type='hidden' name='orderId' value='" + v_oid + "'>\n");
                strHiddenField.Append("<input type='hidden' name='orderAmount' value='" + orderAmount + "'>\n");
                strHiddenField.Append("<input type='hidden' name='orderTime' value='" + orderTime + "'>\n");
                strHiddenField.Append("<input type='hidden' name='productName' value='" + productName + "'>\n");
                strHiddenField.Append("<input type='hidden' name='productNum' value='" + productNum + "'>\n");
                strHiddenField.Append("<input type='hidden' name='productId' value='" + productId + "'>\n");
                strHiddenField.Append("<input type='hidden' name='productDesc' value='" + productDesc + "'>\n");
                strHiddenField.Append("<input type='hidden' name='ext1' value='" + ext1 + "'>\n");
                strHiddenField.Append("<input type='hidden' name='ext2' value='" + ext2 + "'>\n");
                strHiddenField.Append("<input type='hidden' name='payType' value='" + payType + "'>\n");
                strHiddenField.Append("<input type='hidden' name='bankId' value='" + bankId + "'>\n");
                strHiddenField.Append("<input type='hidden' name='redoFlag' value='" + redoFlag + "'>\n");
                strHiddenField.Append("<input type='hidden' name='pid' value='" + pid + "'>\n");
                break;
            case 110:  //快钱神州行
                m_PayOnlineProviderUrl = "https://www.99bill.com/szxgateway/recvMerchantInfoAction.htm";
                //生成返回URL
                v_urlBuilder.Append("Plus/Pay/PayResult99billSzx.aspx");
                v_url = v_urlBuilder.ToString();

                merchantAcctId = v_mid; //神州行网关账户号
                key = payOnlineKey; //设置人民币网关密钥
                inputCharset = "3"; //1代表UTF-8; 2代表GBK; 3代表gb2312
                bgUrl = ""; //服务器接受支付结果的后台地址
                pageUrl = v_url; //接受支付结果的页面地址
                version = "v2.0"; //网关版本.固定值
                language = "1"; //1代表中文；2代表英文
                signType = "1"; //签名类型.固定值
                payerName = ""; //支付人姓名
                payerContactType = ""; //支付人联系方式类型,1代表Email；2代表手机号
                payerContact = ""; //支付人联系方式,只能选择Email或手机号
                orderAmount = Convert.ToString(decimal.Ceiling(Convert.ToDecimal(v_amount) * 100)); //订单金额,以分为单位，必须是整型数字
                orderTime = v_ymd + v_hms; //订单提交时间
                productName = ""; //商品名称
                productNum = ""; //商品数量
                productId = ""; //商品代码
                productDesc = ""; //商品描述
                ext1 = ""; //扩展字段1
                ext2 = ""; //扩展字段2
                payType = "00"; //只能选择00,代表支持神州行卡和快钱帐户支付
                string cardNumber = ""; //神州行卡序号,仅在商户定制了神州行卡密直连功能时填写
                string cardPwd = ""; //神州行卡密码,仅在商户定制了神州行卡密直连功能时填写
                                     //全额支付标志       ////0代表卡面额小于订单金额时返回支付结果为失败；1代表卡面额小于订单金额是返回支付结果为成功，同时订单金额和实际支付金额都为神州行卡的面额.如果商户定制神州行卡密直连时，本参数固定值为1
                string fullAmountFlag = "0"; //0代表卡面额小于订单金额时返回支付结果为失败

                //请务必按照如下顺序和规则组成加密串！
                signMsgVal = "";
                signMsgVal = AppendParam(signMsgVal, "inputCharset", inputCharset);
                signMsgVal = AppendParam(signMsgVal, "bgUrl", bgUrl);
                signMsgVal = AppendParam(signMsgVal, "pageUrl", pageUrl);
                signMsgVal = AppendParam(signMsgVal, "version", version);
                signMsgVal = AppendParam(signMsgVal, "language", language);
                signMsgVal = AppendParam(signMsgVal, "signType", signType);
                signMsgVal = AppendParam(signMsgVal, "merchantAcctId", merchantAcctId);
                signMsgVal = AppendParam(signMsgVal, "payerName", payerName);
                signMsgVal = AppendParam(signMsgVal, "payerContactType", payerContactType);
                signMsgVal = AppendParam(signMsgVal, "payerContact", payerContact);
                signMsgVal = AppendParam(signMsgVal, "orderId", v_oid);
                signMsgVal = AppendParam(signMsgVal, "orderAmount", orderAmount);
                signMsgVal = AppendParam(signMsgVal, "payType", payType);
                signMsgVal = AppendParam(signMsgVal, "cardNumber", cardNumber);
                signMsgVal = AppendParam(signMsgVal, "cardPwd", cardPwd);
                signMsgVal = AppendParam(signMsgVal, "fullAmountFlag", fullAmountFlag);
                signMsgVal = AppendParam(signMsgVal, "orderTime", orderTime);
                signMsgVal = AppendParam(signMsgVal, "productName", productName);
                signMsgVal = AppendParam(signMsgVal, "productNum", productNum);
                signMsgVal = AppendParam(signMsgVal, "productId", productId);
                signMsgVal = AppendParam(signMsgVal, "productDesc", productDesc);
                signMsgVal = AppendParam(signMsgVal, "ext1", ext1);
                signMsgVal = AppendParam(signMsgVal, "ext2", ext2);
                signMsgVal = AppendParam(signMsgVal, "key", key);

                md5string = Utils.MD5(signMsgVal).ToUpper();

                strHiddenField.Append("<input type='hidden' name='inputCharset' value='" + inputCharset + "'>\n");
                strHiddenField.Append("<input type='hidden' name='bgUrl' value='" + bgUrl + "'>\n");
                strHiddenField.Append("<input type='hidden' name='pageUrl' value='" + pageUrl + "'>\n");
                strHiddenField.Append("<input type='hidden' name='version' value='" + version + "'>\n");
                strHiddenField.Append("<input type='hidden' name='language' value='" + language + "'>\n");
                strHiddenField.Append("<input type='hidden' name='signType' value='" + signType + "'>\n");
                strHiddenField.Append("<input type='hidden' name='merchantAcctId' value='" + merchantAcctId + "'>\n");
                strHiddenField.Append("<input type='hidden' name='payerName' value='" + payerName + "'>\n");
                strHiddenField.Append("<input type='hidden' name='payerContactType' value='" + payerContactType + "'>\n");
                strHiddenField.Append("<input type='hidden' name='payerContact' value='" + payerContact + "'>\n");
                strHiddenField.Append("<input type='hidden' name='orderId' value='" + v_oid + "'>\n");
                strHiddenField.Append("<input type='hidden' name='orderAmount' value='" + orderAmount + "'>\n");
                strHiddenField.Append("<input type='hidden' name='orderTime' value='" + orderTime + "'>\n");
                strHiddenField.Append("<input type='hidden' name='productName' value='" + productName + "'>\n");
                strHiddenField.Append("<input type='hidden' name='productNum' value='" + productNum + "'>\n");
                strHiddenField.Append("<input type='hidden' name='productId' value='" + productId + "'>\n");
                strHiddenField.Append("<input type='hidden' name='productDesc' value='" + productDesc + "'>\n");
                strHiddenField.Append("<input type='hidden' name='ext1' value='" + ext1 + "'>\n");
                strHiddenField.Append("<input type='hidden' name='ext2' value='" + ext2 + "'>\n");
                strHiddenField.Append("<input type='hidden' name='payType' value='" + payType + "'>\n");
                strHiddenField.Append("<input type='hidden' name='fullAmountFlag' value='" + fullAmountFlag + "'>\n");
                strHiddenField.Append("<input type='hidden' name='cardNumber' value='" + cardNumber + "'>\n");
                strHiddenField.Append("<input type='hidden' name='cardPwd' value='" + cardPwd + "'>\n");
                strHiddenField.Append("<input type='hidden' name='signMsg' value='" + md5string + "'>\n");
                break;
            case 10: //财付通
            case 11: //中介
            case 13: //双接口

                subject = Utils.CutString(subject, 0, 32); //财付通限制长度

                v_urlBuilder.Append("Plus/Pay/TenpayNotify.aspx?from=" + from + "&paymentplat=" + payPlatformId + "&userid=" + (new TemporaryVar()).UserID);
                v_url = v_urlBuilder.ToString();

                //创建RequestHandler实例
                RequestHandler reqHandler = new RequestHandler(Context);
                //初始化
                reqHandler.init();
                //设置密钥
                reqHandler.setKey(payOnlineKey);
                reqHandler.setGateUrl("https://gw.tenpay.com/gateway/pay.htm");


                //-----------------------------
                //设置支付参数
                //-----------------------------
                reqHandler.setParameter("partner", v_mid);              //商户号
                reqHandler.setParameter("out_trade_no", orderId);       //商家订单号
                reqHandler.setParameter("total_fee", (Convert.ToDouble(v_amount) * 100).ToString());                    //商品金额,以分为单位
                reqHandler.setParameter("return_url", v_ShowResultUrl);         //交易完成后跳转的URL
                reqHandler.setParameter("notify_url", v_url);           //接收财付通通知的URL
                reqHandler.setParameter("body", subject);                       //商品描述
                reqHandler.setParameter("bank_type", "DEFAULT");            //银行类型(中介担保时此参数无效)
                reqHandler.setParameter("spbill_create_ip", Page.Request.UserHostAddress);   //用户的公网ip，不是商户服务器IP
                reqHandler.setParameter("fee_type", "1");                    //币种，1人民币
                reqHandler.setParameter("subject", subject);              //商品名称(中介交易时必填)

                //系统可选参数
                reqHandler.setParameter("sign_type", "MD5");
                reqHandler.setParameter("service_version", "1.0");
                reqHandler.setParameter("input_charset", "UTF-8");
                reqHandler.setParameter("sign_key_index", "1");

                //业务可选参数

                reqHandler.setParameter("attach", "");                      //附加数据，原样返回
                reqHandler.setParameter("product_fee", "0");                 //商品费用，必须保证transport_fee + product_fee=total_fee
                reqHandler.setParameter("transport_fee", "0");               //物流费用，必须保证transport_fee + product_fee=total_fee
                reqHandler.setParameter("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));            //订单生成时间，格式为yyyymmddhhmmss
                reqHandler.setParameter("time_expire", "");                 //订单失效时间，格式为yyyymmddhhmmss
                reqHandler.setParameter("buyer_id", "");                    //买方财付通账号
                reqHandler.setParameter("goods_tag", "");                   //商品标记
                reqHandler.setParameter("trade_mode", payPlatformId == 11 ? "2" : ((payPlatformId == 13) ? "3" : "1"));                 //交易模式，1即时到账(默认)，2中介担保，3后台选择（买家进支付中心列表选择）
                reqHandler.setParameter("transport_desc", "");              //物流说明
                reqHandler.setParameter("trans_type", "1");                  //交易类型，1实物交易，2虚拟交易
                reqHandler.setParameter("agentid", "");                     //平台ID
                reqHandler.setParameter("agent_type", "");                  //代理模式，0无代理(默认)，1表示卡易售模式，2表示网店模式
                reqHandler.setParameter("seller_id", "");                   //卖家商户号，为空则等同于partner

                string requestUrl = reqHandler.getRequestURL();
                m_PayOnlineProviderUrl = reqHandler.getGateUrl();
                Hashtable ht = reqHandler.getAllParameters();
                foreach (DictionaryEntry de in ht)
                {
                    strHiddenField.Append("<input type=\"hidden\" name=\"" + de.Key + "\" value=\"" + de.Value + "\" >\n");

                }


                break;
            case 14:   //银联在线支付

                v_urlBuilder.Append("Plus/Pay/PayResultUnionPay.aspx");
                v_url = v_urlBuilder.ToString();


                //以下代码只是为了方便商户测试而提供的样例代码，商户可以根据自己需要，按照技术文档编写。该代码仅供参考
                // **************演示前台交易的请求***********************
                Dictionary<string, string> param = new Dictionary<string, string>();
                // 随机构造一个订单号（演示用）
                Random rnd = new Random();
                //填写参数
                param["version"] = "5.1.0";//版本号
                param["encoding"] = "UTF-8";//编码方式
                param["txnType"] = "01";//交易类型
                param["txnSubType"] = "01";//交易子类
                param["bizType"] = "000201";//业务类型
                param["frontUrl"] = v_ShowResultUrl;    //前台通知地址      
                param["backUrl"] = v_url;  //后台通知地址，改自己的外网地址
                param["signMethod"] = "01";//签名方法
                param["channelType"] = "08";//渠道类型，07-PC，08-手机
                param["accessType"] = "0";//接入类型
                param["merId"] = AccountID.Trim();//商户号，请改成自己的商户号
                param["orderId"] = v_oid.Trim();//商户订单号，可任意修改
                param["txnTime"] = DateTime.Now.ToString("yyyyMMddHHmmss");//订单发送时间
                param["txnAmt"] = (Utils.StrToDecimal(v_amount) * 100).ToString("f0");//交易金额，单位分
                param["currencyCode"] = "156";//交易币种
                param["reqReserved"] = "txnAmt=" + (Utils.StrToDecimal(v_amount)).ToString("f0") + "&orderId=" + orderId;//请求方保留域，透传字段，查询、通知、对账文件中均会原样出现
                AcpService.Sign(param, Encoding.UTF8);
                // 将SDKUtil产生的Html文档写入页面，从而引导用户浏览器重定向   
                string html = AcpService.CreateAutoFormHtml(SDKConfig.FrontTransUrl, param, Encoding.UTF8);
                Response.ContentEncoding = Encoding.UTF8; // 指定输出编码
                Response.Write(html);
                KSCMS.Die("正在转向支付页面,请稍候...");



                break;
            case 15:  //微信支付

                if (new TemporaryVar().FromPage == "3g" || Utils.IsMobileDevice())
                {
                    Response.Redirect("wx/send.aspx?orderid=" + v_oid + "&flag=" + from + "&uid=" + new TemporaryVar().UserID);
                }
                else
                {
                    Context.Items["pay_orderid"] = orderId;
                    this.PlaceHolder1.Controls.Add(base.LoadControl("~/Config/Control/Member/Basic/WXPayControl.ascx"));
                    return;

                }
                break;
            default:
                JS.Alert(Utils.GetLanguageNode("//language/node[@name='user']/payonline/platiderr"));
                break;
        }

        string newForm = string.Empty;
        //string newForm = "<form method=\"post\" action='" + m_PayOnlineProviderUrl + "' id=\"form2\" target=\"_blank\">";
        string redirectcft;

        redirectcft = "<!--<input type=\"submit\" id=\"submits\" onclick=\"$('#__VIEWSTATE').remove();this.form.target='_blank';this.form.action='" + m_PayOnlineProviderUrl + "'\" class=\"button\" value=\"确认支付\">";
        string endFrom = redirectcft + "  <input type=\"button\" class=\"button\" id=\"Cancel\" value=\"取消支付\" onclick=\"window.location.href='index.aspx'\" />-->";



        // endFrom += "</form>";
        m_HiddenValue = newForm + strHiddenField.ToString() + endFrom;

        //给页面赋值



        if (payPlatformId == 8 && Utils.IsAppDevice())
        {

            m_HiddenValue = @"<!DOCTYPE html>
            <html>
            <head> 
            <title>在线充值</title>
            <meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"">
            <meta http-equiv=""Cache-control"" content=""max-age=1700"">
            <meta name=""viewport"" content=""user-scalable=no, width=device-width"">
            <meta name=""MobileOptimized"" content=""320"">
             <script src='http://static.ydbimg.com/Scripts/jquery-1.9.1.js' type='text/javascript'></sc" + @"ript>
            <script src='http://static.ydbimg.com/API/YdbOnline.js' type='text/javascript'></sc" + @"ript>
          <body>
               <div style=""margin-top:100px;font-size:26px"">正在转向支付页面,请稍候...</div>
             ";
            m_HiddenValue += @"<script>
                    //  YDB.SetAlipayInfo(ProductName, Desicript, Price, OuttradeNo);
                    //参数说明：ProductName 名称, Desicript 描述, Price 支付金额, OuttradeNo 订单编号
                    $(function(){
                    var YDB = new YDBOBJ();
                 ";

            m_HiddenValue += string.Format(@"YDB.SetAlipayInfo('{0}', '{1}', '{2}','{3}');", subject, subject, vmoney, v_oid);
            m_HiddenValue += @"}); </s" + @"cript>";

            KSCMS.Die(m_HiddenValue);

        }
        else
        {
            m_HiddenValue = "正在转向支付页面,请稍候...<script src='/ks_inc/jquery.js'></scri" + @"pt><form name='myform' id='myform' action='" + m_PayOnlineProviderUrl + "' method='get'>" + m_HiddenValue + "</form>";
            m_HiddenValue += @"<script>$(document).ready(function(){
                   $('#myform').submit();
                 });
             </scr" + @"ipt>";
            KSCMS.Die(m_HiddenValue);
        }


        LabHiddenField.Text = m_HiddenValue;
    }

    /// <summary>
    /// 在线充值预付款，记录起来
    /// </summary>
    /// <param name="orderid"></param>
    /// <param name="paymoney"></param>
    /// <param name="realmoney"></param>
    /// <param name="remark"></param>
    /// <param name="platId"></param>
    public static void addToRechargeRecords(string orderid, double paymoney, double realmoney, string remark, int platId, int OrderType = 0)
    {
        if (paymoney > 0)
        {
            Hashtable ht = new Hashtable();
            ht.Add("username", (new TemporaryVar()).UserName);
            ht.Add("orderid", orderid);
            ht.Add("userid", (new TemporaryVar()).UserID);
            ht.Add("paymoney", paymoney);
            ht.Add("realmoney", realmoney);
            ht.Add("totalmoney", Utils.StrToFloat(KSCMS.S("totalmoney")));
            ht.Add("adddate", DateTime.Now);
            ht.Add("status", 0);
            ht.Add("remark", remark);
            ht.Add("platid", platId);
            ht.Add("packId", Utils.StrToInt(KSCMS.S("packId"), 0));

            ht.Add("OrderType", OrderType);  //1课程支付,
            ht.Add("platName", PlatForm.GetPlatFormById(platId).PlatName);
            if (!DataFactoryUser.Exists("KS_RechargeRecords", "orderID='" + Utils.ChkSQL(orderid) + "'"))
            {
                CommonDataUser.Insert("KS_RechargeRecords", ht);
            }
            else
            {
                CommonDataUser.Update("KS_RechargeRecords", ht, "where orderID='" + Utils.ChkSQL(orderid) + "'");
            }
        }
    }


    /// <summary>
    /// 添加参数,惹参数值不为空串,则添加。反之,不添加。
    /// </summary>
    private StringBuilder AddParameter(StringBuilder buf, String parameterName, String parameterValue)
    {
        #region 添加参数,惹参数值不为空串,则添加。反之,不添加。
        if (null == parameterValue || "".Equals(parameterValue))
        {
            return buf;
        }

        if ("".Equals(buf.ToString()))
        {
            buf.Append(parameterName);
            buf.Append("=");
            buf.Append(parameterValue);
        }
        else
        {
            buf.Append("&");
            buf.Append(parameterName);
            buf.Append("=");
            buf.Append(parameterValue);
        }
        return buf;
        #endregion
    }
    //将变量值不为空的参数组成字符串(快钱)
    public static string AppendParam(string returnStr, string paramId, string paramValue)
    {
        string str = string.Empty;
        if (returnStr != "")
        {
            if (paramValue != "")
            {
                str = str + "&" + paramId + "=" + paramValue;

            }
        }
        else
        {
            if (paramValue != "")
            {
                str = paramId + "=" + paramValue;
            }
        }
        return str;

    }
</script>
