Esempio n. 1
0
        public string RequestPay(string ordernum, string return_url, double?PayMoney, string ProductName, string Remark)
        {
            //创建PayRequestHandler实例
            PayRequestHandler reqHandler = new PayRequestHandler(context);

            Model.SitePayAPI m_entity = Model.SitePayAPI.GetModel(t => t.ApiType == "财付通");
            //商户号
            string bargainor_id = m_entity.AppIdentity;

            //设置密钥
            reqHandler.setKey(m_entity.AppKey);

            //初始化
            reqHandler.init();

            //当前时间 yyyyMMdd
            string date = DateTime.Now.ToString("yyyyMMdd");

            //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
            string strReq = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);


            //财付通订单号,10位商户号+8位日期+10位序列号,需保证全局唯一
            string transaction_id = bargainor_id + date + strReq;


            //-----------------------------
            //设置支付参数
            //-----------------------------
            reqHandler.setParameter("bargainor_id", bargainor_id);                    //商户号
            reqHandler.setParameter("sp_billno", ordernum);                           //商家订单号
            reqHandler.setParameter("transaction_id", transaction_id);                //财付通交易单号
            reqHandler.setParameter("return_url", return_url);                        //支付通知url
            reqHandler.setParameter("desc", ProductName);                             //商品名称
            reqHandler.setParameter("attach", Remark == null?"":Remark);              //会员ID
            reqHandler.setParameter("total_fee", ((int)(PayMoney * 100)).ToString()); //商品金额,以分为单位


            //用户ip,测试环境时不要加这个ip参数,正式环境再加此参数
            reqHandler.setParameter("spbill_create_ip", DealMvc.Common.Globals.GetUserIP());

            //获取请求带参数的url
            string requestUrl = reqHandler.getRequestURL();

            return(requestUrl);
            //FinalMessage("正在进入财付通网站...", requestUrl, 0, 4);
        }
Esempio n. 2
0
        /// <summary>
        /// 财付通生成URL
        /// </summary>
        /// <param name="orderNo"></param>
        /// <param name="subject_in"></param>
        /// <param name="price_in"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public string GetPayUrlByCFT(string orderNo, string subject_in, decimal price_in, HttpContext context)
        {
            string url = "";
            //商户号
            string bargainor_id = TenpayParameters.Bargainor_ID;
            //密钥
            string key1 = TenpayParameters.Key;

            //当前时间 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(context);

            //初始化
            reqHandler.init();
            //设置密钥
            reqHandler.setKey(key1);
            //-----------------------------
            //设置支付参数
            //-----------------------------
            reqHandler.setParameter("bargainor_id", bargainor_id);                                                        //商户号
            reqHandler.setParameter("sp_billno", orderNo);                                                                //商家订单号
            reqHandler.setParameter("transaction_id", transaction_id);                                                    //财付通交易单号
            reqHandler.setParameter("return_url", TenpayParameters.DomainPath + "/TicketsCenter/tenpay/Return_url.aspx"); //支付通知url
            reqHandler.setParameter("desc", subject_in);                                                                  //商品名称
            reqHandler.setParameter("total_fee", price_in.ToString());                                                    //商品金额,以分为单
            reqHandler.setParameter("cs", TenpayParameters.Input_Charset);
            //用户的公网ip,测试时填写127.0.0.1,只能支持10分以下交易
            reqHandler.setParameter("spbill_create_ip", HttpContext.Current.Request.UserHostAddress);
            //获取请求带参数的url
            url = reqHandler.getRequestURL();

            return(url);
        }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //创建工具对象,读取配置
        TenpayUtil util = new TenpayUtil();

        if (!IsPostBack)
        {
            //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
            string strReq = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);

            //当前时间 yyyyMMdd
            string date = DateTime.Now.ToString("yyyyMMdd");

            //商户订单号,不超过32位,财付通只做记录,不保证唯一性
            string sp_billno = date + strReq;
            lbl_Name.Text = TenpayUtil.bargainor_id;
            order_no.Text = sp_billno;
        }
    }
Esempio n. 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string sp_billno = Request["order_no"];
            //当前时间 yyyyMMdd
            string date = DateTime.Now.ToString("yyyyMMdd");

            if (null == sp_billno)
            {
                //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
                sp_billno = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
            }
            else
            {
                sp_billno = Request["order_no"].ToString();
            }

            sp_billno = TenpayUtil.partner + sp_billno;


            RequestHandler outParams = new RequestHandler(Context);

            outParams.init();
            string productid = sp_billno;
            string timeStamp = TenpayUtil.getTimestamp();
            string nonceStr  = TenpayUtil.getNoncestr();

            RequestHandler Params = new RequestHandler(Context);

            Params.setParameter("appid", TenpayUtil.appid);
            Params.setParameter("appkey", TenpayUtil.appkey);
            Params.setParameter("noncestr", nonceStr);
            Params.setParameter("timestamp", timeStamp);
            Params.setParameter("productid", productid);
            string sign = Params.createSHA1Sign();

            Params.setParameter("sign", sign);


            parm = "weixin://wxpay/bizpayurl?sign=" + sign + "&appid=" + TenpayUtil.appid + "&productid=" + productid + "&timeStamp=" + timeStamp + "&nonceStr=" + nonceStr;
            parm = QRfromGoogle(parm);
        }
