Esempio n. 1
0
        string IPayBLL.Query(string mer_id, string sheet_no, string pay_type)
        {
            DB.IDB db     = new DB.DBByAutoClose(Appsetting.conn);
            string status = "0";

            try
            {
                //微信支付生成微信预支付订单
                if (pay_type == "W")
                {
                    try
                    {
                        Wxpay.MicroPay bll  = new Wxpay.MicroPay();
                        int            eid  = 0;
                        string         emsg = "";
                        bll.WXMicroPayQuery(mer_id, sheet_no, out eid, out emsg);
                        if (eid == 0)
                        {
                            status = "1";
                        }
                        else if (eid == 1)
                        {
                            status = "2";
                            throw new Exception("微信扫码支付失败[" + eid.ToString() + "]:" + emsg);
                        }
                        else
                        {
                            status = "0";
                        }
                    }
                    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 emsg = "";
                        var res  = alibll.Alipay_Query(acc.app_id, acc.rsa1_private, acc.rsa1, sheet_no, out emsg);

                        if (!res)
                        {
                            throw new Exception("支付宝扫码支付失败:" + emsg);
                        }
                        else
                        {
                            status = "1";
                        }
                    }
                    catch (Exception ex2)
                    {
                        throw ex2;
                    }
                }
                //
                if (status != "1")
                {
                    string sql  = "update ot_pay_record set status=@status where sheet_no=@sheet_no ";
                    var    pars = new System.Data.SqlClient.SqlParameter[]
                    {
                        new System.Data.SqlClient.SqlParameter("@sheet_no", sheet_no),
                        new System.Data.SqlClient.SqlParameter("@status", status)
                    };

                    db.ExecuteScalar(sql, pars);
                }
                return(status);
            }
            catch (Exception ex)
            {
                LogHelper.writeLog("PayBLL.Query()", ex.ToString(), sheet_no, mer_id, pay_type);
                throw ex;
            }
        }
Esempio n. 2
0
        void IPayBLL.MicroPay(string ori_sheet_no, string mer_id, string jh, string pay_type, decimal pay_amt, string barcode, out string sheet_no, out string status, out int errId, out string errMsg)
        {
            DB.IDB db = new DB.DBByAutoClose(Appsetting.conn);
            sheet_no = "";
            errId    = 0;
            errMsg   = "";
            status   = "0";
            try
            {
                sheet_no = mer_id + create_sheet_no();//商家编号+14位单号
                //微信支付生成微信预支付订单
                if (pay_type == "W")
                {
                    try
                    {
                        Wxpay.MicroPay bll  = new Wxpay.MicroPay();
                        int            eid  = 0;
                        string         emsg = "";
                        bll.WXMicroPay(mer_id, sheet_no, pay_amt, barcode, jh, out eid, out emsg);
                        errId  = eid;
                        errMsg = emsg;
                        if (eid == 0)
                        {
                            status = "1";
                        }
                        else if (eid == 1)
                        {
                            status = "2";
                            throw new Exception("微信扫码支付失败[" + eid.ToString() + "]:" + errMsg);
                        }
                        else
                        {
                            status = "0";
                        }
                    }
                    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 emsg = "";
                        var res  = alibll.Alipay_BarcodePay(acc.app_id, acc.rsa1_private, acc.rsa1, sheet_no, "commongoods", pay_amt, barcode, acc.pid, out emsg);
                        status = "1";
                        if (!res)
                        {
                            status = "2";
                            errId  = -1;
                            errMsg = emsg;
                            throw new Exception("支付宝扫码支付失败:" + emsg);
                        }
                    }
                    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,@status,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("@status", status),
                    new System.Data.SqlClient.SqlParameter("@pay_scene", "barcode_pay")
                };

                db.ExecuteScalar(sql, pars);
            }
            catch (Exception ex)
            {
                LogHelper.writeLog("PayBLL.MicroPay()", ex.ToString(), sheet_no, ori_sheet_no, mer_id, pay_type, jh, pay_amt.ToString());
                throw ex;
            }
        }