void AliMicroCancel(string mer_id, string sheet_no, out string need_try, out string need_query, out int errId, out string errMsg)
        {
            IBLL.ISysBLL bll    = new BLL.SysBLL();
            var          config = bll.GetMerAlipayById(mer_id);

            if (config == null)
            {
                throw new Exception("未配置支付宝帐户");
            }
            //
            body.alimicrocancel_par par = new body.alimicrocancel_par();
            par.app_id       = config.app_id;
            par.method       = "alipay.trade.cancel";
            par.charset      = "utf-8";
            par.sign_type    = "RSA";
            par.timestamp    = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            par.version      = "1.0";
            par.out_trade_no = sheet_no;
            string url = "https://openapi.alipay.com/gateway.do";

            Aop.Api.IAopClient client = new Aop.Api.DefaultAopClient(url, par.app_id, config.rsa1_private);
            Aop.Api.Request.AlipayTradeCancelRequest req = new Aop.Api.Request.AlipayTradeCancelRequest();
            req.BizContent = par.biz_content();
            var response = client.Execute <Aop.Api.Response.AlipayTradeCancelResponse>(req);
            var context  = response.Body;
            var parres   = new body.alimicrocancel_res(context);

            if (parres.code == "10000")
            {
                if (parres.retry_flag == "Y")
                {
                    need_try   = "1";
                    need_query = "0";
                    errId      = 0;
                    errMsg     = parres.sub_msg;
                }
                else
                {
                    need_try   = "0";
                    need_query = "1";
                    errId      = 0;
                    errMsg     = parres.sub_msg;
                }
            }
            else
            {
                need_try   = "1";
                need_query = "0";
                errId      = 0;
                errMsg     = parres.msg;
            }

            if (errId != 0)
            {
                LogHelper.writeLog("AliMicroCancel()", errMsg, errId.ToString(), mer_id, sheet_no, par.biz_content());
            }
        }
Exemple #2
0
 /// <summary>
 /// 查询订单支付宝支付状态
 /// </summary>
 /// <param name="sheet_no">单号</param>
 bool IPayBLL.QueryAliPrePay(string sheet_no, string mer_id, out string errMsg)
 {
     errMsg = "";
     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 res = alibll.Alipay_Query(acc.app_id, acc.rsa1_private, acc.rsa1, sheet_no, out errMsg);
         return(res);
     }
     catch (Exception ex)
     {
         LogHelper.writeLog("PayBLL.QueryAliPrePay()", ex.ToString(), sheet_no);
         throw ex;
     }
 }
Exemple #3
0
        /// <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;
            }
        }
Exemple #4
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;
            }
        }
Exemple #5
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;
            }
        }
        /// <summary>
        /// 微信扫码支付
        /// </summary>
        /// <param name="mer_key">常春藤商户id</param>
        /// <param name="ord_id">订单号</param>
        /// <param name="pay_amt">支付金额</param>
        /// <param name="barcode">支付码</param>
        /// <param name="branch_no">机构码</param>
        /// <param name="sign">客户端签名</param>
        /// <param name="res"></param>
        /// <param name="errMsg"></param>
        void AliMicroPay(string mer_id, string sheet_no, decimal pay_amt, string barcode, string jh, out int errId, out string errMsg)
        {
            IBLL.ISysBLL bll    = new BLL.SysBLL();
            var          config = bll.GetMerAlipayById(mer_id);

            if (config == null)
            {
                throw new Exception("未配置支付宝帐户");
            }
            //
            body.alimicropay_par par = new body.alimicropay_par();
            par.app_id       = config.app_id;
            par.method       = "alipay.trade.pay";
            par.charset      = "utf-8";
            par.sign_type    = "RSA";
            par.timestamp    = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            par.version      = "1.0";
            par.out_trade_no = sheet_no;
            par.scene        = "bar_code";
            par.auth_code    = barcode;
            par.subject      = "commongoods";
            par.total_amount = pay_amt.ToString("0.00");
            par.store_id     = jh;
            string url = "https://openapi.alipay.com/gateway.do";

            Aop.Api.IAopClient client = new Aop.Api.DefaultAopClient(url, par.app_id, config.rsa1_private);
            Aop.Api.Request.AlipayTradePayRequest req = new Aop.Api.Request.AlipayTradePayRequest();
            req.BizContent = par.biz_content();
            var response = client.Execute <Aop.Api.Response.AlipayTradePayResponse>(req);
            var context  = response.Body;
            var parres   = new body.alimicropay_res(context);

            if (parres.code == "10000")
            {
                errId  = 0;
                errMsg = "";
            }
            else if (parres.code == "20000" || parres.code == "20001" || parres.code == "40001" || parres.code == "40002" || parres.code == "40006")//出错
            {
                errId  = 1;
                errMsg = parres.code + "," + parres.msg + "," + parres.sub_code + "," + parres.sub_msg;
            }
            else if (parres.code == "40004")
            {
                if (parres.is_doing(parres.sub_code) == true)
                {
                    errId  = 2;
                    errMsg = "";
                }
                else
                {
                    errId  = 1;
                    errMsg = parres.sub_code + "," + parres.sub_msg;
                }
            }
            else//未知错误
            {
                errId  = 2;
                errMsg = "";
            }
            if (errId == 1)
            {
                LogHelper.writeLog("AliMicroPay()", errMsg, mer_id, sheet_no, par.biz_content());
            }
        }