Esempio n. 5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string sp_billno     = Request["order_no"];
        string product_name  = Request["product_name"];
        string order_price   = Request["order_price"];;
        string remarkexplain = Request["remarkexplain"];
        double money         = 0;

        if (null == Request["order_price"])
        {
            Response.End();
            return;
        }
        try
        {
            money = Convert.ToDouble(order_price);
        }
        catch
        {
            //Response.Write("支付金额格式错误!");
            //Response.End();
            //return;
        }
        if (null == sp_billno)
        {
            //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
            sp_billno = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
        }
        else
        {
            sp_billno = Request["order_no"].ToString();
        }

        //创建RequestHandler实例
        RequestHandler reqHandler = new RequestHandler(Context);

        //初始化
        reqHandler.init();
        //设置密钥
        reqHandler.setKey(TenpayUtil.tenpay_key);
        reqHandler.setGateUrl("https://gw.tenpay.com/gateway/pay.htm");



        //-----------------------------
        //设置支付参数
        //-----------------------------
        reqHandler.setParameter("partner", TenpayUtil.bargainor_id);               //商户号
        reqHandler.setParameter("out_trade_no", sp_billno);                        //商家订单号
        reqHandler.setParameter("total_fee", (money * 100).ToString());            //商品金额,以分为单位
        reqHandler.setParameter("return_url", TenpayUtil.tenpay_return);           //交易完成后跳转的URL
        reqHandler.setParameter("notify_url", TenpayUtil.tenpay_notify);           //接收财付通通知的URL
        reqHandler.setParameter("body", "测试");                                     //商品描述
        reqHandler.setParameter("bank_type", "DEFAULT");                           //银行类型(中介担保时此参数无效)
        reqHandler.setParameter("spbill_create_ip", Page.Request.UserHostAddress); //用户的公网ip,不是商户服务器IP
        reqHandler.setParameter("fee_type", "1");                                  //币种,1人民币
        reqHandler.setParameter("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", "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



        //获取请求带参数的url
        string requestUrl = reqHandler.getRequestURL();

        //Get的实现方式
        string a_link = "<a target=\"_blank\" href=\"" + requestUrl + "\">" + "财付通支付" + "</a>";

        Response.Write(a_link);


        //post实现方式

        /* Response.Write("<form method=\"post\" action=\""+ reqHandler.getGateUrl() + "\" >\n");
         * Hashtable ht = reqHandler.getAllParameters();
         * foreach(DictionaryEntry de in ht)
         * {
         *   Response.Write("<input type=\"hidden\" name=\"" + de.Key + "\" value=\"" + de.Value + "\" >\n");
         * }
         * Response.Write("<input type=\"submit\" value=\"财付通支付\" >\n</form>\n");*/


        //获取debug信息,建议把请求和debug信息写入日志,方便定位问题
        string debuginfo = reqHandler.getDebugInfo();

        Response.Write("<br/>requestUrl:" + requestUrl + "<br/>");
        Response.Write("<br/>debuginfo:" + debuginfo + "<br/>");
    }
Esempio n. 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //商户号
            string bargainor_id = ConfigurationManager.AppSettings["bargainor_id"].ToString();

            //密钥
            string key = ConfigurationManager.AppSettings["tenpay_key"].ToString();


            //创建请求对象
            RequestHandler reqHandler = new RequestHandler(Context);

            //通信对象
            TenpayHttpClient httpClient = new TenpayHttpClient();

            //应答对象
            ClientResponseHandler resHandler = new ClientResponseHandler();


            //当前时间 yyyyMMdd
            string domain_url    = ConfigurationManager.AppSettings["domain_url"].ToString();
            string date          = DateTime.Now.ToString("yyyyMMdd");
            string sp_billno     = Request["order_no"];
            string product_name  = Request["product_name"];
            string order_price   = Request["order_price"];;
            string remarkexplain = Request["remarkexplain"];
            double money         = 0;

            if (null == Request["order_price"])
            {
                Response.End();
                return;
            }
            try
            {
                money = Convert.ToDouble(order_price);
            }
            catch
            {
                //Response.Write("支付金额格式错误!");
                //Response.End();
                //return;
            }
            if (null == sp_billno)
            {
                //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
                sp_billno = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
            }
            else
            {
                sp_billno = Request["order_no"].ToString();
            }


            reqHandler.init();
            //设置密钥
            reqHandler.setKey(key);
            reqHandler.setGateUrl("https://wap.tenpay.com/cgi-bin/wappayv2.0/wappay_init.cgi");



            //-----------------------------
            //设置支付初始化参数
            //-----------------------------
            reqHandler.setParameter("ver", "2.0");
            reqHandler.setParameter("charset", "1");
            reqHandler.setParameter("bank_type", "0");
            reqHandler.setParameter("desc", "订单" + sp_billno);
            reqHandler.setParameter("bargainor_id", bargainor_id);
            reqHandler.setParameter("sp_billno", sp_billno);
            reqHandler.setParameter("total_fee", (money * 100).ToString());
            reqHandler.setParameter("fee_type", "1");
            reqHandler.setParameter("notify_url", domain_url + "/PayRetrun/ZFPay/tenpay/payNotifyUrl.aspx");
            reqHandler.setParameter("callback_url", domain_url + "/PayRetrun/ZFPay/tenpay/payCallbackUrl.aspx");
            reqHandler.setParameter("attach", "attach");

            string initRequestUrl = reqHandler.getRequestURL();

            //设置请求内容
            httpClient.setReqContent(initRequestUrl);
            //设置超时
            httpClient.setTimeOut(5);

            string rescontent    = "";
            string payRequestUrl = "";

            //后台调用
            if (httpClient.call())
            {
                //获取结果
                rescontent = httpClient.getResContent();

                //设置结果参数
                resHandler.setContent(rescontent);

                string token_id = resHandler.getParameter("token_id");

                //成功,则token_id有只
                if (token_id != "")
                {
                    //生成支付请求
                    payRequestUrl = "https://wap.tenpay.com/cgi-bin/wappayv2.0/wappay_gate.cgi?token_id=" + TenpayUtil.UrlEncode(token_id, Request.ContentEncoding.BodyName);

                    //Get的实现方式
                    string a_link = "<script type='text/javascript'>window.location = '" + payRequestUrl + "';</script>";
                    Response.Write(a_link);
                }
                else
                {
                    //获取token_id调用失败 ,显示错误 页面
                    Response.Write("支付初始化错误:" + resHandler.getParameter("err_info") + "<br>");
                }
            }
            else
            {
                //后台调用通信失败
                Response.Write("call err:" + httpClient.getErrInfo() + "<br>" + httpClient.getResponseCode() + "<br>");
                //有可能因为网络原因,请求已经处理,但未收到应答。
            }


            //获取debug信息,建议把请求、应答内容、debug信息,通信返回码写入日志,方便定位问题

            /*
             * Response.Write("http res:" + httpClient.getResponseCode() + "," + httpClient.getErrInfo() + "<br>");
             * Response.Write("req url:" + initRequestUrl + "<br/>");
             * Response.Write("req debug:" + reqHandler.getDebugInfo() + "<br/>");
             * Response.Write("res content:" + Server.HtmlEncode(rescontent) + "<br/>");
             * Response.Write("res debug:" + Server.HtmlEncode(resHandler.getDebugInfo()) + "<br/>");
             * Response.Write("pay req url:" + payRequestUrl + "<br/>");
             */
        }
