/// <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(); }