Example #1
0
        public static bool GetAccessTokenAndOpenID(string code, string state, out string accessToken, out string openID)
        {
            accessToken = string.Empty;
            openID      = string.Empty;
            try
            {
                if (string.IsNullOrEmpty(code))
                {
                    return(false);
                }

                if (System.Web.HttpContext.Current.Session["qqstate"] == null || System.Web.HttpContext.Current.Session["qqstate"].ToString() != state)
                {
                    return(false);
                }

                string refreshToken = string.Empty;

                accessToken = QQAPI.GetAccessToken(code, out refreshToken);

                openID = QQAPI.GetOpenID(accessToken);
            }
            catch (Exception e)
            {
                //写个日志
                return(false);
            }
            return(true);
        }
        public ActionResult ListAlbum()
        {
            var str = QQAPI.ListAlbum(Session["accessToken"].ToString(), Session["openid"].ToString());

            return(Content(str));
        }
        public ActionResult GetUserInfo()
        {
            GetUserInfoJson info = QQAPI.GetUserInfoToNickName(Session["accessToken"].ToString(), Session["openid"].ToString());

            return(Content(info.nickname));
        }
 public ActionResult qqlogin()
 {
     Session["qqstate"] = (RndSeed.Next(1, 0x5f5e0ff).ToString("00000000") + RndSeed.Next(1, 0x5f5e0ff).ToString("00000000") +
                           RndSeed.Next(1, 0x5f5e0ff).ToString("00000000") + RndSeed.Next(1, 0x5f5e0ff).ToString("00000000"));
     return(Redirect(QQAPI.GetLoginUrl(Session["qqstate"].ToString())));
 }