コード例 #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
ファイル: Service.cs プロジェクト: Shikyoh/HSWB2B2C
        public FormData GetFormData()
        {
            OAuthQQConfig config    = QQCore.GetConfig();
            FormData      formDatum = new FormData();

            FormData.FormItem[] formItemArray = new FormData.FormItem[3];
            FormData.FormItem   formItem      = new FormData.FormItem();
            formItem.DisplayName = "AppId";
            formItem.Name        = "AppId";
            formItem.IsRequired  = true;
            formItem.Type        = FormData.FormItemType.text;
            formItem.Value       = config.AppId;
            formItemArray[0]     = formItem;
            FormData.FormItem formItem1 = new FormData.FormItem();
            formItem1.DisplayName = "AppKey";
            formItem1.Name        = "AppKey";
            formItem1.IsRequired  = true;
            formItem1.Type        = FormData.FormItemType.text;
            formItem1.Value       = config.AppKey;
            formItemArray[1]      = formItem1;
            FormData.FormItem formItem2 = new FormData.FormItem();
            formItem2.DisplayName = "验证内容";
            formItem2.Name        = "ValidateContent";
            formItem2.IsRequired  = true;
            formItem2.Type        = FormData.FormItemType.text;
            formItem2.Value       = config.ValidateContent;
            formItemArray[2]      = formItem2;
            formDatum.Items       = formItemArray;
            return(formDatum);
        }
コード例 #3
0
ファイル: Service.cs プロジェクト: Shikyoh/HSWB2B2C
        public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values)
        {
            KeyValuePair <string, string> keyValuePair = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "AppId");

            if (string.IsNullOrWhiteSpace(keyValuePair.Value))
            {
                throw new PluginException("AppId不能为空");
            }
            KeyValuePair <string, string> keyValuePair1 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "AppKey");

            if (string.IsNullOrWhiteSpace(keyValuePair1.Value))
            {
                throw new PluginException("AppKey不能为空");
            }
            KeyValuePair <string, string> keyValuePair2 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "ValidateContent");

            if (!string.IsNullOrWhiteSpace(keyValuePair2.Value))
            {
                string lower = keyValuePair2.Value.ToLower();
                if (!lower.StartsWith("<meta "))
                {
                    throw new PluginException("验证内容必须以meta标签开头");
                }
                if (!lower.EndsWith(" />"))
                {
                    throw new PluginException("验证内容必须以 /> 结尾");
                }
            }
            OAuthQQConfig config = QQCore.GetConfig();

            config.AppId           = keyValuePair.Value;
            config.AppKey          = keyValuePair1.Value;
            config.ValidateContent = keyValuePair2.Value;
            QQCore.SaveConfig(config);
        }
コード例 #4
0
ファイル: Service.cs プロジェクト: Shikyoh/HSWB2B2C
        public void CheckCanEnable()
        {
            OAuthQQConfig config = QQCore.GetConfig();

            if (string.IsNullOrWhiteSpace(config.AppId))
            {
                throw new PluginConfigException("未设置AppId");
            }
            if (string.IsNullOrWhiteSpace(config.AppKey))
            {
                throw new PluginConfigException("未设置AppKey");
            }
            if (string.IsNullOrWhiteSpace(config.AuthorizeURL))
            {
                throw new PluginConfigException("未设置授权地址(AuthorizeURL)");
            }
        }
コード例 #5
0
ファイル: Service.cs プロジェクト: Shikyoh/HSWB2B2C
        public string GetOpenLoginUrl(string returnUrl)
        {
            Service.ReturnUrl = returnUrl;
            OAuthQQConfig config = QQCore.GetConfig();

            if (string.IsNullOrWhiteSpace(config.AppId))
            {
                throw new MissingFieldException("未配置AppId");
            }
            if (string.IsNullOrWhiteSpace(config.AppKey))
            {
                throw new MissingFieldException("未配置AppKey");
            }
            string str  = "test";
            string str1 = "get_user_info";
            string str2 = string.Concat(config.AuthorizeURL, "?response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}");

            object[] appId = new object[] { config.AppId, returnUrl, str1, str };
            return(string.Format(str2, appId));
        }
コード例 #6
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);
        }
コード例 #7
0
        public Core.Plugins.FormData GetFormData()
        {
            var config = QQCore.GetConfig();

            var formData = new Core.Plugins.FormData()
            {
                Items = new Core.Plugins.FormData.FormItem[] {
                    //AppId
                    new  Core.Plugins.FormData.FormItem()
                    {
                        DisplayName = "AppId",
                        Name        = "AppId",
                        IsRequired  = true,
                        Type        = Core.Plugins.FormData.FormItemType.text,
                        Value       = config.AppId
                    },

                    //AppKey
                    new  Core.Plugins.FormData.FormItem()
                    {
                        DisplayName = "AppKey",
                        Name        = "AppKey",
                        IsRequired  = true,
                        Type        = Core.Plugins.FormData.FormItemType.text,
                        Value       = config.AppKey
                    },
                    //验证内容
                    new  Core.Plugins.FormData.FormItem()
                    {
                        DisplayName = "验证内容",
                        Name        = "ValidateContent",
                        IsRequired  = true,
                        Type        = Core.Plugins.FormData.FormItemType.text,
                        Value       = config.ValidateContent
                    }
                }
            };

            return(formData);
        }
コード例 #8
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);
        }
コード例 #9
0
ファイル: Service.cs プロジェクト: Shikyoh/HSWB2B2C
        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);
        }
コード例 #10
0
ファイル: Service.cs プロジェクト: Shikyoh/HSWB2B2C
 public string GetValidateContent()
 {
     return(QQCore.GetConfig().ValidateContent);
 }
コード例 #11
0
        public string GetValidateContent()
        {
            OAuthQQConfig config = QQCore.GetConfig();

            return(config.ValidateContent);
        }