예제 #1
0
    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>");
        }
    }
예제 #2
0
    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");
                }
            }
        }
    }