Log.Info(this.GetType().ToString(), "支付页面加载");
if (!IsPostBack)
{
JsApiPay jsApiPayId = new JsApiPay(this);
try
{
//调用【网页授权获取用户信息】接口获取用户的openid和access_token
jsApiPayId.GetOpenidAndAccessToken();
//获取收货地址js函数入口参数
//wxEditAddrParam = jsApiPay.GetEditAddressParameters();
ViewState["openid"] = jsApiPayId.openid;
}
catch (Exception ex)
{
Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>");
}
string openid = jsApiPayId.openid.ToString();
//string total_fee = "1";
//支付金额
string total_fee = String.Empty;
total_fee = (int.Parse(Session["czprice"].ToString()) * 100).ToString();
//支付单号
string orderNo = Session["czorderno"].ToString();
string viptel = Session["czviptel"].ToString();
//检测是否给当前页面传递了相关参数
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...");
return;
}
//若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
JsApiPay jsApiPay = new JsApiPay(this);
jsApiPay.openid = openid;
jsApiPay.total_fee = int.Parse(total_fee);
//JSAPI支付预处理
try
{
WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResultChongZhi(orderNo, viptel);
wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
Log.Debug(this.GetType().ToString(), "unifiedOrderResult : " + unifiedOrderResult.ToPrintStr());
//在页面上显示订单信息
//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)
{
Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>");
}
//调用微信接口付款
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ca", "<script type=\"text/javascript\">callpay()</script>");
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章