Example #1
0
        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);
        }
Example #2
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);
        }