|
@@ -1,20 +1,13 @@
|
|
|
package com.huimv.manager.modular.controller;
|
|
|
|
|
|
-
|
|
|
-import com.huimv.manager.exception.RRException;
|
|
|
-import com.huimv.manager.util.VerifyUtil;
|
|
|
+import cn.dustlight.captcha.annotations.CodeValue;
|
|
|
+import cn.dustlight.captcha.annotations.SendCode;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-
|
|
|
/**
|
|
|
* <p>
|
|
|
* 验证码前端控制器
|
|
@@ -28,37 +21,9 @@ import java.util.concurrent.TimeUnit;
|
|
|
@Slf4j
|
|
|
public class CaptchaController {
|
|
|
|
|
|
- @Autowired
|
|
|
- private RedisTemplate<String, String> redisTemplate;
|
|
|
-
|
|
|
-// @GetMapping("/send")
|
|
|
-// @SendCode
|
|
|
- public void getCaptcha(HttpServletRequest request) {
|
|
|
-
|
|
|
-
|
|
|
-// log.info(code);
|
|
|
- String remoteHost = request.getRemoteHost();
|
|
|
- }
|
|
|
-
|
|
|
@GetMapping("/send")
|
|
|
- public void createImg(HttpServletRequest request, HttpServletResponse response) {
|
|
|
- try {
|
|
|
- //设置响应类型,告诉浏览器输出的内容为图片
|
|
|
- response.setContentType("image/jpeg");
|
|
|
- //设置响应头信息,告诉浏览器不要缓存此内容
|
|
|
- response.setHeader("Pragma", "No-cache");
|
|
|
- response.setHeader("Cache-Control", "no-cache");
|
|
|
- response.setDateHeader("Expire", 0);
|
|
|
- VerifyUtil randomValidateCode = new VerifyUtil();
|
|
|
- //输出验证码图片
|
|
|
- String code = randomValidateCode.getRandcode(request, response);
|
|
|
- log.info(code);
|
|
|
- //将生成的随机验证码存放到redis中
|
|
|
- String remoteHost = request.getRemoteHost();
|
|
|
- redisTemplate.opsForValue().set(remoteHost,code,300, TimeUnit.SECONDS);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("获取验证码异常:",e);
|
|
|
- throw new RRException("获取验证码失败!");
|
|
|
- }
|
|
|
+ @SendCode()
|
|
|
+ public void getCaptcha(@CodeValue String code){
|
|
|
+ log.info(code);
|
|
|
}
|
|
|
}
|