namespace Yw.Application { /// /// Tool /// [AllowAnonymous] [Route("Auth/Tool")] [ApiDescriptionSettings("Auth", Name = "权限工具", Order = 100000)] public class Tool_Controller : IDynamicApiController, ITransient { private readonly ICaptcha _captcha;//验证码组件 /// /// /// public Tool_Controller(ICaptcha captcha) { _captcha = captcha; } /// /// 获取图片验证码 /// [Route("GetCaptcha@V1.0")] [HttpGet] public dynamic GetCaptcha() { var codeId = YitIdHelper.NextId(); var captcha = _captcha.Generate(codeId.ToString()); return new { Id = codeId, Img = captcha.Base64 }; } /// /// 验证图片验证码 /// /// 验证码id /// 验证码 /// [Route("VerifyCaptcha@V1.0")] [HttpGet] public bool VerifyCaptcha ( [Required] long Id, //验证码id [Required,DataValidation(AllowEmptyStrings = false)] string Code//验证码 ) { // 判断验证码 if (!_captcha.Validate(Id.ToString(), Code)) { return false; } return true; } } }