예제 #1
0
        public string Validate(string captcha, string ipAddress)
        {
            if (string.IsNullOrEmpty(captcha))
            {
                return("验证码为空。");
            }

            try
            {
                JObject jObject;
                using (var response = HttpRequestHelper.CreatePostResponse(
                           "https://www.recaptcha.net/recaptcha/api/siteverify", new Dictionary <string, string>
                {
                    { "secret", _options.SecretKey },
                    { "response", captcha },
                    { "remoteip", ipAddress }
                }))
                {
                    jObject = (JObject)HttpRequestHelper.GetObjectFromJsonResponse(response);
                }

                return(jObject.GetValue("success").Value <bool>()
                    ? null
                    : "人机验证时发生错误:" + string.Join(",", jObject["error-codes"].ToList()));
            }
            catch (Exception ex)
            {
                return("人机验证时发生错误:" + ex.Message);
            }
        }