Exemplo n.º 1
0
        /// <summary>
        /// 支付并分账接口
        /// </summary>
        /// <param name="tenPayParam">参数 Model</param>
        /// <returns></returns>
        public string SplitPayRequest(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;       //商品金额,以分为单
                string bus_Args     = tenPayParam.Bus_Args;        //分账明细
                string bus_desc     = tenPayParam.Bus_Desc;        //行业描述信息
                string purchaser_id = tenPayParam.Purchaser_id;
                string bank_type    = tenPayParam.BankType;
                string attach       = tenPayParam.Attach;
                //当前时间 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;
                //创建BaseSplitRequestHandler实例
                //BaseSplitRequestHandler reqHandler = new BaseSplitRequestHandler(Context);
                BaseSplitRequestHandler reqHandler = new BaseSplitRequestHandler(HttpContext.Current);
                //初始化
                reqHandler.init();
                //设置密钥
                reqHandler.setKey(key);
                reqHandler.setGateUrl("https://www.tenpay.com/cgi-bin/v4.0/pay_set.cgi");
                //-----------------------------
                //设置支付参数
                //-----------------------------
                reqHandler.setParameter("bank_type", bank_type);
                reqHandler.setParameter("cmdno", "1");// 财付通支付支付接口填  1
                reqHandler.setParameter("date", DateTime.Now.ToString("yyyyMMdd"));
                reqHandler.setParameter("fee_type", "1");
                reqHandler.setParameter("version", "4");                   //版本号必须填4
                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);
                //业务类型
                reqHandler.setParameter("bus_type", "97");//暂固定为97
                reqHandler.setParameter("purchaser_id", purchaser_id);
                reqHandler.setParameter("attach", attach);

                /**
                 * 业务参数
                 * 帐号^分帐金额^角色
                 * 角色说明:	1:供应商 2:平台服务方 4:独立分润方
                 * 帐号1^分帐金额1^角色1|帐号2^分帐金额2^角色2|...
                 */
                reqHandler.setParameter("bus_args", bus_Args);
                //行业描述信息
                //reqHandler.setParameter("bus_desc", "12345^深圳-上海^1^fady^庄^13800138000");
                reqHandler.setParameter("bus_desc", bus_desc);//业务描述,特定格式的字符串,格式为:PNR^航程^机票张数^机票销售商在机票平台的id^联系人姓名^联系电话

                //用户的公网ip,测试时填写127.0.0.1,只能支持10分以下交易
                reqHandler.setParameter("spbill_create_ip", ip);
                //获取请求带参数的url
                string requestUrl = reqHandler.getRequestURL();

                #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

                //获取debug信息,建议把请求和debug信息写入日志,方便定位问题
                //string debuginfo = reqHandler.getDebugInfo();
                //Response.Write("<br/>requestUrl:" + requestUrl + "<br/>");
                //Response.Write("<br/>debuginfo:" + debuginfo + "<br/>");
            }
            catch (Exception ex)
            {
            }
            return(result);
        }