Example #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);
        }
Example #2
0
        /// <summary>
        /// 保存配置
        /// </summary>
        /// <param name="config"></param>
        public static void SaveConfig(OAuthQQConfig config)
        {
            string        sDirectory = Mall.Core.Helper.IOHelper.urlToVirtual(WorkDirectory) + "/QQ.config";
            XmlSerializer xml        = new XmlSerializer(typeof(OAuthQQConfig));
            MemoryStream  Stream     = new MemoryStream();

            xml.Serialize(Stream, config);

            byte[]       b       = Stream.ToArray();
            MemoryStream stream2 = new MemoryStream(b);

            Mall.Core.MallIO.CreateFile(sDirectory, stream2, Core.FileCreateType.Create);
        }
Example #3
0
        public void CheckCanEnable()
        {
            OAuthQQConfig qqconfig = QQCore.GetConfig();

            if (string.IsNullOrWhiteSpace(qqconfig.AppId))
            {
                throw new Mall.Core.PluginConfigException("未设置AppId");
            }

            if (string.IsNullOrWhiteSpace(qqconfig.AppKey))
            {
                throw new Mall.Core.PluginConfigException("未设置AppKey");
            }

            if (string.IsNullOrWhiteSpace(qqconfig.AuthorizeURL))
            {
                throw new Mall.Core.PluginConfigException("未设置授权地址(AuthorizeURL)");
            }
        }
Example #4
0
        public string GetOpenLoginUrl(string returnUrl)
        {
            ReturnUrl = returnUrl;
            OAuthQQConfig qqconfig = QQCore.GetConfig();

            if (string.IsNullOrWhiteSpace(qqconfig.AppId))
            {
                throw new MissingFieldException("未配置AppId");
            }
            if (string.IsNullOrWhiteSpace(qqconfig.AppKey))
            {
                throw new MissingFieldException("未配置AppKey");
            }

            string state = "test";
            string scope = "get_user_info";
            string url   = string.Format(qqconfig.AuthorizeURL + "?response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}", qqconfig.AppId, returnUrl, scope, state);

            return(url);
        }
Example #5
0
        /// <summary>
        /// 获取配置
        /// </summary>
        /// <returns></returns>
        public static OAuthQQConfig GetConfig()
        {
            OAuthQQConfig config = new OAuthQQConfig();

            string sDirectory = Mall.Core.Helper.IOHelper.urlToVirtual(WorkDirectory) + "/QQ.config";

            if (MallIO.ExistFile(sDirectory))
            {
                XmlSerializer xs  = new XmlSerializer(typeof(OAuthQQConfig));
                byte[]        b   = Mall.Core.MallIO.GetFileContent(sDirectory);
                string        str = System.Text.Encoding.Default.GetString(b);
                MemoryStream  fs  = new MemoryStream(b);
                config = (OAuthQQConfig)xs.Deserialize(fs);
            }
            else
            {
                SaveConfig(config);
            }

            return(config);
        }
Example #6
0
        public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values)
        {
            var appidItem = values.FirstOrDefault(item => item.Key == "AppId");

            if (string.IsNullOrWhiteSpace(appidItem.Value))
            {
                throw new PluginException("AppId不能为空");
            }

            var appKeyItem = values.FirstOrDefault(item => item.Key == "AppKey");

            if (string.IsNullOrWhiteSpace(appKeyItem.Value))
            {
                throw new PluginException("AppKey不能为空");
            }

            var validateContent = values.FirstOrDefault(item => item.Key == "ValidateContent");

            if (!string.IsNullOrWhiteSpace(validateContent.Value))//如果验证内容不为空,则该内容必须是<meta>节点
            {
                var lowerValidate = validateContent.Value.ToLower();
                if (!lowerValidate.StartsWith("<meta "))
                {
                    throw new PluginException("验证内容必须以meta标签开头");
                }
                if (!lowerValidate.EndsWith(" />"))
                {
                    throw new PluginException("验证内容必须以 /> 结尾");
                }
            }

            OAuthQQConfig oldConfig = QQCore.GetConfig();

            oldConfig.AppId           = appidItem.Value;
            oldConfig.AppKey          = appKeyItem.Value;
            oldConfig.ValidateContent = validateContent.Value;
            QQCore.SaveConfig(oldConfig);
        }
Example #7
0
        public string GetValidateContent()
        {
            OAuthQQConfig config = QQCore.GetConfig();

            return(config.ValidateContent);
        }