Esempio n. 7
0
        /// <param name="OrderNo">订单编号</param>
        /// <param name="planeInfo">航班信息(用户显示订单详细信息)</param>
        /// <param name="TotalAmount">总金额</param>
        /// <param name="SupplierCId">供应商公司编号</param>
        private void ShowCgSPayType(string OrderNo, decimal TotalAmount, string planeInfo, string SupplierCId, string OrderId)
        {
            //判断用户绑定的支付帐户信息 是否已经成功加入支付圈
            EyouSoft.IBLL.TicketStructure.ITicketCompanyAccount bll =
                EyouSoft.BLL.TicketStructure.TicketCompanyAccount.CreateInstance();

            //当前只能判断支付宝接口的帐户
            IList <EyouSoft.Model.TicketStructure.TicketCompanyAccount> accountList =
                bll.GetTicketCompanyAccountList(SupplierCId);

            if (accountList != null && accountList.Count > 0)
            {
                foreach (EyouSoft.Model.TicketStructure.TicketCompanyAccount account in accountList)
                {
                    if (account.InterfaceType == EyouSoft.Model.TicketStructure.TicketAccountType.支付宝)
                    {
                        if (account.IsSign)//已经签约
                        {
                            divPayType.Visible = true;
                            #region 支付配置
                            ///////////////////////以下参数是需要设置的相关配置参数,设置后不会更改的///////////////////////////
                            string partner       = AlipayParameters.Partner;                                                                 //合作身份者ID
                            string key           = AlipayParameters.Key;                                                                     //安全检验码
                            string seller_email  = AlipayParameters.Seller_mailer;                                                           //签约支付宝账号或卖家支付宝帐户
                            string input_charset = AlipayParameters.Input_Charset;                                                           //字符编码格式 目前支持 gbk 或 utf-8
                            string notify_url    = AlipayParameters.DomainPath + "/AirTickets/alipay/directpay/notify_url.aspx";             //交易过程中服务器通知的页面 要用 http://格式的完整路径,不允许加?id=123这类自定义参数
                            string return_url    = Domain.UserPublicCenter + "/AirTickets/alipay/directpay/Return_url.aspx";                 //付完款后跳转的页面 要用 http://格式的完整路径,不允许加?id=123这类自定义参数
                            string show_url      = Domain.UserPublicCenter + "/AirTickets/OrderManage/OrderDetails.aspx?OrderId=" + OrderId; //网站商品的展示地址,不允许加?id=123这类自定义参数
                            string sign_type     = AlipayParameters.SignType;                                                                //加密方式 不需修改
                            string antiphishing  = "0";                                                                                      //防钓鱼功能开关,'0'表示该功能关闭,'1'表示该功能开启。默认为关闭
                            //一旦开启,就无法关闭,根据商家自身网站情况请慎重选择是否开启。
                            //申请开通方法:联系我们的客户经理或拨打商户服务电话0571-88158090,帮忙申请开通
                            //若要使用防钓鱼功能,建议使用POST方式请求数据

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

                            ///////////////////////以下参数是需要通过下单时的订单数据传入进来获得////////////////////////////////
                            //必填参数
                            string out_trade_no = OrderNo;                            //请与贵网站订单系统中的唯一订单号匹配
                            string subject      = "同业114机票平台(订单号:" + OrderNo + ")";   //订单名称,显示在支付宝收银台里的“商品名称”里,显示在支付宝的交易管理的“商品名称”的列表里。
                            string body         = "订单号:" + OrderNo + "/" + planeInfo; //订单描述、订单详细、订单备注,显示在支付宝收银台里的“商品描述”里
                            string total_fee    = Utils.GetMoney(TotalAmount);        //订单总金额,显示在支付宝收银台里的“应付总额”里


                            //扩展功能参数——网银提前
                            //string paymethod = "bankPay";                                   //默认支付方式,四个值可选:bankPay(网银); cartoon(卡通); directPay(余额); CASH(网点支付)
                            //string defaultbank = "CMB";                                     //默认网银代号,代号列表见http://club.alipay.com/read.php?tid=8681379
                            //zxb 修改 此处暂不需要网银提前功能
                            string paymethod   = "directPay";
                            string defaultbank = "";

                            //扩展功能参数——防钓鱼
                            string encrypt_key     = "";                                    //防钓鱼时间戳,初始值
                            string exter_invoke_ip = "";                                    //客户端的IP地址,初始值
                            if (antiphishing == "1")
                            {
                                encrypt_key     = AlipayFunction.Query_timestamp(partner);
                                exter_invoke_ip = "";                                       //获取客户端的IP地址,建议:编写获取客户端IP地址的程序
                            }

                            //扩展功能参数——其他
                            string extra_common_param = "";                //自定义参数,可存放任何内容(除=、&等特殊字符外),不会显示在页面上
                            string buyer_email        = "";                //默认买家支付宝账号

                            //扩展功能参数——分润(若要使用,请按照注释要求的格式赋值)
                            string royalty_type       = "";                             //提成类型,该值为固定值:10,不需要修改
                            string royalty_parameters = "";
                            //提成信息集,与需要结合商户网站自身情况动态获取每笔交易的各分润收款账号、各分润金额、各分润说明。最多只能设置10条
                            //提成信息集格式为:收款方Email_1^金额1^备注1|收款方Email_2^金额2^备注2
                            //如:
                            //royalty_type = "10";
                            //royalty_parameters = "[email protected]^0.01^分润备注一|[email protected]^0.01^分润备注二";

                            //扩展功能参数——自定义超时(若要使用,请按照注释要求的格式赋值)
                            //该功能默认不开通,需联系客户经理咨询
                            string it_b_pay = "";  //超时时间,不填默认是15天。八个值可选:1h(1小时),2h(2小时),3h(3小时),1d(1天),3d(3天),7d(7天),15d(15天),1c(当天)

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

                            //构造请求函数
                            AlipayService aliService = new AlipayService(partner, seller_email, return_url, notify_url, show_url, out_trade_no, subject, body, total_fee, paymethod, defaultbank, encrypt_key, exter_invoke_ip, extra_common_param, buyer_email, royalty_type, royalty_parameters, it_b_pay, key, input_charset, sign_type);

                            //GET方式传递
                            string url = aliService.Create_url();
                            PayHtmlText += "<a href=" + url + " onclick=\"return OrderDetails.InsertAccount('2');\"><img border='0' src='" + Domain.ServerComponents + "/images/jipiao/alipay.jpg' /></a>" + "&nbsp;&nbsp;&nbsp;";

                            #endregion
                        }
                    }
                    if (account.InterfaceType == EyouSoft.Model.TicketStructure.TicketAccountType.财付通)
                    {
                        if (account.IsSign) //供应商已经签约财付通
                        {
                            divPayType.Visible = true;
                            #region 财付通支付配置
                            //商户号
                            string bargainor_id = TenpayParameters.Bargainor_ID;
                            //密钥
                            string key1 = TenpayParameters.Key;

                            //当前时间 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(Context);
                            //初始化
                            reqHandler.init();
                            //设置密钥
                            reqHandler.setKey(key1);
                            //-----------------------------
                            //设置支付参数
                            //-----------------------------
                            reqHandler.setParameter("bargainor_id", bargainor_id);                                                               //商户号
                            reqHandler.setParameter("sp_billno", OrderNo);                                                                       //商家订单号
                            reqHandler.setParameter("transaction_id", transaction_id);                                                           //财付通交易单号
                            reqHandler.setParameter("return_url", TenpayParameters.DomainPath + "/AirTickets/tenpay/directpay/Return_url.aspx"); //支付通知url
                            reqHandler.setParameter("desc", string.Format("同业114机票平台(订单号:{0})", OrderNo));                                       //商品名称
                            reqHandler.setParameter("total_fee", Utils.GetMoney(TotalAmount * 100));                                             //商品金额,以分为单
                            reqHandler.setParameter("cs", TenpayParameters.Input_Charset);                                                       //设置编码
                            //用户的公网ip,测试时填写127.0.0.1,只能支持10分以下交易
                            reqHandler.setParameter("spbill_create_ip", Page.Request.UserHostAddress);

                            //获取请求带参数的url
                            string requestUrl = reqHandler.getRequestURL();

                            //Get的实现方式
                            string a_link = "<a  onclick=\"return OrderDetails.InsertAccount('1')\" href=\"" + requestUrl + "\"><img border='0' src='" + Domain.ServerComponents + "/images/jipiao/cft.jpg'  /></a>";
                            PayHtmlText += a_link + "&nbsp;&nbsp;&nbsp;";
                            #endregion
                        }
                    }
                }
            }
        }
