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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public string GetValidateContent() { return(WeiboCore.GetConfig().ValidateContent); }
public string GetValidateContent() { var oldConfig = WeiboCore.GetConfig(); return(oldConfig.ValidateContent); }