コード例 #1
0
ファイル: TenPay.cs プロジェクト: toyslife/PiaoBaoWork3.0
        /// <summary>
        /// 签约查询
        /// </summary>
        /// <returns></returns>
        public int TrustRequest(string account)
        {
            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/inquire_entrust_relation.cgi");

            reqHandler.setParameter("cmdno", "99");
            reqHandler.setParameter("bargainor_id", bargainor_id);
            reqHandler.setParameter("purchaser_id", account);
            reqHandler.setParameter("type", "1");
            reqHandler.setParameter("return_url", "http://127.0.0.1/");
            reqHandler.setParameter("version", "4");

            httpClient.setCertInfo(pfxPath, bargainor_id);
            string requestUrl = reqHandler.getRequestURL();

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

            //后台调用
            if (httpClient.call())
            {
                //获取结果
                rescontent = httpClient.getResContent();
                resHandler.setKey(key);
                //设置结果参数
                resHandler.setContent(rescontent);
                //判断签名及结果
                if (resHandler.isTenpaySign() && resHandler.getParameter("status") == "1")
                {
                    result = 1;
                }
                else
                {
                    result = 2;
                }
            }
            return(result);
        }
コード例 #2
0
        private void SaveData()
        {
            bool   IsResult = false;
            string OrderId  = Utils.GetFormValue(this.CancleOrder_hidOrderId.UniqueID);//订单ID

            //根据ID获取订单明细
            EyouSoft.IBLL.TicketStructure.ITicketOrder OrderBll = EyouSoft.BLL.TicketStructure.TicketOrder.CreateInstance();
            orderInfo = OrderBll.GetOrderInfoById(OrderId);
            //根据订单ID获取订单最新的变更信息
            orderChangeInfo = OrderBll.GetLatestChange(OrderId);

            //判断是否有当前订单内容
            if (orderInfo == null)//没有
            {
                //输出提示信息
                Utils.ResponseMeg(false, "当前订单不存在");
            }

            EyouSoft.Model.TicketStructure.OrderState?OrderState = null;                                         //请求的订单状态
            int tmpOrderStateId = Utils.GetInt(Utils.GetFormValue(this.CancleOrder_hidOrderState.UniqueID), -1); //订单状态ID

            if (tmpOrderStateId != -1)
            {
                OrderState = (EyouSoft.Model.TicketStructure.OrderState)tmpOrderStateId;
            }

            EyouSoft.Model.TicketStructure.OrderChangeType?ChangeType = null;                                         //请求的订单变更类型
            int tmpOrderChangeTypeId = Utils.GetInt(Utils.GetFormValue(this.CancleOrder_hidChangeType.UniqueID), -1); //订单变更类型ID

            if (tmpOrderChangeTypeId != -1)
            {
                ChangeType = (EyouSoft.Model.TicketStructure.OrderChangeType)tmpOrderChangeTypeId;
            }

            EyouSoft.Model.TicketStructure.OrderInfo OrderModel = orderInfo;        //订单明细

            string Remark = Server.UrlDecode(Utils.GetFormValue("txtRemark", 250)); //备注信息

            /*
             * 根据请求的订单状态,请求的订单变更类型,获取请求类型
             */
            if (OrderState == EyouSoft.Model.TicketStructure.OrderState.等待审核)// 拒绝审核订单请求
            {
                #region 拒绝审核
                //判断当前订单状态与 请求的订单状态是否同步
                if (OrderState == OrderModel.OrderState)
                {
                    IsResult = OrderBll.SupplierNotCheckOrder(OrderId, Remark, SiteUserInfo.ID, SiteUserInfo.CompanyID);
                    Utils.ResponseMeg(IsResult, IsResult ? "订单修改成功" : "订单修改失败,请稍候再试");
                }
                else
                {
                    Utils.ResponseMeg(false, "页面已经过期");
                }
                #endregion
            }
            else if (OrderState == EyouSoft.Model.TicketStructure.OrderState.支付成功)// 拒绝出票订单请求
            {
                #region 拒绝出票
                //判断当前订单状态与 请求的订单状态是否同步
                if (OrderState != OrderModel.OrderState)
                {
                    Utils.ResponseMeg(false, "页面已经过期");
                }
                string BatchNo = string.Empty;
                // 判断是否有写入支付记录
                IList <EyouSoft.Model.TicketStructure.TicketPay> PayList =
                    OrderBll.GetPayList(OrderModel.OrderId, EyouSoft.Model.TicketStructure.ItemType.平台到采购商_订单, string.Empty, string.Empty);
                if (PayList == null || PayList.Count == 0 || PayList.Where(item => item.PayState == EyouSoft.Model.TicketStructure.PayState.交易完成).Count() == 0)
                {
                    // 拒绝出票完成前写入支付明细记录
                    IsResult = OrderBll.NoOutputTicketBefore(OrderId, OrderModel.OrderNo, SiteUserInfo.ID, SiteUserInfo.CompanyID, OrderModel.TotalAmount, OrderModel.PayType, Remark, out BatchNo);
                }

                // 获取当前订单上相关的支付接口信息和账户信息
                #region 获取当前订单上相关的支付接口信息和账户信息
                string AccountNumber = string.Empty;
                string PayNumber     = string.Empty;//支付接口返回的交易号
                EyouSoft.Model.TicketStructure.OrderAccountInfo AccountModel = OrderBll.GetOrderAccountInfo(OrderModel.OrderId);
                if (AccountModel != null)
                {
                    AccountNumber = AccountModel.PayAccount;
                    //AccountNumber = "*****@*****.**";
                    PayNumber = AccountModel.PayNumber;
                }
                AccountModel = null;
                #endregion

                #region 退款
                if (OrderModel.PayType == EyouSoft.Model.TicketStructure.TicketAccountType.支付宝)
                {
                    #region 支付宝退款
                    string partner       = AlipayParameters.Partner;                                                    //合作身份者ID
                    string key           = AlipayParameters.Key;                                                        //安全检验码
                    string input_charset = AlipayParameters.Input_Charset;                                              //字符编码格式 目前支持 gbk 或 utf-8
                    string sign_type     = AlipayParameters.SignType;                                                   //加密方式 不需修改

                    string notify_url  = AlipayParameters.DomainPath + "/TicketsCenter/alipay/refund/notify3_url.aspx"; //通知地址
                    string batch_no    = BatchNo;                                                                       //批次号
                    string refund_date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");                                  //退款日期
                    string batch_num   = "1";                                                                           //退款数量
                    string detail_data = "";                                                                            //退款请求数据集

                    //计算支付宝退款金额对应的手续费
                    decimal alipayFee = Refund_Platform_Parameter.ComputeAlipayFee(OrderModel.TotalAmount);
                    if (alipayFee > 0)
                    {
                        Refund_Platform_Parameter parameter = new Refund_Platform_Parameter(
                            PayNumber, OrderModel.TotalAmount.ToString("F2"), Remark,
                            AlipayParameters.Seller_mailer,
                            alipayFee.ToString("F2"), Remark);
                        detail_data = parameter.ToString();
                    }
                    else
                    {
                        Refund_Platform_Parameter parameter = new Refund_Platform_Parameter(PayNumber, OrderModel.TotalAmount.ToString("F2"), Remark);
                        detail_data = parameter.ToString();
                    }


                    RefundNoPwd refund = new RefundNoPwd(partner, key, sign_type, input_charset, notify_url, batch_no, refund_date, batch_num, detail_data);

                    string url = refund.Create_url();

                    CreateSSL ssl = new CreateSSL(url);

                    string responseFromServer = ssl.GetResponse();

                    Distribute_royalty_Result result = new Distribute_royalty_Result(responseFromServer);

                    IsResult = result.IsSuccess;

                    //判断退款请求是否提交成功
                    if (result.IsSuccess == false)//退款请求提交失败
                    {
                        OrderBll.PayAfterCallBack(PayNumber, OrderModel.TotalAmount,
                                                  EyouSoft.Model.TicketStructure.PayState.未提交到支付接口,
                                                  EyouSoft.Model.TicketStructure.TicketAccountType.支付宝,
                                                  string.Empty, result.ErrorCode, OrderModel.OrderNo, DateTime.Now, batch_no);

                        Utils.ResponseMeg(false, "退款请求提交失败,请稍候再试");
                    }
                    else//退款请求提交成功
                    {
                        //因为支付宝的退款成功信息,是通过异步通知的方式通知
                        //返回到客户端后,在客户端需要启用 实时的请求 查询 数据库,查看退款成功或者失败
                        Response.Clear();
                        Response.Write(string.Format("{{success:'1',message:'{0}',paytype:'{1}',batchno:'{2}'}}",
                                                     "退款请求提交成功,正在退款中...",
                                                     "2",
                                                     batch_no));
                        Response.End();
                    }
                    #endregion
                }
                else if (OrderModel.PayType == EyouSoft.Model.TicketStructure.TicketAccountType.财付通)
                {
                    #region 财付通退款
                    //商户号
                    string bargainor_id = TenpayParameters.Bargainor_ID;
                    //密钥
                    string key = TenpayParameters.Key;

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

                    //通信对象
                    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", OrderModel.OrderNo);   //商家订单号
                    reqHandler.setParameter("transaction_id", PayNumber);       //财付通交易单号
                    reqHandler.setParameter("return_url", "http://127.0.0.1/"); //后台系统调用,必现填写为http://127.0.0.1/
                    reqHandler.setParameter("total_fee", Utils.GetMoney(OrderModel.TotalAmount * 100));
                    //退款ID,同个ID财付通认为是同一个退款,格式为109+10位商户号+8位日期+7位序列号
                    reqHandler.setParameter("refund_id", "109" + bargainor_id + BatchNo);
                    reqHandler.setParameter("refund_fee", Utils.GetMoney(OrderModel.TotalAmount * 100));


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

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

                    string rescontent = "";

                    IList <EyouSoft.Model.TicketStructure.TicketPay> tmpPayList = EyouSoft.BLL.TicketStructure.TicketOrder.CreateInstance().GetPayList(string.Empty, EyouSoft.Model.TicketStructure.ItemType.平台到采购商_订单, string.Empty, BatchNo);

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

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

                        //判断签名及结果
                        if (resHandler.isTenpaySign() && resHandler.getParameter("pay_result") == "0")
                        {
                            //取结果参数做业务处理
                            if (tmpPayList != null && tmpPayList.Count > 0)
                            {
                                EyouSoft.Model.TicketStructure.TicketPay PayModel = tmpPayList[0];

                                // 拒绝出票完成后更新订单状态为‘拒绝出票’,并修改支付明细状态
                                IsResult = EyouSoft.BLL.TicketStructure.TicketOrder.CreateInstance().PayAfterCallBack(PayNumber, PayModel.PayPrice, EyouSoft.Model.TicketStructure.PayState.交易完成, PayModel.PayType, string.Empty, PayModel.Remark, PayModel.TradeNo, DateTime.Now, BatchNo);

                                //判断支付记录 修改是否成功
                                if (IsResult)//成功
                                {
                                    Utils.ResponseMeg(true, "款项已经成功退到采购商帐户中,拒绝出票成功");
                                }
                                else//失败
                                {
                                    Utils.ResponseMeg(true, "款项已经成功退到采购商帐户中,订单状态修改失败,请联系客服");
                                }

                                PayModel = null;
                            }
                            tmpPayList = null;
                        }
                        else
                        {
                            string errorCode = resHandler.getParameter("pay_result");
                            //错误时,返回结果未签名。
                            //如包格式错误或未确认结果的,请使用原来订单号重新发起,确认结果,避免多次操作
                            if (tmpPayList != null && tmpPayList.Count > 0)
                            {
                                EyouSoft.Model.TicketStructure.TicketPay PayModel = tmpPayList[0];
                                //修改之前的支付记录 为 交易失败
                                EyouSoft.BLL.TicketStructure.TicketOrder.CreateInstance().PayAfterCallBack(PayNumber, PayModel.PayPrice, EyouSoft.Model.TicketStructure.PayState.交易失败, PayModel.PayType, string.Empty, PayModel.Remark, PayModel.TradeNo, DateTime.Now, BatchNo);
                                PayModel = null;
                            }
                            IsResult   = false;
                            tmpPayList = null;

                            Utils.ResponseMeg(false, "退款失败,修改订单失败(错误码:" + errorCode + ")");
                        }
                    }
                    else
                    {
                        //后台调用通信失败
                        if (tmpPayList != null && tmpPayList.Count > 0)
                        {
                            EyouSoft.Model.TicketStructure.TicketPay PayModel = tmpPayList[0];

                            EyouSoft.BLL.TicketStructure.TicketOrder.CreateInstance().PayAfterCallBack(PayNumber, PayModel.PayPrice, EyouSoft.Model.TicketStructure.PayState.交易失败, PayModel.PayType, string.Empty, PayModel.Remark, PayModel.TradeNo, DateTime.Now, BatchNo);
                            PayModel = null;
                        }
                        IsResult   = false;
                        tmpPayList = null;
                        //有可能因为网络原因,请求已经处理,但未收到应答。

                        Utils.ResponseMeg(false, "操作失败,有可能因为网络原因,请求已经处理,但未收到应答。");
                    }

                    #endregion
                }
                #endregion
                #endregion
            }
            else if (OrderState == EyouSoft.Model.TicketStructure.OrderState.出票完成)
            {
                if (ChangeType.HasValue == false)
                {
                    Utils.ResponseMeg(false, "参数错误");
                }

                #region 拒绝退票、改签、改期、作废
                string ChangeID = string.Empty;
                EyouSoft.Model.TicketStructure.OrderChangeInfo ChangeModel = orderChangeInfo;
                //OrderBll.GetLatestChange(OrderModel.OrderId);

                /*
                 * 判断请求的订单处理状态 是否与 订单的当前状态  是否同步
                 * */
                if (ChangeModel == null)
                {
                    Utils.ResponseNoPermit("当前订单不能进行【退/废/改/签】处理");
                }
                if (ChangeType.Value != ChangeModel.ChangeType ||
                    ChangeModel.ChangeState == EyouSoft.Model.TicketStructure.OrderChangeState.接受 ||
                    ChangeModel.ChangeState == EyouSoft.Model.TicketStructure.OrderChangeState.拒绝)
                {
                    Utils.ResponseNoPermit("当前订单的状态已经被修改");
                }
                ChangeID = ChangeModel.ChangeId;
                IsResult = OrderBll.CheckOrderChange(ChangeID, SiteUserInfo.ID, Remark, EyouSoft.Model.TicketStructure.OrderChangeState.拒绝);
                Utils.ResponseMeg(IsResult, IsResult ? "订单修改成功" : "订单修改失败,请稍候再试");
                #endregion
            }
            //return IsResult;
        }
