Exemplo n.º 1
0
        /// <summary>
        /// 给微信支付做准备,更新相应的数据表
        /// </summary>
        /// <param name="dicPar"></param>
        public void GetPayParams(Dictionary <string, object> dicPar)
        {
            var wxJsApiParam = string.Empty;
            ///要检测的参数信息 money:单位为分
            List <string> pra = new List <string>()
            {
                "GUID", "USER_ID", "money", "stocode", "orderno", "type", "zkje", "zkcode", "zkname", "yhje", "yhcode", "yhname", "strJson"
            };

            //检测方法需要的参数
            if (!CheckActionParameters(dicPar, pra))
            {
                return;
            }
            try
            {
                var openid    = dicPar["USER_ID"].ToString();
                var wxopenid  = Convert.ToString(SQL.SQLTool.ExecuteScalar("SELECT wxopenid FROM WX_members_wx WHERE openid='" + openid + "'"));
                var total_fee = Convert.ToDecimal(dicPar["money"].ToString());
                var stocode   = dicPar["stocode"].ToString();
                var orderno   = dicPar["orderno"].ToString();
                var strJson   = Convert.ToString(dicPar["strJson"]).Replace('\'', '"');

                var sresult = Dishes.GetSoldResult(stocode, strJson);
                if (!string.IsNullOrEmpty(sresult))
                {
                    ToCustomerJson("1", "菜品【" + sresult + "】已售罄");
                    return;
                }

                System.Web.UI.Page page = new System.Web.UI.Page();
                //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
                JsApiPay jsApiPay = new JsApiPay(page);
                jsApiPay.openid    = wxopenid;
                jsApiPay.total_fee = Convert.ToInt32(total_fee * 100);  //*100
                //JSAPI支付预处理

                //查询该订单是否已有商户订单号
                var otn = "select out_trade_no from WX_orderdetails where orderno='" + orderno + "' AND openid='" + openid + "'";

                //查询是否已支付,如果已经支付过,返回错误信息给前端
                var existSql = "select trade_state from wx_pay where out_trade_no=(" + otn + ")";
                var result   = Convert.ToString(SQL.SQLTool.ExecuteScalar(existSql));

                if (result == "SUCCESS")
                {
                    wxJsApiParam = "paid";
                }
                else
                {
                    SetParam.SetParams(stocode);
                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                    wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数

                    var zkmoney = dicPar["zkje"].ToString();
                    var yhmoney = dicPar["yhje"].ToString();

                    try
                    {
                        //此处更新订单及支付相关的表
                        var sql = "update WX_orderdetails set postJson='" + strJson + "',out_trade_no='" + jsApiPay.out_trade_no + "',discountprice='" + total_fee + "',privilegepre='" + zkmoney + "',singlemoney='" + yhmoney + "'  where orderno='" + orderno + "' AND openid='" + openid + "';UPDATE WX_choorderdetail SET conmoney='" + total_fee + "' WHERE detailcode='" + orderno + "';UPDATE dbo.choorderdetailBreakhistory SET yhqmoney='" + yhmoney + "',zkmoney='" + zkmoney + "',disratemoney='" + yhmoney + "',cardCode='" + dicPar["zkcode"].ToString() + "',cschemediscmoney='" + zkmoney + "',dispname='" + dicPar["zkname"].ToString() + "',disccardCode='" + dicPar["zkcode"].ToString() + "' where detailcodes='" + orderno + "';UPDATE dbo.chopayhistory SET couponmoney='" + yhmoney + "',accountcode='" + dicPar["zkcode"].ToString() + "',paymoney='" + total_fee + "',rmmoney='" + total_fee + "' where detailcode='" + orderno + "'";

                        var type = Convert.ToString(dicPar["type"]);
                        if (type == "3") //0后支付,1先支付,2打赏,3充值
                        {
                            var detailcode = Convert.ToString(SQLTool.ExecuteScalar("SELECT dbo.f_GetChoorderNo()"));
                            sql = "insert into WX_orderdetails(source,buscode,stocode,openid,orderno,sumprice,money,discountprice,status,payType,out_trade_no,cardCode,postJson) values ('wechat','88888888','" + stocode + "','" + openid + "','" + detailcode + "','" + total_fee + "','" + total_fee + "','" + total_fee + "','0','" + type + "','" + jsApiPay.out_trade_no + "','" + orderno + "','" + strJson + "')";
                        }

                        SQLTool.ExecuteNonQuery(sql);
                    }
                    catch (Exception ex)
                    {
                        ErrorLog.WriteErrorMessage(ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                wxJsApiParam = "";
                ErrorLog.WriteErrorMessage(ex.ToString());
            }

            Pagcontext.Response.Clear();
            Pagcontext.Response.Write(wxJsApiParam);
            Pagcontext.Response.End();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 给微信支付做准备,更新相应的数据表
        /// </summary>
        /// <param name="dicPar"></param>
        public void GetPayParamsRecharge(Dictionary <string, object> dicPar)
        {
            var wxJsApiParam = string.Empty;
            ///要检测的参数信息 money:单位为分
            List <string> pra = new List <string>()
            {
                "GUID", "USER_ID", "money", "stocode", "strJson", "cardID", "memcode"
            };

            //检测方法需要的参数
            if (!CheckActionParameters(dicPar, pra))
            {
                return;
            }

            var openid = dicPar["USER_ID"].ToString();
            //var wxopenid = Convert.ToString(SQLTool.ExecuteScalar("SELECT wxopenid FROM WX_members_wx WHERE openid='" + openid + "'"));
            var total_fee = Convert.ToDecimal(dicPar["money"].ToString());
            var stocode   = dicPar["stocode"].ToString();
            var strJson   = Convert.ToString(dicPar["strJson"]).Replace('\'', '"');
            var cardId    = dicPar["cardID"].ToString();
            var memcode   = dicPar["memcode"].ToString();

            System.Web.UI.Page page = new System.Web.UI.Page();
            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            JsApiPay jsApiPay = new JsApiPay(page);

            jsApiPay.openid    = openid;
            jsApiPay.total_fee = Convert.ToInt32(total_fee * 100);  //*100
            //JSAPI支付预处理
            try
            {
                SetParam.SetParams(stocode);
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                try
                {
                    var detailcode = Convert.ToString(SQLTool.ExecuteScalar("declare @ordcode varchar(32); exec [dbo].[p_GetOrderCode] @ordcode output;select 'WX'+@ordcode;"));
                    var sql        = "insert into WX_orderdetails(source,buscode,stocode,openid,orderno,sumprice,money,discountprice,status,payType,out_trade_no,postJson) values ('wechat','88888888','" + stocode + "','" + openid + "','" + detailcode + "','" + total_fee + "','" + total_fee + "','" + total_fee + "','0','3','" + jsApiPay.out_trade_no + "','" + strJson + "');";
                    if (!string.IsNullOrEmpty(cardId))
                    {
                        sql += "update members set IDNO='" + Tools.SafeSql(cardId) + "' where ISNULL(IDNO,'')='' and memcode='" + memcode + "';";
                    }
                    SQLTool.ExecuteNonQuery(sql);
                }
                catch (Exception ex)
                {
                    ErrorLog.WriteErrorMessage(ex.ToString());
                }
            }
            catch (Exception ex)
            {
                //  wxJsApiParam = "";
                ErrorLog.WriteErrorMessage("ex:" + ex.ToString());
            }

            try
            {
                Pagcontext.Response.Clear();
                Pagcontext.Response.Write(wxJsApiParam);
            }
            catch (Exception)
            {
            }
            finally
            {
                Pagcontext.Response.End();
            }
        }