protected void Page_Load(object sender, EventArgs e) { Log.Info(this.GetType().ToString(), "page load"); if (!IsPostBack) { JsApiPay jsApiPay = new JsApiPay(this); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(); //获取收货地址js函数入口参数 wxEditAddrParam = jsApiPay.GetEditAddressParameters(); ViewState["openid"] = jsApiPay.openid; } 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; } } }
/// <summary> /// 进行微信授权验证,获取Openid /// </summary> /// <param name="UrlCode">URL参数</param> /// <param name="UrlHost">URL服务地址</param> /// <param name="UrlPath">URL路径</param> /// <returns></returns> public static string GetOpenidAndAccessToken(string UrlCode,string Url) { string str=""; JsApiPay jsApiPay = new JsApiPay(); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(UrlCode,Url); if (string.IsNullOrEmpty(UrlCode)) { //如果UrlCode为空,则获取重定向URL str = jsApiPay.url1; } else { //如果UrlCode不为空,则解析Code,获取Openid //用户统一下单接口 str = jsApiPay.openid; str +=","+ jsApiPay.access_token; } } catch (Exception ex) { } return str; }
protected void Page_Load(object sender, EventArgs e) { Log.Info(this.GetType().ToString(), "page load"); if (!IsPostBack) { JsApiPay jsApiPay = new JsApiPay(this); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.GetOpenidAndAccessToken(); ViewState["openid"] = jsApiPay.openid; //GetUserOpenId(); } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>"); BtnSave.Visible = false; } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { JsApiPay jsApiPay = new JsApiPay(this); try { //调用【网页授权获取用户信息】接口获取用户的openid和access_token jsApiPay.appid = appid; jsApiPay.appsecret = "53e3943476118a3dff21fb95848de6d7"; jsApiPay.GetOpenidAndAccessToken(); //ViewState["openid"] = jsApiPay.openid; Response.Write(jsApiPay.openid); BCBill bill = new BCBill(BCPay.PayChannel.WX_JSAPI.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水"); bill.openId = jsApiPay.openid; try { BCBill resultBill = BCPay.BCPayByChannel(bill); timeStamp = resultBill.timestamp; noncestr = resultBill.noncestr; package = resultBill.package; paySign = resultBill.paySign; signType = resultBill.signType; } catch (Exception excption) { Response.Write("<span style='color:#00CD00;font-size:20px'>" + excption.Message + "</span><br/>"); } } catch (Exception ex) { Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + ex.Message + "</span>"); } } }