コード例 #3
0
ファイル: TenPay.cs プロジェクト: toyslife/PiaoBaoWork3.0
        /// <summary>
        /// 订单查询接口
        /// </summary>
        /// <param name="tenpayParam"></param>
        /// <returns></returns>
        public string ClientSplitInquire(TenPayParam tenpayParam)
        {
            StringBuilder sbxml = new StringBuilder();
            //创建请求对象
            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/inquire_refund.cgi");

            reqHandler.setParameter("cmdno", "96");
            reqHandler.setParameter("version", "4");
            reqHandler.setParameter("bargainor_id", bargainor_id);        //商户号
            reqHandler.setParameter("sp_billno", tenpayParam.Orderid);    //商家订单号
            reqHandler.setParameter("transaction_id", tenpayParam.PayNo); //财付通订单号
            reqHandler.setParameter("return_url", "http://127.0.0.1/");   //后台系统调用,必现填写为http://127.0.0.1/
            reqHandler.setParameter("date", tenpayParam.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")
                {
                    sbxml.Append("订单已支付成功!\r\n");
                    sbxml.AppendFormat("财付通订单号:{0}\r\n", resHandler.getParameter("transaction_id"));
                    sbxml.AppendFormat("支付时间:{0}\r\n", resHandler.getParameter("pay_time"));
                    sbxml.AppendFormat("bus_type:{0}\r\n", resHandler.getParameter("bus_type"));
                    sbxml.AppendFormat("分账参数:{0}\r\n", resHandler.getParameter("bus_args"));
                    if (!string.IsNullOrEmpty(resHandler.getParameter("bus_split_refund_args")))
                    {
                        sbxml.AppendFormat("分账回退成功:{0}\r\n", resHandler.getParameter("bus_split_refund_args"));
                    }
                    else
                    {
                        sbxml.AppendFormat("未分账回退\r\n");
                    }
                    if (!string.IsNullOrEmpty(resHandler.getParameter("bus_platform_re")))
                    {
                        sbxml.AppendFormat("平台退款成功:{0}\r\n", resHandler.getParameter("bus_platform_re"));
                    }
                    else
                    {
                        sbxml.Append("未平台退款\r\n");
                    }
                    if (!string.IsNullOrEmpty(resHandler.getParameter("bus_freeze_args")))
                    {
                        sbxml.AppendFormat("已冻结:{0}\r\n", resHandler.getParameter("bus_freeze_args"));
                    }
                    else
                    {
                        sbxml.Append("账户未冻结\r\n");
                    }
                }
                else
                {
                    sbxml.Append("业务错误信息或签名错误\r\n返回码:" + resHandler.getParameter("pay_result") + "\r\n返回信息:" + resHandler.getParameter("pay_info"));
                }
            }
            else
            {
                //后台调用通信失败
                sbxml.Append("call err:" + httpClient.getErrInfo() + "\r\n" + httpClient.getResponseCode());
                //有可能因为网络原因,请求已经处理,但未收到应答。
            }
            return(sbxml.ToString());
        }
コード例 #4
0
ファイル: TenPay.cs プロジェクト: toyslife/PiaoBaoWork3.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);
        }
コード例 #5
0
ファイル: TenPay.cs プロジェクト: toyslife/PiaoBaoWork3.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);
        }
コード例 #6
0
ファイル: TenPay.cs プロジェクト: toyslife/PiaoBaoWork3.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);
        }