namespace Yw.Application
|
{
|
/// <summary>
|
/// Tool
|
/// </summary>
|
[AllowAnonymous]
|
[Route("Auth/Tool")]
|
[ApiDescriptionSettings("Auth", Name = "权限工具", Order = 100000)]
|
public class Tool_Controller : IDynamicApiController, ITransient
|
{
|
private readonly ICaptcha _captcha;//验证码组件
|
|
/// <summary>
|
///
|
/// </summary>
|
public Tool_Controller(ICaptcha captcha)
|
{
|
_captcha = captcha;
|
}
|
|
|
|
/// <summary>
|
/// 获取图片验证码
|
/// </summary>
|
[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 };
|
}
|
|
/// <summary>
|
/// 验证图片验证码
|
/// </summary>
|
/// <param name="Id">验证码id</param>
|
/// <param name="Code">验证码</param>
|
/// <returns></returns>
|
[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;
|
}
|
|
}
|
}
|