protected void Page_Load(object sender, EventArgs e) { NG.WeiXin.NGWebOAuth2 webOAuth2 = new NG.WeiXin.NGWebOAuth2(); NGWebOAuth2Ticket mod = webOAuth2.GetOpenidAndAccessToken("snsapi_userinfo"); if (mod != null) { Response.Write("<br>--------------------------<br>"); Response.Write("openid:" + mod.openid); Response.Write("<br>"); Response.Write("access_token:" + mod.access_token); Response.Write("<br>"); Session["openid"] = mod.openid; Session["access_token"] = mod.access_token; } NGWebOAuth2UserInfo userInfo = webOAuth2.GetUserinfo(mod.access_token, mod.openid); if (userInfo != null) { Response.Write("<br>--------------------------<br>"); Response.Write("nickname:" + userInfo.nickname); Response.Write("<br>"); Response.Write("headimgurl:" + userInfo.headimgurl); Response.Write("<br>"); Response.Write("openid:" + userInfo.openid); Response.Write("<br>"); } }
protected void Page_Load(object sender, EventArgs e) { NG.WeiXin.NGWebOAuth2 webOAuth2 = new NG.WeiXin.NGWebOAuth2(); NGWebOAuth2Ticket mod = webOAuth2.GetOpenidAndAccessToken("snsapi_userinfo"); if (mod != null) { Response.Write("<br>--------------------------<br>"); Response.Write("openid:" + mod.openid); Response.Write("<br>"); Response.Write("access_token:" + mod.access_token); Response.Write("<br>"); Session["wx_openid"] = mod.openid; Session["wx_access_token"] = mod.access_token; NG.WeiXin.Log.Debug(this.GetType().ToString(), "【CTTXOAuth2.aspx】openid=" + mod.openid + "&access_token=" + mod.access_token + ""); //采用openid登录 int r = LoginByOpenId(mod.openid); if (r == 1) { Response.Redirect("CTTXHome.aspx"); } else { NGWebOAuth2UserInfo userInfo = webOAuth2.GetUserinfo(mod.access_token, mod.openid); if (userInfo != null) { Response.Write("<br>--------------------------<br>"); Response.Write("nickname:" + userInfo.nickname); Response.Write("<br>"); Response.Write("headimgurl:" + userInfo.headimgurl); Response.Write("<br>"); Response.Write("openid:" + userInfo.openid); Response.Write("<br>"); Session["wx_nickname"] = userInfo.nickname; Session["wx_headimgurl"] = userInfo.headimgurl; NG.WeiXin.Log.Debug(this.GetType().ToString(), "【YqxkjOAuth2.aspx】nickname=" + userInfo.nickname + "&headimgurl=" + userInfo.headimgurl + ""); //获取微信用户信息之后,重定向到用户注册界面 Response.Redirect("CTTXUserLogin.aspx"); } } } }
protected void Page_Load(object sender, EventArgs e) { //统一授权中心,先保存授权之后要跳转的页面 if (Request["local_redirect_url"] != null) { Session["local_redirect_url"] = Request["local_redirect_url"]; } NG.WeiXin.Log.Debug(this.GetType().ToString(), "【YqxkjOAuth2Center.aspx】Session[local_redirect_url]=" + Session["local_redirect_url"] + ""); //重定向到微信服务器授权,微信服务器处理之后再次重定向到当前页面 NG.WeiXin.NGWebOAuth2 webOAuth2 = new NG.WeiXin.NGWebOAuth2(); NGWebOAuth2Ticket mod = webOAuth2.GetOpenidAndAccessToken(""); if (mod != null) { Session["wx_openid"] = mod.openid; Session["wx_access_token"] = mod.access_token; NG.WeiXin.Log.Debug(this.GetType().ToString(), "【YqxkjOAuth2Center.aspx】openid=" + mod.openid + "&access_token=" + mod.access_token + ""); //采用openid登录 int r = LoginByOpenId(mod.openid); if (r == 1) { if (Session["local_redirect_url"] != null) { Response.Redirect(Session["local_redirect_url"].ToString()); } else { Response.Redirect("YqxkjHome.aspx?r=" + DateTime.Now.Ticks); } } else { //重定向到用户注册界面 Response.Redirect("YqxkjOAuth2.aspx?r=" + DateTime.Now.Ticks); } } }