Esempio n. 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        /* 商户号,上线时务必将测试商户号替换为正式商户号 */
        string partner = "1900000109";


        //密钥
        string key = "8934e7d15453e97507ef794cf7b0519d";


        //当前时间 yyyyMMdd
        string date = DateTime.Now.ToString("yyyyMMdd");
        //订单号,此处用时间和随机数生成,商户根据自己调整,保证唯一
        string out_trade_no = "" + DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);



        //创建RequestHandler实例
        RequestHandler reqHandler = new RequestHandler(Context);

        //初始化
        reqHandler.init();
        //设置密钥
        reqHandler.setKey(key);
        reqHandler.setGateUrl("https://gw.tenpay.com/gateway/pay.htm");



        //-----------------------------
        //设置支付参数
        //-----------------------------
        reqHandler.setParameter("total_fee", "1");
        //用户的公网ip,测试时填写127.0.0.1,只能支持10分以下交易
        reqHandler.setParameter("spbill_create_ip", Page.Request.UserHostAddress);
        reqHandler.setParameter("return_url", "http://localhost:1588/tenpay_api_b2c/payReturnUrl.aspx");
        //reqHandler.setParameter("return_url", "");
        reqHandler.setParameter("partner", partner);
        reqHandler.setParameter("out_trade_no", out_trade_no);
        reqHandler.setParameter("notify_url", "http://localhost:1588/tenpay_api_b2c/payNotifyUrl.aspx");
        reqHandler.setParameter("attach", "123");
        reqHandler.setParameter("body", "测试");
        reqHandler.setParameter("bank_type", "DEFAULT");


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

        //业务可选参数

        /*
         * reqHandler.setParameter("attach", "");
         * reqHandler.setParameter("product_fee", "");
         * reqHandler.setParameter("transport_fee", "");
         * reqHandler.setParameter("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
         * reqHandler.setParameter("time_expire", "");
         *
         * reqHandler.setParameter("buyer_id", "");
         * reqHandler.setParameter("goods_tag", "");
         * reqHandler.setParameter("agentid", "");
         * reqHandler.setParameter("agent_type", "");
         */



        //获取请求带参数的url
        string requestUrl = reqHandler.getRequestURL();

        //Get的实现方式
        string a_link = "<a target=\"_blank\" href=\"" + requestUrl + "\">" + "财付通支付" + "</a>";

        Response.Write(a_link);


        //post实现方式

        /*
         * Response.Write("<form method=\"post\" action=\""+ reqHandler.getGateUrl() + "\" >\n");
         * Hashtable ht = reqHandler.getAllParameters();
         * foreach(DictionaryEntry de in ht)
         * {
         *  Response.Write("<input type=\"hidden\" name=\"" + de.Key + "\" value=\"" + de.Value + "\" >\n");
         * }
         * Response.Write("<input type=\"submit\" value=\"财付通支付\" >\n</form>\n");
         */

        //获取debug信息,建议把请求和debug信息写入日志,方便定位问题
        //string debuginfo = reqHandler.getDebugInfo();
        //Response.Write("<br/>requestUrl:" + requestUrl + "<br/>");
        //Response.Write("<br/>debuginfo:" + debuginfo + "<br/>");
    }
