protected void Page_Load(object sender, EventArgs e) { TenPayParam tenPayParam = new TenPayParam(); tenPayParam.Orderid = getParameter("orderid"); //订单号 tenPayParam.Total_Tee = getParameter("total_tee"); //商品金额 tenPayParam.UserHostAddress = getParameter("userhostaddress"); //ip tenPayParam.Attach = getParameter("attach"); tenPayParam.Bus_Args = getParameter("busargs"); //分账明细 tenPayParam.Bus_Desc = getParameter("busdesc"); tenPayParam.Desc = "机票支付"; string banktype = getParameter("banktype"); if (string.IsNullOrEmpty(banktype)) { tenPayParam.BankType = "0"; } else { tenPayParam.BankType = banktype; } string msgShow = new TenPay().SplitPayRequest(tenPayParam); OnErrorNew(msgShow, false); //} Response.Write(msgShow); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button3_Click(object sender, EventArgs e) { TenPay tenPay = new TenPay(); string price = "10000"; decimal total = decimal.Parse(price); //订单支付金额 decimal supperates = 0.001M; //支付费率 decimal paySXF = FourToFiveNum(total * supperates, 2); //支付手续费 decimal actPrice = total - paySXF; //收款账号金额 string orderId = DateTime.Now.Ticks.ToString(); TenPayParam tenPayParam = new TenPayParam(); tenPayParam.Bus_Args = "261065527^" + 1 + "^1|465853660^" + 1 + "^4|" + "[email protected]^" + 2 + "^4"; tenPayParam.Bus_Desc = "12345^深圳-上海^1^fady^庄^13800138000";///业务描述,特定格式的字符串,格式为:PNR^航程^机票张数^机票销售商在机票平台的id^联系人姓名^联系电话 //tenPayParam.Bus_Desc = "测试"; tenPayParam.Desc = "在线充值"; tenPayParam.Orderid = orderId; tenPayParam.Total_Tee = total.ToString(); tenPayParam.UserHostAddress = Page.Request.UserHostAddress; tenPayParam.Total_Tee = "4"; string strFromValue = new PbProject.Logic.Pay.TenPay().SplitPayRequest(tenPayParam); Response.Write(strFromValue); }
/// <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()); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// 退款查询 /// </summary> /// <param name="payType">支付方式</param> /// <param name="oldOrderId">原支付订单号</param> /// <param name="newOrderId">退款订单号</param> /// <param name="onlineNo">在线交易号 、退款流水号</param> /// <returns></returns> public string RefundSel(string payType, string oldOrderId, string newOrderId, string onlineNo, out string msgShow) { string returnValue = ""; msgShow = ""; try { if (payType == "1" || payType == "5") { #region 支付宝 PbProject.Logic.Pay.AliPay alipay = new PbProject.Logic.Pay.AliPay(); msgShow = (string.IsNullOrEmpty(onlineNo) || onlineNo.Length != 16) ? "请正确输入交易号!" : msgShow; if (msgShow == "") { string str = alipay.QueryRefundResultStr(onlineNo); string[] strs = str.Split('#'); for (int i = 0; i < strs.Length; i++) { if (!string.IsNullOrEmpty(strs[i])) { string[] strss = strs[i].Split('$'); if (!string.IsNullOrEmpty(strss[0]) && strss[0].Contains("SUCCESS")) { //退款成功 msgShow = "退款成功!银行卡 2 - 7个工作日到账,信用卡 2 - 14 个工作日到账!"; break; } } } returnValue = str + "<br/>" + msgShow + "<br/>"; } #endregion } else if (payType == "2" || payType == "6") { #region 快钱 msgShow = (string.IsNullOrEmpty(newOrderId)) ? "请输入订单号!" : msgShow; msgShow = (string.IsNullOrEmpty(oldOrderId)) ? "请输入原订单号!" : msgShow; msgShow = (string.IsNullOrEmpty(onlineNo)) ? "请输入退款流水号!" : msgShow; if (msgShow == "") { PbProject.Logic.Pay._99Bill bill = new PbProject.Logic.Pay._99Bill(); string[] strOrderNoS = onlineNo.Split('|'); for (int i = 0; i < strOrderNoS.Length; i++) { if (!string.IsNullOrEmpty(strOrderNoS[i])) { // strOrderNoS[i]; //快钱退款流水号 string str = bill.GetRefund(oldOrderId, strOrderNoS[i]); if (str != null && str.Contains("<result>10</result>")) { msgShow = "退款成功!银行卡 2 - 7个工作日到账,信用卡 2 - 14 个工作日到账!"; returnValue += str + "<br/>" + msgShow + "<br/>"; break; } else if (str != null && (str.Contains("<result>00</result>") && str.Contains("<errCode></errCode>"))) { msgShow = "退款进行中!需等待快钱审核!银行卡 2 - 7个工作日到账,信用卡 2 - 14 个工作日到账!"; returnValue += str + "<br/>" + msgShow + "<br/>"; break; } else { msgShow = "退款失败!"; returnValue += str + "<br/>" + msgShow + "<br/>"; } } } } #endregion } else if (payType == "3" || payType == "7") { #region 汇付 PbProject.Logic.Pay.ChinaPnr chinaPnr = new PbProject.Logic.Pay.ChinaPnr(); msgShow = (string.IsNullOrEmpty(onlineNo)) ? "请输入退款流水号!" : msgShow; if (msgShow == "") { string[] strOrderNoS = onlineNo.Split('|'); for (int i = 0; i < strOrderNoS.Length; i++) { if (!string.IsNullOrEmpty(strOrderNoS[i])) { // strOrderNoS[i]; //汇付 退款订单号 //string str = chinaPnr.QueryRefundStatus(strOrderNoS[i]).Replace("#", "<br/>\n"); string str = chinaPnr.QueryRefundStatus(strOrderNoS[i]); if (str != null && str.Contains("RespCode=000000") && str.Contains("ErrMsg=退款交易已成功")) { msgShow = " 退款成功!银行卡 2 - 7个工作日到账,信用卡 2 - 14 个工作日到账!"; returnValue += str + "<br/>" + msgShow + "<br/>"; break; } else if (str != null && str.Contains("RespCode=000000") && str.Contains("ErrMsg=退款交易,已扣款,系统处理中")) { msgShow = " 退款成功,退款中!银行卡 2 - 7个工作日到账,信用卡 2 - 14 个工作日到账!"; returnValue += str + "<br/>" + msgShow + "<br/>"; break; } else { msgShow = " 退款失败!"; returnValue += str + "<br/>" + msgShow + "<br/>"; } } } } #endregion } else if (payType == "4" || payType == "8" || payType == "40") { #region 财付通 TenPayParam tenPayParam = new TenPayParam(); tenPayParam.Orderid = newOrderId; tenPayParam.OldOrderid = oldOrderId; tenPayParam.PayNo = onlineNo; tenPayParam.Date = DateTime.Now.ToString("yyyyMMdd"); returnValue = new TenPay().ClientSplitInquire(tenPayParam); #endregion } else { msgShow = "请选择支付方式"; } } catch (Exception) { } return(returnValue); }
/// <summary> /// 退款处理 /// </summary> /// <param name="mOrder">订单 Model</param> /// <param name="uEmployees">用户 Model</param> /// <param name="uCompany">公司 Model</param> /// <returns></returns> public bool TitckOrderRefund(Tb_Ticket_Order mOrder, User_Employees uEmployees, User_Company uCompany, out string msg) { bool result = false; msg = ""; try { if (mOrder.PayWay == 1 || mOrder.PayWay == 5) { #region 支付宝 AliPay aliPay = new AliPay(); string strTime = DateTime.Now.ToString("yyyyMMdd"); string bno = strTime + mOrder.OrderId + DateTime.Now.ToString("HHmm"); string detail_data = ""; string[] Details = new string[3]; Details[0] = bno; //批次号规则 Details[1] = "1"; //1.要退款的支付宝交易号 //2.退款参数 detail_data = mOrder.PayNo + "^" + mOrder.PayMoney.ToString("F2") + "^退款|" + ""; #region 分账信息 string tempSqlWhere = " OrderId='" + mOrder.OrderId + "'"; List <Tb_Order_PayDetail> payDetailList = new PbProject.Logic.Order.Tb_Order_PayDetailBLL().GetListBySqlWhere(tempSqlWhere); payDetailList = bill.OnLinePayDetails(payDetailList); #endregion 分账信息 Tb_Order_PayDetail payDetail = null; decimal realPayMoney = 0; for (int i = 0; i < payDetailList.Count; i++) { payDetail = payDetailList[i]; realPayMoney = payDetail.RealPayMoney; if (payDetail.PayType == "付款" || realPayMoney == 0) { continue; } detail_data += payDetail.PayAccount + "^^" + aliPay._serveremail + "^^" + realPayMoney.ToString("F2") + "^退" + payDetail.PayType + "|"; } detail_data = detail_data.TrimEnd('|'); Details[2] = detail_data; result = aliPay.IsRefund(Details); if (result) { bill.CreateBillRefundFailedLog(uEmployees, mOrder.OrderId, "提交退款成功,等待退款......"); //退款失败 } else { bill.CreateBillRefundFailedLog(uEmployees, mOrder.OrderId, "提交退款失败"); //退款失败 } #endregion } else if (mOrder.PayWay == 2 || mOrder.PayWay == 6) { #region 快钱 _99Bill _99bill = new _99Bill(); string dataTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string detail_data = ""; decimal total = mOrder.PayMoney; //退款金额 int orderPrice = int.Parse((total * 100).ToString().Split('.')[0]); //退款金额 分为单位 int tempPrice = 0; #region 分账信息 string tempSqlWhere = " OrderId='" + mOrder.OrderId + "'"; List <Tb_Order_PayDetail> payDetailList = new PbProject.Logic.Order.Tb_Order_PayDetailBLL().GetListBySqlWhere(tempSqlWhere); payDetailList = bill.OnLinePayDetails(payDetailList); #endregion 分账信息 Tb_Order_PayDetail payDetail = null; decimal realPayMoney = 0; int allTempPrice = 0; for (int i = 0; i < payDetailList.Count; i++) { payDetail = payDetailList[i]; realPayMoney = payDetail.RealPayMoney; if (payDetail.PayType == "付款" || realPayMoney == 0) { continue; } tempPrice = int.Parse((realPayMoney * 100).ToString().Split('.')[0]);//退款金额 分为单位 //"1^[email protected]^5000^爱的|1^[email protected]^7000^分账1|1^[email protected]^8000^分账2"; // Details[3] = "1^" + LinkEmail + "^" + p2 + "^Refund|1^" + account + "^" + p1 + "^Refund"; detail_data += "1^" + payDetail.PayAccount + "^" + tempPrice + "^Refund|"; allTempPrice += tempPrice; } tempPrice = orderPrice - allTempPrice; detail_data += "1^" + _99bill.LinkEmail + "^" + tempPrice + "^Refund|"; //主账号退款 , 用于退款平衡 detail_data = detail_data.TrimEnd('|'); string[] Details = new string[6]; string OldOrderId = (string.IsNullOrEmpty(mOrder.OldOrderId)) ? mOrder.OrderId : mOrder.OldOrderId; Details[0] = OldOrderId; // 订单编号(原订单号) Details[1] = orderPrice.ToString(); // 订单金额 Details[2] = "系统退款"; //备注 Details[3] = detail_data; //退款明细 Details[4] = mOrder.OrderId; // 订单编号(退废订单编号) Details[5] = DateTime.Now.ToString("yyyyMMddHHmmss"); //退款流水号 string str = _99bill.Refund(Details); //PbProject.WebCommon.Log.Log.RecordLog("RefundOper", str, false, null);//日志 result = _99bill.IsRefund(str); if (result == true) { //退款成功,处理订单状态 string indexno = Details[5] + Details[4]; // 退款成功流水号 bill.CreateBillRefund(mOrder.OrderId, indexno, 2, "在线退款", "快钱退款", str); } else { //退款失败日志 bill.CreateBillRefundFailedLog(uEmployees, mOrder.OrderId, "退款失败,请检查:" + str); //退款失败 } #endregion } else if (mOrder.PayWay == 3 || mOrder.PayWay == 7) { #region 汇付 ChinaPnr chinaPnr = new ChinaPnr(); string dataTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string detail_data = ""; decimal total = mOrder.PayMoney; //退款金额 #region 分账信息 string tempSqlWhere = " OrderId='" + mOrder.OrderId + "'"; List <Tb_Order_PayDetail> payDetailList = new PbProject.Logic.Order.Tb_Order_PayDetailBLL().GetListBySqlWhere(tempSqlWhere); payDetailList = bill.OnLinePayDetails(payDetailList); #endregion 分账信息 Tb_Order_PayDetail payDetail = null; decimal realPayMoney = 0; for (int i = 0; i < payDetailList.Count; i++) { payDetail = payDetailList[i]; realPayMoney = payDetail.RealPayMoney; if (payDetail.PayType == "付款" || realPayMoney == 0) { continue; } detail_data += "Agent:" + payDetail.PayAccount + ":" + realPayMoney.ToString("f2") + ";"; } detail_data = detail_data.TrimEnd(';'); string strOrderOldID = string.IsNullOrEmpty(mOrder.OldOrderId) ? mOrder.OrderId : mOrder.OldOrderId; string[] Details = new string[4]; Details[0] = mOrder.OrderId; //订单编号 Details[1] = strOrderOldID; //原订单编号 Details[2] = total.ToString(); //退款总金额 Details[3] = detail_data; //退分润数据集 string value = chinaPnr.Refund(Details[0], Details[1], Details[2], Details[3]); if (value.Contains("RespCode=000000") && value.Contains("ErrMsg=成功")) { result = true; } if (result == true) { string indexno = mOrder.OrderId; // 退款成功流水号 bill.CreateBillRefund(mOrder.OrderId, indexno, 3, "在线退款", "汇付退款", value); } else { bill.CreateBillRefundFailedLog(uEmployees, mOrder.OrderId, "退款失败,请检查:" + value); //退款失败 } #endregion } else if (mOrder.PayWay == 4 || mOrder.PayWay == 8 || mOrder.PayWay == 40) { #region 财付通 // 财付通 暂时不处理 TenPayParam tenPayParam = new TenPayParam(); //内部订单号 tenPayParam.Orderid = mOrder.OrderId; //旧订单号 if (!String.IsNullOrEmpty(mOrder.OldOrderId)) { tenPayParam.OldOrderid = mOrder.OldOrderId; } else { tenPayParam.OldOrderid = mOrder.OrderId; } //财付通交易号 tenPayParam.PayNo = mOrder.PayNo; //总金额 Tb_Ticket_Order tbTicketOrder = new PbProject.Logic.Order.Tb_Ticket_OrderBLL().GetTicketOrderByOrderId(tenPayParam.OldOrderid); if (tbTicketOrder != null) { tenPayParam.Total_Tee = (tbTicketOrder.PayMoney * 100).ToString("F0"); } else { tenPayParam.Total_Tee = (mOrder.PayMoney * 100).ToString("F0"); } tenPayParam.Date = (mOrder.PayMoney * 100).ToString("F0"); /*---------------------分账信息----------------------------*/ string detail_data = string.Format("{0}|", (mOrder.PayMoney * 100).ToString("F0")); string tempSqlWhere = " OrderId='" + mOrder.OrderId + "'"; Tb_Order_PayDetail payDetail = null; decimal realPayMoney = 0; List <Tb_Order_PayDetail> payDetailList = new PbProject.Logic.Order.Tb_Order_PayDetailBLL().GetListBySqlWhere(tempSqlWhere); /* * for (int i = 0; i < payDetailList.Count; i++) * { * payDetail = payDetailList[i]; * if (payDetail.PayType == "付款") * { * tenPayParam.BackState = payDetail.A1; * } * if (payDetail.PayType == "手续费") * { * realPayMoney = payDetail.BuyPoundage; * detail_data += string.Format("{0}^{1}|", payDetail.PayAccount, (realPayMoney * 100).ToString("F0")); * } * } */ // payDetailList = bill.OnLinePayDetails(payDetailList); for (int i = 0; i < payDetailList.Count; i++) { payDetail = payDetailList[i]; realPayMoney = payDetail.RealPayMoney; if (payDetail.PayType == "付款") { tenPayParam.BackState = payDetail.A1; continue; } detail_data += string.Format("{0}^{1}|", payDetail.PayAccount, (realPayMoney * 100).ToString("F0")); } detail_data = detail_data.TrimEnd('|'); //1000|(帐号^退款金额)| /*----------------------------------------------------------*/ //退款分账 tenPayParam.Bus_Args = detail_data; //分账退款 TenPay tenPay = new TenPay(); result = tenPay.ClientSplitRollback(tenPayParam); #endregion } else if (mOrder.PayWay == 14) { #region 账户支付 try { result = bill.CreateVirtualRefundBill(mOrder, uEmployees, uCompany, out msg); if (!result) { //退款失败记录日志 bill.CreateBillRefundFailedLog(uEmployees, mOrder.OrderId, msg); } } catch (Exception) { msg = "退款异常!"; } #endregion } else if (mOrder.PayWay == 15) { // 收银 暂时不处理 result = true; } } catch (Exception) { } return(result); }