/// <summary> /// 结算提交订单 /// </summary> /// <param name="flow_no">收银单号</param> /// <param name="mer_id">商家id</param> /// <param name="jh">机台</param> /// <param name="pay_type">支付方式: W微信支付; Z支付宝支付</param> /// <param name="pay_amt">支付金额</param> /// <param name="prepay_id">微信预支付id</param> /// <param name="qrcode_url">微信/支付宝支付二维码内容</param> void IPayBLL.CreatePrePay(string ori_sheet_no, string mer_id, string jh, string pay_type, decimal pay_amt, out string sheet_no, out string prepay_id, out string qrcode_url) { DB.IDB db = new DB.DBByAutoClose(Appsetting.conn); sheet_no = ""; prepay_id = ""; qrcode_url = ""; try { sheet_no = mer_id + create_sheet_no();//商家编号+14位单号 //微信支付生成微信预支付订单 if (pay_type == "W") { try { IBLL.ISysBLL bll = new BLL.SysBLL(); body.wxpay acc = bll.GetMerWxpayById(mer_id); if (acc == null) { throw new Exception("未初始化微信商家帐户"); } var wxconfig = new Wxpay.WxpayConfig(acc.wx_appid, acc.wx_secret, acc.wx_mcid, acc.wx_paykey); var wxorder = new Wxpay.WxpayOrder(wxconfig); var errMsg = ""; var res = wxorder.Pay4Qrcode(Appsetting.pay_notify_url, sheet_no, pay_amt, "commongoods", Appsetting.server_ip, out errMsg, out prepay_id, out qrcode_url); if (!res) { LogHelper.writeLog("PayBLL.CreatePrePay(1)", "微信预付账单异常", acc.wx_appid, acc.wx_secret, acc.wx_mcid, acc.wx_paykey, sheet_no, Appsetting.pay_notify_url, pay_amt.ToString(), Appsetting.server_ip, errMsg, prepay_id, qrcode_url); throw new Exception("微信预付账单生成失败:" + errMsg); } } catch (Exception ex2) { throw ex2; } } else if (pay_type == "Z") { try { IBLL.ISysBLL bll = new BLL.SysBLL(); body.alipay acc = bll.GetMerAlipayById(mer_id); if (acc == null) { throw new Exception("未初始化支付宝商家帐户"); } Com.Alipay.AliPay alibll = new Com.Alipay.AliPay(); var errMsg = ""; var res = alibll.Alipay_PreCreate(acc.app_id, acc.rsa1_private, acc.rsa1, sheet_no, "commongoods", pay_amt, acc.pid, out qrcode_url, out errMsg); if (!res) { throw new Exception("支付宝预付账单生成失败:" + errMsg); } } catch (Exception ex2) { throw ex2; } } // string sql = "insert into ot_pay_record(sheet_no,mer_id,jh,pay_type,pay_scene,pay_amt,status,create_time,ori_sheet_no)"; sql += "values(@sheet_no,@mer_id,@jh,@pay_type,@pay_scene,@pay_amt,'0',getdate(),@ori_sheet_no) "; var pars = new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("@sheet_no", sheet_no), new System.Data.SqlClient.SqlParameter("@ori_sheet_no", ori_sheet_no), new System.Data.SqlClient.SqlParameter("@mer_id", mer_id), new System.Data.SqlClient.SqlParameter("@jh", jh), new System.Data.SqlClient.SqlParameter("@pay_type", pay_type), new System.Data.SqlClient.SqlParameter("@pay_amt", pay_amt), new System.Data.SqlClient.SqlParameter("@pay_scene", "pre_pay") }; db.ExecuteScalar(sql, pars); } catch (Exception ex) { LogHelper.writeLog("PayBLL.CreatePrePay()", ex.ToString(), sheet_no, ori_sheet_no, mer_id, pay_type, jh, pay_amt.ToString()); throw ex; } }