Esempio n. 9
0
        /// <summary>
        /// 获取支付链接
        /// </summary>
        /// <param name="payWhich">支付方式</param>
        /// <param name="orderNo">订单号</param>
        /// <param name="totol">金额</param>
        /// <returns></returns>
        protected string GetPayUrl(string payWhich, string orderNo, decimal total, string freightType)
        {
            string url = "";

            switch (payWhich)//2-支付宝,1-财付通,3-工行,4-建行,5-农行,6-招行,7-其它
            {
            case "2":
                ///////////////////////以下参数是需要设置的相关配置参数,设置后不会更改的///////////////////////////
                string partner       = AlipayParameters.Partner;                                                     //合作身份者ID
                string key           = AlipayParameters.Key;                                                         //安全检验码
                string seller_email  = AlipayParameters.Seller_mailer;                                               //签约支付宝账号或卖家支付宝帐户
                string input_charset = AlipayParameters.Input_Charset;                                               //字符编码格式 目前支持 gbk 或 utf-8
                string notify_url    = AlipayParameters.DomainPath + "/AirTickets/alipay/directpay/notify_url.aspx"; //交易过程中服务器通知的页面 要用 http://格式的完整路径,不允许加?id=123这类自定义参数
                string return_url    = Domain.UserPublicCenter + "/AirTickets/alipay/directpay/Return_url.aspx";     //付完款后跳转的页面 要用 http://格式的完整路径,不允许加?id=123这类自定义参数
                string show_url      = Domain.UserPublicCenter + "/AirTickets/alipay/directpay/MyOrder.aspx";        //网站商品的展示地址,不允许加?id=123这类自定义参数
                string sign_type     = AlipayParameters.SignType;                                                    //加密方式 不需修改
                string antiphishing  = "0";                                                                          //防钓鱼功能开关,'0'表示该功能关闭,'1'表示该功能开启。默认为关闭
                //一旦开启,就无法关闭,根据商家自身网站情况请慎重选择是否开启。
                //申请开通方法:联系我们的客户经理或拨打商户服务电话0571-88158090,帮忙申请开通
                //若要使用防钓鱼功能,建议使用POST方式请求数据

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

                ///////////////////////以下参数是需要通过下单时的订单数据传入进来获得////////////////////////////////
                //必填参数
                string CgsPayInfo = "";
                if (freightType == "1")
                {
                    CgsPayInfo = "航班信息(单程):" + Utils.GetFormValue("leaveTime") + "/" + Utils.GetFormValue("homeCityName") + "至" + Utils.GetFormValue("destCityName");
                }
                else if (freightType == "2")
                {
                    CgsPayInfo = "航班信息(往返程):去程" + Utils.GetFormValue("leaveTime") + "/" + Utils.GetFormValue("homeCityName") + "至" + Utils.GetFormValue("destCityName") + ";" + " 回程" + Utils.GetFormValue("returnTime") + "/" + Utils.GetFormValue("destCityName") + "至" + Utils.GetFormValue("homeCityName");
                }
                string out_trade_no = orderNo;                             //DateTime.Now.ToString("yyyyMMddHHmmss");;  //请与贵网站订单系统中的唯一订单号匹配
                string subject      = "同业114机票平台(订单号:" + orderNo + ")";    //订单名称,显示在支付宝收银台里的“商品名称”里,显示在支付宝的交易管理的“商品名称”的列表里。
                string body         = "订单号:" + orderNo + "/" + CgsPayInfo; //订单描述、订单详细、订单备注,显示在支付宝收银台里的“商品描述”里
                string total_fee    = Utils.GetMoney(total);               //订单总金额,显示在支付宝收银台里的“应付总额”里


                //扩展功能参数——网银提前
                //string paymethod = "bankPay";                                   //默认支付方式,四个值可选:bankPay(网银); cartoon(卡通); directPay(余额); CASH(网点支付)
                //string defaultbank = "CMB";                                     //默认网银代号,代号列表见http://club.alipay.com/read.php?tid=8681379
                //zxb 修改 此处暂不需要网银提前功能
                string paymethod   = "directPay";
                string defaultbank = "";

                //扩展功能参数——防钓鱼
                string encrypt_key     = "";                                    //防钓鱼时间戳,初始值
                string exter_invoke_ip = "";                                    //客户端的IP地址,初始值
                if (antiphishing == "1")
                {
                    encrypt_key     = AlipayFunction.Query_timestamp(partner);
                    exter_invoke_ip = "";                                       //获取客户端的IP地址,建议:编写获取客户端IP地址的程序
                }

                //扩展功能参数——其他
                string extra_common_param = "";                //自定义参数,可存放任何内容(除=、&等特殊字符外),不会显示在页面上
                string buyer_email        = "";                //默认买家支付宝账号

                //扩展功能参数——分润(若要使用,请按照注释要求的格式赋值)
                string royalty_type       = "";                             //提成类型,该值为固定值:10,不需要修改
                string royalty_parameters = "";
                //提成信息集,与需要结合商户网站自身情况动态获取每笔交易的各分润收款账号、各分润金额、各分润说明。最多只能设置10条
                //提成信息集格式为:收款方Email_1^金额1^备注1|收款方Email_2^金额2^备注2
                //如:
                //royalty_type = "10";
                //royalty_parameters = "[email protected]^0.01^分润备注一|[email protected]^0.01^分润备注二";

                //扩展功能参数——自定义超时(若要使用,请按照注释要求的格式赋值)
                //该功能默认不开通,需联系客户经理咨询
                string it_b_pay = "";  //超时时间,不填默认是15天。八个值可选:1h(1小时),2h(2小时),3h(3小时),1d(1天),3d(3天),7d(7天),15d(15天),1c(当天)

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

                //构造请求函数
                AlipayService aliService = new AlipayService(partner, seller_email, return_url, notify_url, show_url, out_trade_no, subject, body, total_fee, paymethod, defaultbank, encrypt_key, exter_invoke_ip, extra_common_param, buyer_email, royalty_type, royalty_parameters, it_b_pay, key, input_charset, sign_type);
                //GET方式传递
                url = aliService.Create_url();
                break;

            case "1":
                //商户号
                string bargainor_id = TenpayParameters.Bargainor_ID;
                //密钥
                string key1 = TenpayParameters.Key;

                //当前时间 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(Context);
                //初始化
                reqHandler.init();
                //设置密钥
                reqHandler.setKey(key1);
                //-----------------------------
                //设置支付参数
                //-----------------------------
                reqHandler.setParameter("bargainor_id", bargainor_id);                                                               //商户号
                reqHandler.setParameter("sp_billno", orderNo);                                                                       //商家订单号
                reqHandler.setParameter("transaction_id", transaction_id);                                                           //财付通交易单号
                reqHandler.setParameter("return_url", TenpayParameters.DomainPath + "/AirTickets/tenpay/directpay/Return_url.aspx"); //支付通知url
                reqHandler.setParameter("desc", string.Format("同业114机票平台(订单号:{0})", orderNo));                                       //商品名称
                reqHandler.setParameter("total_fee", Utils.GetMoney(total * 100));                                                   //商品金额,以分为单
                reqHandler.setParameter("cs", TenpayParameters.Input_Charset);                                                       //设置编码
                //用户的公网ip,测试时填写127.0.0.1,只能支持10分以下交易
                reqHandler.setParameter("spbill_create_ip", Page.Request.UserHostAddress);
                //获取请求带参数的url
                url = reqHandler.getRequestURL();
                break;
            }
            return(url);
        }
