Exemple #1
0
        public FormData GetFormData()
        {
            OAuthWeiboConfig config    = WeiboCore.GetConfig();
            FormData         formDatum = new FormData();

            FormData.FormItem[] formItemArray = new FormData.FormItem[3];
            FormData.FormItem   formItem      = new FormData.FormItem();
            formItem.DisplayName = "AppKey";
            formItem.Name        = "AppKey";
            formItem.IsRequired  = true;
            formItem.Type        = FormData.FormItemType.text;
            formItem.Value       = config.AppKey;
            formItemArray[0]     = formItem;
            FormData.FormItem formItem1 = new FormData.FormItem();
            formItem1.DisplayName = "AppSecret";
            formItem1.Name        = "AppSecret";
            formItem1.IsRequired  = true;
            formItem1.Type        = FormData.FormItemType.text;
            formItem1.Value       = config.AppSecret;
            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);
        }
Exemple #2
0
        public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values)
        {
            KeyValuePair <string, string> keyValuePair = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "AppKey");

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

            if (string.IsNullOrWhiteSpace(keyValuePair1.Value))
            {
                throw new ArgumentNullException("AppSecret不能为空");
            }
            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("验证内容必须以 /> 结尾");
                }
            }
            OAuthWeiboConfig config = WeiboCore.GetConfig();

            config.AppSecret       = keyValuePair1.Value;
            config.AppKey          = keyValuePair.Value;
            config.ValidateContent = keyValuePair2.Value;
            WeiboCore.SaveConfig(config);
        }
Exemple #3
0
        public string GetOpenLoginUrl(string returnUrl)
        {
            Service.ReturnUrl = returnUrl;
            OAuthWeiboConfig config = WeiboCore.GetConfig();
            string           str    = string.Format(string.Concat(config.AuthorizeURL, "?client_id={0}&response_type=code&redirect_uri={1}"), config.AppKey, returnUrl);

            return(str);
        }
Exemple #4
0
        public string GetOpenLoginUrl(string returnUrl)
        {
            ReturnUrl = returnUrl;
            var    config = WeiboCore.GetConfig();
            string url    = string.Format(config.AuthorizeURL + "?client_id={0}&response_type=code&redirect_uri={1}", config.AppKey, returnUrl);

            return(url);
        }
Exemple #5
0
        public OAuthUserInfo GetUserInfo(System.Collections.Specialized.NameValueCollection queryString)
        {
            var config = WeiboCore.GetConfig();
            var oatuth = new NetDimension.Weibo.OAuth(config.AppKey, config.AppSecret, ReturnUrl);

            NetDimension.Weibo.Client client = new NetDimension.Weibo.Client(oatuth);
            var code        = queryString["code"];
            var accessToken = oatuth.GetAccessTokenByAuthorizationCode(code);

            OAuthUserInfo userInfo = null;

            if (oatuth != null)
            {
                userInfo        = new OAuthUserInfo();
                userInfo.OpenId = client.API.Entity.Account.GetUID();
                var user = client.API.Entity.Users.Show(userInfo.OpenId);
                userInfo.NickName = userInfo.RealName = user.Name;
                userInfo.IsMale   = user.Gender == "m";
            }
            return(userInfo);
        }
Exemple #6
0
        public Core.Plugins.FormData GetFormData()
        {
            var config = WeiboCore.GetConfig();

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

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

            return(formData);
        }
Exemple #7
0
        public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values)
        {
            var appKeyItem = values.FirstOrDefault(item => item.Key == "AppKey");

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

            var appidItem = values.FirstOrDefault(item => item.Key == "AppSecret");

            if (string.IsNullOrWhiteSpace(appidItem.Value))
            {
                throw new Himall.Core.PluginConfigException("AppSecret不能为空");
            }

            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("验证内容必须以 /> 结尾");
                }
            }

            var oldConfig = WeiboCore.GetConfig();

            oldConfig.AppSecret       = appidItem.Value;
            oldConfig.AppKey          = appKeyItem.Value;
            oldConfig.ValidateContent = validateContent.Value;
            WeiboCore.SaveConfig(oldConfig);
        }
Exemple #8
0
        public OAuthUserInfo GetUserInfo(NameValueCollection queryString)
        {
            OAuthWeiboConfig config = WeiboCore.GetConfig();

            NetDimension.Weibo.OAuth oAuth = new NetDimension.Weibo.OAuth(config.AppKey, config.AppSecret, Service.ReturnUrl);
            Client client = new Client(oAuth);

            oAuth.GetAccessTokenByAuthorizationCode(queryString["code"]);
            OAuthUserInfo oAuthUserInfo = null;

            if (oAuth != null)
            {
                oAuthUserInfo        = new OAuthUserInfo();
                oAuthUserInfo.OpenId = client.API.Entity.Account.GetUID();
                Entity entity = client.API.Entity.Users.Show(oAuthUserInfo.OpenId, "");
                string name   = entity.Name;
                string str    = name;
                oAuthUserInfo.RealName = name;
                oAuthUserInfo.NickName = str;
                oAuthUserInfo.IsMale   = new bool?(entity.Gender == "m");
            }
            return(oAuthUserInfo);
        }
Exemple #9
0
 public string GetValidateContent()
 {
     return(WeiboCore.GetConfig().ValidateContent);
 }
Exemple #10
0
        public string GetValidateContent()
        {
            var oldConfig = WeiboCore.GetConfig();

            return(oldConfig.ValidateContent);
        }