Exemplo n.º 1
0
        /// <summary>
        /// 调用js获取收货地址时需要传入的参数
        /// 格式:json串
        /// 包含以下字段:
        ///     appid:公众号id
        ///     scope: 填写“jsapi_address”,获得编辑地址权限
        ///     signType:签名方式,目前仅支持SHA1
        ///     addrSign: 签名,由appid、url、timestamp、noncestr、accesstoken参与签名
        ///     timeStamp:时间戳
        ///     nonceStr: 随机字符串
        /// </summary>
        //public static string wxEditAddrParam { get; set; }

        public ActionResult TestPayAddressInfo()
        {
            JsApiPay jsApiPay = new JsApiPay(this.HttpContext);
            try
            {
                //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                Tuple<bool, string> tup = jsApiPay.GetOpenidAndAccessToken();

                if (!tup.Item1) { return Redirect(tup.Item2); }

                //获取收货地址js函数入口参数
                string wxEditAddrParam = jsApiPay.GetEditAddressParameters();
                ViewBag.WxEditAddrParam = wxEditAddrParam;
                Session["WxEditAddrParam"] = wxEditAddrParam;
            }
            catch (Exception ex)
            {
                Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>");
                /*
                Button1.Visible = false;
                Button2.Visible = false;
                Label1.Visible = false;
                Label2.Visible = false;
                */
            }

            return View();
        }
Exemplo n.º 2
0
        public ActionResult TestNc()
        {
            LogFileHelper.WriteLogByTxt("This is TestController's TestNc");

            try
            {
                JsApiPay jsApiPay = new JsApiPay(this.HttpContext);

                //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                jsApiPay.GetOpenidAndAccessToken();

                //获取收货地址js函数入口参数
                string wxEditAddrParam = jsApiPay.GetEditAddressParameters();
                ViewBag.WxEditAddrParam = wxEditAddrParam;
                Session["openid"] = jsApiPay.openid;
            }
            catch (Exception ex)
            {
                LogFileHelper.WriteLogByTxt("TestNc页面异常信息:" + ex.Message);
                Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>");
                /*
                Button1.Visible = false;
                Button2.Visible = false;
                Label1.Visible = false;
                Label2.Visible = false;
                */
            }

            return Content("JsApiPay is OK");
        }
Exemplo n.º 3
0
        /// <summary>
        /// 立即购买 -> 确认收货地址
        /// </summary>
        /// <returns></returns>
        public ActionResult PayAddressInfo(string id)
        {
            //Request Data
            string beOrderID = id;
            if (string.IsNullOrEmpty(id)) { return View("OrderList"); }

            //ViewBag
            ViewBag.OrderID = beOrderID;

            JsApiPay jsApiPay = new JsApiPay(this.HttpContext);
            try
            {
                //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                Tuple<bool, string> tup = jsApiPay.GetOpenidAndAccessToken();
                if (!tup.Item1) { return Redirect(tup.Item2); }

                //获取收货地址js函数入口参数
                string wxEditAddrParam = jsApiPay.GetEditAddressParameters();
                ViewBag.WxEditAddrParam = wxEditAddrParam;
                Session["WxEditAddrParam"] = wxEditAddrParam;

                //获取订单数据
                IEnumerable<dynamic> vResult = shopService.Query_BeOrderInfo(beOrderID);

                //拼凑
                string strPar = string.Empty;
                string strOrderNum = string.Empty;
                string strCommTitle = string.Empty;
                foreach (var item in vResult.GroupBy(x => x.BeOrderID))
                {
                    var vItem = item.ElementAt(0);
                    strPar += string.Format("订单号:{0};商品名称:{1};总价:{2}", vItem.OrderNum, vItem.Title, vItem.RealPrice);
                    strOrderNum += vItem.OrderNum + ",";
                    strCommTitle += vItem.Title + ",";
                }

                //总金额
                float totalPrice = 0f;
                foreach (var vItem in vResult)
                {
                    totalPrice += vItem.Count * vItem.RealUnitPrice;
                }

                ViewBag.BeOrderLine = vResult;
                ViewBag.TotalPrice = totalPrice;
                ViewBag.StoreName = vResult.ElementAtOrDefault(0) != null ? vResult.ElementAtOrDefault(0).StoreName : string.Empty;
                ViewBag.OrderNum = string.IsNullOrEmpty(strOrderNum) ? string.Empty : strOrderNum.TrimEnd(',');
                ViewBag.CommTitle = string.IsNullOrEmpty(strCommTitle) ? string.Empty : strCommTitle.TrimEnd(',');
                ViewBag.Param = strPar;
            }
            catch (Exception ex)
            {
                LogFileHelper.WriteLogByTxt("PayAddrssInfo页面报错:" + ex.Message);
                Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>");
                /*
                Button1.Visible = false;
                Button2.Visible = false;
                Label1.Visible = false;
                Label2.Visible = false;
                */
            }

            return View();
        }