Esempio n. 10
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());
        }
Esempio n. 11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string sp_billno     = Request["order_no"];
        string product_name  = Request["product_name"];
        string order_price   = Request["order_price"];;
        string remarkexplain = Request["remarkexplain"];
        double money         = 0;

        if (null == Request["order_price"])
        {
            Response.End();
            return;
        }
        try
        {
            money = Convert.ToDouble(order_price);
        }
        catch
        {
            //Response.Write("支付金额格式错误!");
            //Response.End();
            //return;
        }
        if (null == sp_billno)
        {
            //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯一
            sp_billno = DateTime.Now.ToString("HHmmss") + TenpayUtil.BuildRandomStr(4);
        }
        else
        {
            sp_billno = Request["order_no"].ToString();
        }


        //财付通订单号,10位商户号+8位日期+10位序列号,需保证全局唯一
        string transaction_id = TenpayUtil.bargainor_id + sp_billno;

        //创建PayRequestHandler实例
        PayRequestHandler reqHandler = new PayRequestHandler(Context);

        //设置密钥
        reqHandler.setKey(TenpayUtil.tenpay_key);

        //初始化
        reqHandler.init();

        //-----------------------------
        //设置支付参数
        //-----------------------------
        reqHandler.setParameter("bargainor_id", TenpayUtil.bargainor_id); //商户号
        reqHandler.setParameter("sp_billno", sp_billno);                  //商家订单号
        reqHandler.setParameter("transaction_id", transaction_id);        //财付通交易单号
        reqHandler.setParameter("return_url", TenpayUtil.tenpay_return);  //支付通知url
        reqHandler.setParameter("desc", "订单号:" + transaction_id);         //商品名称
        reqHandler.setParameter("total_fee", (money * 100).ToString());   //商品金额,以分为单位

        reqHandler.setParameter("cs", "UTF-8");
        reqHandler.setParameter("spbill_create_ip", Request.ServerVariables["REMOTE_ADDR"]);

        //用户ip,测试环境时不要加这个ip参数,正式环境再加此参数
        //reqHandler.setParameter("spbill_create_ip",Page.Request.UserHostAddress);

        //获取请求带参数的url
        string requestUrl = reqHandler.getRequestURL();

        this.hl_main.NavigateUrl = requestUrl;


        //post实现方式

        /*
         * reqHandler.getRequestURL();
         * Response.Write("<form method=\"post\" action=\""+ reqHandler.getGateUrl() + "\" >\n");
         * Hashtable ht = reqHandler.getAllParameters();
         * foreach(DictionaryEntry de in ht)
         * {
         *  Response.Write("<input type=\"hidden\" name=\"" + de.Key + "\" value=\"" + de.Value + "\" >\n");
         * }
         * Response.Write("<input type=\"submit\" value=\"财付通支付\" >\n</form>\n");
         */

        //获取debug信息
        //string debuginfo = reqHandler.getDebugInfo();
        //Response.Write("<br/>" + debuginfo + "<br/>");

        //重定向到财付通支付
        //reqHandler.doSend();
    }
