Exemple #1
0
        public void WXMicroPayCancel(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          wxconfig = bll.GetMerWxpayById(mer_id);

            if (wxconfig == null)
            {
                throw new Exception("未配置微信帐户");
            }
            //
            body.microcancel_par par = new body.microcancel_par();
            par.appid        = wxconfig.wx_appid;
            par.mch_id       = wxconfig.wx_mcid;
            par.nonce_str    = Guid.NewGuid().ToString().Replace("-", "");
            par.out_trade_no = sheet_no;

            var context = request(par.ToString(wxconfig.wx_paykey), mer_id, wxconfig.wx_mcid);
            var parres  = new body.microcancel_res(context);

            if (parres.return_code.ToLower() == "success".ToLower())
            {
                if (parres.result_code.ToLower() == "success".ToLower())
                {
                    need_try   = "0";
                    need_query = "0";
                    errId      = 1;
                    errMsg     = "";
                }
                else
                {
                    if (parres.recall == "Y")
                    {
                        need_try   = "1";
                        need_query = "0";
                        errId      = 0;
                        errMsg     = parres.err_code + "," + parres.err_code_des;
                    }
                    else
                    {
                        need_try   = "0";
                        need_query = "1";
                        errId      = 0;
                        errMsg     = parres.err_code + "," + parres.err_code_des;
                    }
                }
            }
            else
            {
                need_try   = "1";
                need_query = "0";
                errId      = 0;
                errMsg     = parres.return_code + "," + parres.return_msg;
            }
            if (errId == 1)
            {
                LogHelper.writeLog("WXMicroPayCancel()", errMsg, mer_id, sheet_no, par.ToString(wxconfig.wx_paykey));
            }
        }
Exemple #2
0
        /// <summary>
        /// 微信扫码支付
        /// </summary>
        /// <param name="mer_key">常春藤商户key</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>
        public void WXMicroPay(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 wxconfig = bll.GetMerWxpayById(mer_id);

            if (wxconfig == null)
            {
                throw new Exception("未配置微信帐户");
            }
            //
            body.micropay_par par = new body.micropay_par();
            par.appid            = wxconfig.wx_appid;
            par.mch_id           = wxconfig.wx_mcid;
            par.device_info      = jh;
            par.nonce_str        = Guid.NewGuid().ToString().Replace("-", "");
            par.body             = "commongoods";
            par.out_trade_no     = sheet_no;
            par.total_fee        = Convert.ToInt32(pay_amt * 100);
            par.spbill_create_ip = Appsetting.server_ip;
            par.auth_code        = barcode;

            string url = "https://api.mch.weixin.qq.com/pay/micropay";

            var context = request(url, par.ToString(wxconfig.wx_paykey));
            var parres  = new body.micropay_res(context);

            if (parres.return_code.ToLower() == "success".ToLower())
            {
                if (parres.result_code.ToLower() == "success".ToLower())
                {
                    errId  = 0;
                    errMsg = "";
                }
                else
                {
                    if (parres.is_doing(parres.err_code) == true)
                    {
                        errId  = 2;
                        errMsg = "";
                    }
                    else
                    {
                        errId  = 1;
                        errMsg = parres.err_code + "," + parres.err_code_des;
                    }
                }
            }
            else
            {
                errId  = 1;
                errMsg = parres.return_code + "," + parres.return_msg;
            }
            if (errId == 1)
            {
                LogHelper.writeLog("WXMicroPay()", "[" + errId.ToString() + "]" + errMsg, mer_id, barcode, jh, par.ToString(wxconfig.wx_paykey));
            }
        }
Exemple #3
0
        /// <summary>
        /// 微信扫码支付查询订单支付状态
        /// </summary>
        /// <param name="mer_key"></param>
        /// <param name="ord_id"></param>
        /// <param name="sign"></param>
        /// <param name="errId"></param>
        /// <param name="errMsg"></param>
        public void WXMicroPayQuery(string mer_id, string sheet_no, out int errId, out string errMsg)
        {
            IBLL.ISysBLL bll      = new BLL.SysBLL();
            var          wxconfig = bll.GetMerWxpayById(mer_id);

            if (wxconfig == null)
            {
                throw new Exception("未配置微信帐户");
            }
            //
            body.microquery_par par = new body.microquery_par();
            par.appid        = wxconfig.wx_appid;
            par.mch_id       = wxconfig.wx_mcid;
            par.nonce_str    = Guid.NewGuid().ToString().Replace("-", "");
            par.out_trade_no = sheet_no;

            string url     = "https://api.mch.weixin.qq.com/pay/orderquery";
            var    context = request(url, par.ToString(wxconfig.wx_paykey));
            var    parres  = new body.microquery_res(context);

            if (parres.return_code.ToLower() == "success".ToLower())
            {
                if (parres.result_code.ToLower() == "success".ToLower())
                {
                    errId  = 0;
                    errMsg = "";
                    if (parres.is_doing(parres.trade_state) == true)
                    {
                        errId  = 2;
                        errMsg = "";
                    }
                    else if (parres.is_success(parres.trade_state) == true)
                    {
                        errId  = 0;
                        errMsg = "";
                    }
                    else
                    {
                        errId  = 1;
                        errMsg = parres.trade_state + "," + parres.trade_state_desc;
                    }
                }
                else
                {
                    errId  = 2;
                    errMsg = "";
                }
            }
            else
            {
                errId  = 2;
                errMsg = "";
            }
            if (errId == 1)
            {
                LogHelper.writeLog("WXMicroPayQuery()", errMsg, mer_id, sheet_no, par.ToString(wxconfig.wx_paykey));
            }
        }
Exemple #4
0
 /// <summary>
 /// 查询订单微信支付状态
 /// </summary>
 /// <param name="sheet_no">单号</param>
 string IPayBLL.QueryWxPrePay(string sheet_no, string mer_id, out string errMsg)
 {
     DB.IDB db = new DB.DBByAutoClose(Appsetting.conn);
     errMsg = "";
     try
     {
         IBLL.ISysBLL bll = new BLL.SysBLL();
         var          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 res      = wxorder.QueryOrderStatusByOrderId(sheet_no, out errMsg);
         return(res);
     }
     catch (Exception ex)
     {
         LogHelper.writeLog("PayBLL.QueryWxPrePay()", ex.ToString(), sheet_no);
         throw ex;
     }
 }
Exemple #5
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;
            }
        }