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"); }
/// <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(); }
/// <summary> /// 立即购买 -> 确认收货地址 -> 确认支付 /// </summary> /// <returns></returns> public ActionResult PayApply() { bool flag = true; string openid = Request.QueryString["openid"]; string total_fee = Request.QueryString["total_fee"]; //检测是否给当前页面传递了相关参数 if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee)) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>"); Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit..."); flag = false; ViewBag.CanSubmit = flag; return View(); } //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数 JsApiPay jsApiPay = new JsApiPay(this.HttpContext); jsApiPay.openid = openid; jsApiPay.total_fee = int.Parse(total_fee); //JSAPI支付预处理 try { WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); string wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数 Session["wxJsApiParam"] = wxJsApiParam; Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam); //在页面上显示订单信息 Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>"); Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>"); } catch (Exception ex) { LogFileHelper.WriteLogByTxt("/WeToken/PayApply页面下单异常:" + ex.Message); Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>"); flag = false; ViewBag.CanSubmit = flag; } ViewBag.CanSubmit = flag; return View(); }
/// <summary> /// 商城主页 /// </summary> /// <returns></returns> public ActionResult Main() { #region Log记录 if (Session.Keys.Cast<string>().Contains("openid")) { } else { if (ZZSCResource.SystemConfig.PrjSettingType == "Server") { JsApiPay jsApiPay = new JsApiPay(this.HttpContext); Tuple<bool, string> tupResult = jsApiPay.GetOpenidAndAccessToken(); if (!tupResult.Item1) { return Redirect(tupResult.Item2); } } } #endregion //校验 if (ZZSCResource.DnmSystemConfig.SystemConfig.PrjSettingType == "TestPay") { return RedirectToAction(ZZSCResource.Redirect.Action.ToString(), ZZSCResource.Redirect.Controller.ToString()); } //Init Data 数据加载 //0.首页广告轮播图片 //1.模块加载 var listNa = shopService.Main_QueryModule(); //2.热门商品加载|先加载全部商品 //var listNb = shopService.Main_QueryCommodity(string.Empty); //var listNb = new WeShopControllerCodeChange().CommodityInfoQueryByPageFun(1, 10, string.Empty); var listNb = new RequestDataControllerCodeChange().CommodityInfoByPageFun(1, 10, string.Empty, string.Empty); ViewBag.listNa = listNa; ViewBag.listNb = listNb; return View(); }
/// <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(); }