Esempio n. 12
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);
        }
Esempio n. 13
0
        /// <summary>
        /// 平台退款
        /// </summary>
        /// <param name="tenPayParam"></param>
        /// <returns></returns>
        public int ClientPlatformRefund(TenPayParam tenPayParam)
        {
            int result = 0;
            //创建请求对象
            BaseSplitRequestHandler reqHandler = new BaseSplitRequestHandler(HttpContext.Current);

            //通信对象
            TenpayHttpClient httpClient = new TenpayHttpClient();

            //应答对象
            ScriptClientResponseHandler resHandler = new ScriptClientResponseHandler();

            //-----------------------------
            //设置请求参数
            //-----------------------------
            reqHandler.init();
            reqHandler.setKey(key);
            reqHandler.setGateUrl("https://mch.tenpay.com/cgi-bin/refund_b2c_split.cgi");

            reqHandler.setParameter("cmdno", "93");
            reqHandler.setParameter("version", "4");
            reqHandler.setParameter("fee_type", "1");
            reqHandler.setParameter("bargainor_id", bargainor_id);              //商户号
            reqHandler.setParameter("sp_billno", tenPayParam.OldOrderid);       //商家订单号
            reqHandler.setParameter("transaction_id", tenPayParam.PayNo);       //财付通交易单号
            reqHandler.setParameter("return_url", "http://127.0.0.1/");         //后台系统调用,必现填写为http://127.0.0.1/
            reqHandler.setParameter("total_fee", tenPayParam.Total_Tee);
            //退款ID,同个ID财付通认为是同一个退款,格式为109+10位商户号+8位日期+7位序列号
            string refund_id = string.Format("109{0}{1}{2}", bargainor_id, DateTime.Now.ToString("yyyyMMdd"), TenpayUtil.BuildRandomStr(7));

            reqHandler.setParameter("refund_id", refund_id);
            reqHandler.setParameter("refund_fee", tenPayParam.Date);//在这里date指的是退款金额


            //-----------------------------
            //设置通信参数
            //-----------------------------
            //证书必须放在用户下载不到的目录,避免证书被盗取
            httpClient.setCertInfo(pfxPath, bargainor_id);

            string requestUrl = reqHandler.getRequestURL();

            //设置请求内容
            httpClient.setReqContent(requestUrl);
            //设置超时
            httpClient.setTimeOut(10);

            string rescontent = "";

            //后台调用
            if (httpClient.call())
            {
                //获取结果
                rescontent = httpClient.getResContent();

                resHandler.setKey(key);
                //设置结果参数
                resHandler.setContent(rescontent);

                //判断签名及结果
                if (resHandler.isTenpaySign() && resHandler.getParameter("pay_result") == "0")
                {
                    //取结果参数做业务处理
                    result = 1;
                }
                else
                {
                    //错误时,返回结果未签名。
                    //如包格式错误或未确认结果的,请使用原来订单号重新发起,确认结果,避免多次操作
                    result = 2;
                    //string msg=("业务错误信息或签名错误:" + resHandler.getParameter("pay_result") + "," + resHandler.getParameter("pay_info") + "<br>");
                }
            }
            return(result);
        }
