示例#1
0
        public OAuthUserInfo GetUserInfo(NameValueCollection queryString)
        {
            QOpenClient qzone    = null;
            var         verifier = queryString["code"];
            var         state    = queryString["state"];

            OAuthQQConfig qqconfig = QQCore.GetConfig();
            string        url      = string.Format(qqconfig.AuthorizeURL + "?grant_type=authorization_code&client_id={0}&state={2}&client_secret={3}&code={4}&redirect_uri={1}", qqconfig.AppId, ReturnUrl, state, qqconfig.AppKey, verifier);

            QQConnectConfig.SetCallBackUrl(ReturnUrl);
            qzone = new QOpenClient(qqconfig.AuthorizeURL, qqconfig.AppId, qqconfig.AppKey, verifier, state);
            OAuthUserInfo userInfo = null;

            if (qzone != null)
            {
                userInfo = new OAuthUserInfo();
                var currentUser = qzone.GetCurrentUser();
                userInfo.NickName = currentUser.Nickname;
                userInfo.RealName = currentUser.Nickname;
                if (!string.IsNullOrWhiteSpace(currentUser.Gender) && (currentUser.Gender == "男" || currentUser.Gender == "女"))
                {
                    userInfo.IsMale = currentUser.Gender == "男" ? true : false;
                }
                userInfo.OpenId = qzone.OAuthToken.OpenId;
            }
            return(userInfo);
        }
示例#2
0
        public OAuthUserInfo GetUserInfo(NameValueCollection queryString)
        {
            bool          flag;
            QOpenClient   qOpenClient = null;
            string        item        = queryString["code"];
            string        str         = queryString["state"];
            OAuthQQConfig config      = QQCore.GetConfig();
            string        str1        = string.Concat(config.AuthorizeURL, "?grant_type=authorization_code&client_id={0}&state={2}&client_secret={3}&code={4}&redirect_uri={1}");

            object[] appId = new object[] { config.AppId, Service.ReturnUrl, str, config.AppKey, item };
            string.Format(str1, appId);
            QQConnectConfig.SetCallBackUrl(Service.ReturnUrl);
            qOpenClient = new QOpenClient(config.AuthorizeURL, config.AppId, config.AppKey, item, str);
            OAuthUserInfo oAuthUserInfo = null;

            if (qOpenClient != null)
            {
                oAuthUserInfo = new OAuthUserInfo();
                User currentUser = qOpenClient.GetCurrentUser();
                oAuthUserInfo.NickName = currentUser.Nickname;
                oAuthUserInfo.RealName = currentUser.Nickname;
                if (string.IsNullOrWhiteSpace(currentUser.Gender))
                {
                    flag = true;
                }
                else
                {
                    flag = (currentUser.Gender == "男" ? false : !(currentUser.Gender == "女"));
                }
                if (!flag)
                {
                    oAuthUserInfo.IsMale = new bool?((currentUser.Gender == "男" ? true : false));
                }
                oAuthUserInfo.OpenId = qOpenClient.OAuthToken.OpenId;
            }
            return(oAuthUserInfo);
        }