public IHttpActionResult Check(string name, [FromBody] CaptchaInfo captchaInfo)
        {
            try
            {
                var code = CookieUtils.GetCookie("SS-" + name);

                if (string.IsNullOrEmpty(code) || CacheUtils.Exists($"SiteServer.API.Controllers.V1.CaptchaController.{code}"))
                {
                    return(BadRequest("验证码已超时,请点击刷新验证码!"));
                }

                CookieUtils.Erase("SS-" + name);
                CacheUtils.InsertMinutes($"SiteServer.API.Controllers.V1.CaptchaController.{code}", true, 10);

                if (!StringUtils.EqualsIgnoreCase(code, captchaInfo.Captcha))
                {
                    return(BadRequest("验证码不正确,请重新输入!"));
                }

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Check([FromBody] CheckRequest request)
        {
            try
            {
                var code = CookieUtils.GetCookie(CookieName);

                if (string.IsNullOrEmpty(code) || CacheUtils.Exists($"{CookieName}.{code}"))
                {
                    return(BadRequest("验证码已超时,请点击刷新验证码!"));
                }

                CookieUtils.Erase(CookieName);
                CacheUtils.InsertMinutes($"{CookieName}.{code}", true, 10);

                if (!StringUtils.EqualsIgnoreCase(code, request.Captcha))
                {
                    return(BadRequest("验证码不正确,请重新输入!"));
                }

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public void Get(string name)
        {
            var response = HttpContext.Current.Response;

            var code = VcManager.CreateValidateCode();

            if (CacheUtils.Exists($"SiteServer.API.Controllers.V1.CaptchaController.{code}"))
            {
                code = VcManager.CreateValidateCode();
            }

            CookieUtils.SetCookie("SS-" + name, code, DateTime.Now.AddMinutes(10));

            response.BufferOutput = true;                                //特别注意
            response.Cache.SetExpires(DateTime.Now.AddMilliseconds(-1)); //特别注意
            response.Cache.SetCacheability(HttpCacheability.NoCache);    //特别注意
            response.AppendHeader("Pragma", "No-Cache");                 //特别注意
            response.ContentType = "image/png";

            var validateimage = new Bitmap(130, 53, PixelFormat.Format32bppRgb);

            var r      = new Random();
            var colors = Colors[r.Next(0, 5)];

            var g = Graphics.FromImage(validateimage);

            g.FillRectangle(new SolidBrush(Color.FromArgb(240, 243, 248)), 0, 0, 200, 200);                                                          //矩形框
            g.DrawString(code, new Font(FontFamily.GenericSerif, 28, FontStyle.Bold | FontStyle.Italic), new SolidBrush(colors), new PointF(14, 3)); //字体/颜色

            var random = new Random();

            for (var i = 0; i < 25; i++)
            {
                var x1 = random.Next(validateimage.Width);
                var x2 = random.Next(validateimage.Width);
                var y1 = random.Next(validateimage.Height);
                var y2 = random.Next(validateimage.Height);

                g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
            }

            for (var i = 0; i < 100; i++)
            {
                var x = random.Next(validateimage.Width);
                var y = random.Next(validateimage.Height);

                validateimage.SetPixel(x, y, Color.FromArgb(random.Next()));
            }

            g.Save();
            var ms = new MemoryStream();

            validateimage.Save(ms, ImageFormat.Png);
            response.ClearContent();
            response.BinaryWrite(ms.ToArray());
            response.End();
        }
        public IHttpActionResult Insert()
        {
            try
            {
                var request = Context.AuthenticatedRequest;
                var siteId  = request.GetPostInt("siteId");
                if (!request.IsAdminLoggin)
                {
                    return(Unauthorized());
                }

                var authCode = request.GetPostString("authCode");
                var code     = CookieUtils.GetCookie(CaptchaController.CookieName);
                if (string.IsNullOrEmpty(code) || CacheUtils.Exists($"{CaptchaController.CookieName}.{code}"))
                {
                    return(BadRequest("验证码已超时,请点击刷新验证码!"));
                }
                CookieUtils.Erase(CaptchaController.CookieName);
                CacheUtils.InsertMinutes($"{CaptchaController.CookieName}.{code}", true, 10);
                if (!StringUtils.EqualsIgnoreCase(code, authCode))
                {
                    return(BadRequest("验证码不正确,请重新输入!"));
                }

                var categoryId     = request.GetPostInt("categoryId");
                var departmentId   = request.GetPostInt("departmentId");
                var categoryInfo   = CategoryManager.GetCategoryInfo(siteId, categoryId);
                var departmentInfo = DepartmentManager.GetDepartmentInfo(siteId, departmentId);

                var dataInfo = new DataInfo
                {
                    Id             = 0,
                    SiteId         = siteId,
                    AddDate        = DateTime.Now,
                    QueryCode      = StringUtils.GetShortGuid(true),
                    CategoryId     = categoryInfo?.Id ?? 0,
                    DepartmentId   = departmentInfo?.Id ?? 0,
                    IsCompleted    = false,
                    State          = DataState.New.Value,
                    DenyReason     = string.Empty,
                    RedoComment    = string.Empty,
                    ReplyContent   = string.Empty,
                    IsReplyFiles   = false,
                    ReplyDate      = DateTime.Now,
                    Name           = request.GetPostString("name"),
                    Gender         = request.GetPostString("gender"),
                    Phone          = request.GetPostString("phone"),
                    Email          = request.GetPostString("email"),
                    Address        = request.GetPostString("address"),
                    Zip            = request.GetPostString("zip"),
                    Title          = request.GetPostString("title"),
                    Content        = request.GetPostString("content"),
                    CategoryName   = categoryInfo == null ? string.Empty : categoryInfo.CategoryName,
                    DepartmentName = departmentInfo == null ? string.Empty : departmentInfo.DepartmentName
                };

                Main.DataRepository.Insert(dataInfo);

                return(Ok(new
                {
                    Value = dataInfo
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }