Beispiel #1
0
        private const string key          = "a2990e2986ef3b21a5400414216c089a"; //密钥

        public static string PayDirect(string sOrderID, string sAccount, decimal dPrice, string PayType, HttpContext Context, string return_url)
        {
            string sPayUrl   = "https://www.tenpay.com/cgi-bin/v1.0/pay_gate.cgi";
            string date      = DateTime.Now.ToString("yyyyMMdd");
            string strReq    = "" + DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
            string sp_billno = sOrderID.Substring(0, 32);
            //财付通订单号,10位商户号+8位日期+10位序列号,需保证全局唯一
            string transaction_id = bargainor_id + date + strReq;
            //创建PayRequestHandler实例
            PayRequestHandler reqHandler = new PayRequestHandler(Context);

            reqHandler.setKey(key);
            reqHandler.setGateUrl(sPayUrl);
            string  attach = string.Format("{0}|{1}|{2}", sOrderID.Substring(32), sAccount, PayType);
            decimal price  = Convert.ToInt32(dPrice * 100);

            //初始化
            reqHandler.init();
            string desc = string.Empty;

            if (PayType == "wlb")
            {
                desc = string.Format("到武林{0}元武林币充值", dPrice.ToString());
            }
            else
            {
                string sGameAbbre = PayType.Split('|')[0];
                string sGameName  = PayAll.GetGameName(sGameAbbre);
                desc = string.Format("到武林{0}元{1}游戏直冲", dPrice.ToString(), sGameName);
            }
            //-----------------------------
            //设置支付参数
            //-----------------------------
            reqHandler.setParameter("bargainor_id", bargainor_id);     //商户号
            reqHandler.setParameter("sp_billno", sp_billno);           //商家订单号
            reqHandler.setParameter("transaction_id", transaction_id); //财付通交易单号
            reqHandler.setParameter("return_url", return_url);         //支付通知url
            reqHandler.setParameter("desc", desc);                     //商品名称
            reqHandler.setParameter("total_fee", price.ToString());    //商品金额,以分为单位
            reqHandler.setParameter("attach", attach);                 //商家数据包,原样返回
            reqHandler.setParameter("cs", "utf-8");
            //用户ip,测试环境时不要加这个ip参数,正式环境再加此参数
            string UserIP = ProvideCommon.GetRealIP();

            reqHandler.setParameter("spbill_create_ip", UserIP);
            //post实现方式
            reqHandler.getRequestURL();
            StringBuilder sbText = new StringBuilder();

            sbText.AppendFormat("<form id='tenpaysubmit' name='tenpaysubmit' method=\"post\" action=\"{0}\">", reqHandler.getGateUrl());
            Hashtable ht = reqHandler.getAllParameters();

            foreach (DictionaryEntry de in ht)
            {
                sbText.AppendFormat("<input type=\"hidden\" name=\"{0}\" value=\"{1}\" >", de.Key, de.Value);
            }
            sbText.Append("<input type='submit' value='submit' style='display:none;'></form>");
            sbText.Append("<script>document.forms['tenpaysubmit'].submit();</script>");
            FirstOfPayPointBLL.Add(sOrderID, UserIP, sbText.ToString());
            return(sbText.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// 支付接口(暂时不用)
        /// </summary>
        /// <param name="tenPayParam">参数 Model</param>
        /// <returns></returns>
        public string payRequest(TenPayParam tenPayParam)
        {
            string result = "";

            try
            {
                string desc      = tenPayParam.Desc;            //商品名称
                string ip        = tenPayParam.UserHostAddress; //用户的公网ip
                string sp_billno = tenPayParam.Orderid;         //商户订单号
                string total_fee = tenPayParam.Total_Tee;       //商品金额,以分为单

                //当前时间 yyyyMMdd
                string date = DateTime.Now.ToString("yyyyMMdd");
                //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
                string strReq = "" + DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
                //商户订单号,不超过32位,财付通只做记录,不保证唯一性
                //string sp_billno = strReq;
                // 财付通交易单号,规则为:10位商户号+8位时间(YYYYmmdd)+10位流水号 ,商户根据自己情况调整,只要保证唯一及符合规则就行
                string transaction_id = bargainor_id + date + strReq;
                //创建PayRequestHandler实例
                PayRequestHandler reqHandler = new PayRequestHandler(HttpContext.Current);
                //初始化
                reqHandler.init();
                //设置密钥
                reqHandler.setKey(key);
                //-----------------------------
                //设置支付参数
                //-----------------------------
                reqHandler.setParameter("bargainor_id", bargainor_id);     //商户号
                reqHandler.setParameter("sp_billno", sp_billno);           //商家订单号
                reqHandler.setParameter("transaction_id", transaction_id); //财付通交易单号
                reqHandler.setParameter("return_url", _ReturnUrl);         //支付通知url
                reqHandler.setParameter("desc", desc);                     //商品名称
                reqHandler.setParameter("total_fee", total_fee);           //商品金额,以分为单
                //用户的公网ip,测试时填写127.0.0.1,只能支持10分以下交易
                reqHandler.setParameter("spbill_create_ip", ip);
                //获取请求带参数的url
                string requestUrl = reqHandler.getRequestURL();

                #region GET  提交方式

                //result = "<a target=\"_blank\" href=\"" + requestUrl + "\">" + "财付通支付" + "</a>";

                #endregion

                #region POST 提交方式
                StringBuilder sb = new StringBuilder();
                sb.Append("<form name='alipaysubmit' method='post' action='" + requestUrl + "'>");
                Hashtable ht = reqHandler.getAllParameters();
                foreach (DictionaryEntry de in ht)
                {
                    sb.Append("<input type='hidden' name='" + de.Key + "' value='" + de.Value + "' >");
                }
                sb.Append("</form>");
                sb.Append("<script>");
                sb.Append("document.alipaysubmit.submit()");
                sb.Append("</script>");
                result = sb.ToString();

                #endregion
            }
            catch (Exception ex)
            {
            }
            return(result);
        }