Exemplo n.º 1
0
        //JsApiPay
        public ActionResult JsApiPay(string OrderId, string OpenId)
        {
            object objResult  = "";
            int    totalPrice = 0;
            string orderId    = OrderId;
            string openid     = OpenId;

            if (Session["orderId"] != null)
            {
                orderId = Session["orderId"].ToString();
                openid  = Session["openId"].ToString();
            }

            var models = OSer.GetOrderDetail(orderId);//正常订单

            if (models.TotalPrice != null && models.TotalPrice > 0)
            {
                totalPrice = Convert.ToInt32(models.TotalPrice * 100);
            }
            if (models.SubtractPrice != null && models.SubtractPrice > 0)
            {
                totalPrice = Convert.ToInt32((models.TotalPrice - models.SubtractPrice) * 100);
            }

            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            try
            {
                WxPayData     unifiedOrderResult = GetUnifiedOrderResult(orderId, openid, totalPrice);
                WxPayData     wxJsApiParam       = GetJsApiParameters();//获取H5调起JS API参数
                ModelForOrder aOrder             = new ModelForOrder()
                {
                    appId        = wxJsApiParam.GetValue("appId").ToString(),
                    nonceStr     = wxJsApiParam.GetValue("nonceStr").ToString(),
                    packageValue = wxJsApiParam.GetValue("package").ToString(),
                    paySign      = wxJsApiParam.GetValue("paySign").ToString(),
                    timeStamp    = wxJsApiParam.GetValue("timeStamp").ToString(),
                    msg          = "1"
                };
                objResult = aOrder;
            }
            catch (Exception ex)
            {
                ModelForOrder aOrder = new ModelForOrder()
                {
                    appId        = "",
                    nonceStr     = "",
                    packageValue = "",
                    paySign      = "",
                    timeStamp    = "",
                    //msg = "请重试,多次失败,请联系管理员."
                    msg = ex + ","
                };
                objResult = aOrder;
            }
            return(Json(objResult));
        }
Exemplo n.º 2
0
        public ActionResult MeterRecharge()
        {
            object objResult    = "";
            string strTotal_fee = Request.Form["totalfee"];
            string strFee       = (double.Parse(strTotal_fee) * 100).ToString();

            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            jsApiPay.openid    = Session["openid"].ToString();
            jsApiPay.total_fee = int.Parse(strFee);

            //JSAPI支付预处理
            try
            {
                string    strBody            = "自闭症家庭训练会员";                   //商品描述
                string    attach             = "帮助每一个自闭症患者,更有尊严的生活";          //附件说明
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(strBody, attach);
                WxPayData wxJsApiParam       = jsApiPay.GetJsApiParameters(); //获取H5调起JS API参数

                ModelForOrder aOrder = new ModelForOrder()
                {
                    appId        = wxJsApiParam.GetValue("appId").ToString(),
                    nonceStr     = wxJsApiParam.GetValue("nonceStr").ToString(),
                    packageValue = wxJsApiParam.GetValue("package").ToString(),
                    paySign      = wxJsApiParam.GetValue("paySign").ToString(),
                    timeStamp    = wxJsApiParam.GetValue("timeStamp").ToString(),
                    msg          = "成功下单,正在接入微信支付."
                };
                objResult = aOrder;
            }
            catch (Exception ex)
            {
                ModelForOrder aOrder = new ModelForOrder()
                {
                    appId        = "",
                    nonceStr     = "",
                    packageValue = "",
                    paySign      = "",
                    timeStamp    = "",
                    msg          = ex.ToString() + "下单失败,请重试,多次失败,请联系管理员.电话:17645134197"
                };
                objResult = aOrder;
            }
            return(Json(objResult));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 开始进行支付
        /// </summary>
        /// <returns></returns>
        public JsonResult WeiXinJsApiPay()
        {
            object objResult    = "";
            string strTotal_fee = Request.Form["totalfee"];
            string strFee       = (double.Parse(strTotal_fee) * 100).ToString();

            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            jsApiPay.openid    = Session["openid"].ToString();
            jsApiPay.total_fee = int.Parse(strFee);

            //JSAPI支付预处理
            try
            {
                string    strBody            = "南宫萧尘微信支付";                    //商品描述
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(strBody);
                WxPayData wxJsApiParam       = jsApiPay.GetJsApiParameters(); //获取H5调起JS API参数,注意,这里引用了官方的demo的方法,由于原方法是返回string的,所以,要对原方法改为下面的代码,代码在下一段

                ModelForOrder aOrder = new ModelForOrder()
                {
                    appId        = wxJsApiParam.GetValue("appId").ToString(),
                    nonceStr     = wxJsApiParam.GetValue("nonceStr").ToString(),
                    packageValue = wxJsApiParam.GetValue("package").ToString(),
                    paySign      = wxJsApiParam.GetValue("paySign").ToString(),
                    timeStamp    = wxJsApiParam.GetValue("timeStamp").ToString(),
                    msg          = "成功下单,正在接入微信支付."
                };
                objResult = aOrder;
            }
            catch (Exception ex)
            {
                ModelForOrder aOrder = new ModelForOrder()
                {
                    appId        = "",
                    nonceStr     = "",
                    packageValue = "",
                    paySign      = "",
                    timeStamp    = "",
                    msg          = "下单失败,请重试,多次失败,请联系管理员."
                };
                objResult = aOrder;
            }
            return(Json(objResult));
        }