Esempio n. 14
0
        /// <summary>
        /// 分账退款接口
        /// </summary>
        /// <returns></returns>
        public bool ClientSplitRollback(TenPayParam tenPayParam)
        {
            PbProject.Logic.Pay.Bill bill = new PbProject.Logic.Pay.Bill();
            bool result = true;

            if (tenPayParam.BackState == 1)
            {
                #region 平台退款
                string details = string.Format("分账参数:{0}", tenPayParam.Bus_Args);
                //平台退款
                int returnresult = ClientPlatformRefund(tenPayParam);

                OnErrorNew("订单号:" + tenPayParam.Orderid + ",平台退款状态:" + returnresult + ",details: " + details);

                switch (returnresult)
                {
                case 0:
                    bill.CreateBillRefundFailedLog(null, tenPayParam.Orderid, "财付通平台退款通信失败:" + details);
                    result = false;
                    break;

                case 1:
                    bill.CreateBillRefund(tenPayParam.Orderid, tenPayParam.PayNo, 4, "在线退款", "财付通退款", details);
                    result = true;
                    break;

                case 2:
                    bill.CreateBillRefundFailedLog(null, tenPayParam.Orderid, "财付通平台退款业务错误信息或签名错误:" + details);
                    result = false;
                    break;

                default:
                    break;
                }
                #endregion
            }
            else
            {
                //创建请求对象
                BaseSplitRequestHandler reqHandler = new BaseSplitRequestHandler(HttpContext.Current);
                //通信对象
                TenpayHttpClient httpClient = new TenpayHttpClient();
                //应答对象
                ScriptClientResponseHandler resHandler = new ScriptClientResponseHandler();
                //请求参数设置

                reqHandler.init();
                reqHandler.setKey(key);
                reqHandler.setGateUrl("https://mch.tenpay.com/cgi-bin/split_rollback.cgi");

                reqHandler.setParameter("cmdno", "95");
                reqHandler.setParameter("version", "4");
                reqHandler.setParameter("fee_type", "1");
                reqHandler.setParameter("bargainor_id", bargainor_id);          //商户号
                reqHandler.setParameter("sp_billno", tenPayParam.OldOrderid);   //商家订单号
                reqHandler.setParameter("transaction_id", tenPayParam.PayNo);   //财付通交易单号[外部订单号]
                reqHandler.setParameter("return_url", "http://127.0.0.1/");     //后台系统调用,必现填写为http://127.0.0.1/
                reqHandler.setParameter("total_fee", tenPayParam.Total_Tee);
                //退款ID,同个ID财付通认为是同一个退款,格式为109+10位商户号+8位日期+7位序列号
                string refund_id = string.Format("109{0}{1}{2}", bargainor_id, DateTime.Now.ToString("yyyyMMdd"), TenpayUtil.BuildRandomStr(7));
                reqHandler.setParameter("refund_id", refund_id);
                reqHandler.setParameter("bus_type", "97");
                //格式:退款总额| (账户^退款金额)[|(账户^退款金额)]*
                reqHandler.setParameter("bus_args", tenPayParam.Bus_Args);

                //-----------------------------
                //设置通信参数
                //-----------------------------
                //证书必须放在用户下载不到的目录,避免证书被盗取
                httpClient.setCertInfo(pfxPath, bargainor_id);

                string requestUrl = reqHandler.getRequestURL();
                //设置请求内容
                httpClient.setReqContent(requestUrl);
                //设置超时
                httpClient.setTimeOut(10);

                string rescontent = "";
                //后台调用

                if (httpClient.call())
                {
                    //获取结果
                    rescontent = httpClient.getResContent();

                    resHandler.setKey(key);
                    //设置结果参数
                    resHandler.setContent(rescontent);

                    //判断签名及结果
                    if (resHandler.isTenpaySign() && resHandler.getParameter("pay_result") == "0")
                    {
                        //分账回退成功
                        bill.UpdateBackState(tenPayParam.OldOrderid, 1);
                        //取结果参数做业务处理
                        // resultMsg = "OK,transaction_id=" + resHandler.getParameter("transaction_id");

                        string details = string.Format("财付通交易号:{0} || {1}", resHandler.getParameter("transaction_id"), tenPayParam.Bus_Args);
                        //平台退款
                        int returnresult = ClientPlatformRefund(tenPayParam);
                        switch (returnresult)
                        {
                        case 0:
                            bill.CreateBillRefundFailedLog(null, tenPayParam.Orderid, "财付通平台退款通信失败:" + details);
                            result = false;
                            break;

                        case 1:
                            bill.CreateBillRefund(tenPayParam.Orderid, tenPayParam.PayNo, 4, "在线退款", "财付通退款", details);
                            result = true;
                            break;

                        case 2:
                            bill.CreateBillRefundFailedLog(null, tenPayParam.Orderid, "财付通平台退款业务错误信息或签名错误:" + details);
                            result = false;
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        result = false;
                        string details = string.Format("财付通分账退款业务错误信息或签名错误:{0},{1}--{2}", resHandler.getParameter("pay_result"), resHandler.getParameter("pay_info"), tenPayParam.Bus_Args);
                        bill.CreateBillRefundFailedLog(null, tenPayParam.Orderid, details); //分账退款失败
                        //错误时,返回结果未签名。
                        //如包格式错误或未确认结果的,请使用原来订单号重新发起,确认结果,避免多次操作
                    }
                }
                else
                {
                    result = false;
                    //后台调用通信失败
                    string details = string.Format("财付通分账退款通信失败:{0}{1}=={2}", httpClient.getErrInfo(), httpClient.getResponseCode(), tenPayParam.Bus_Args);
                    bill.CreateBillRefundFailedLog(null, tenPayParam.Orderid, details); //退款失败
                    //有可能因为网络原因,请求已经处理,但未收到应答。
                }
            }
            return(result);
        }
Esempio n. 15
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);
        }