|
@@ -3,6 +3,9 @@ package com.ym.mec.student.controller;
|
|
|
import com.google.code.kaptcha.Constants;
|
|
|
import com.google.code.kaptcha.Producer;
|
|
|
import com.google.code.kaptcha.servlet.KaptchaServlet;
|
|
|
+import com.wf.captcha.GifCaptcha;
|
|
|
+import com.wf.captcha.SpecCaptcha;
|
|
|
+import com.wf.captcha.utils.CaptchaUtil;
|
|
|
import com.ym.mec.biz.dal.entity.CourseSchedule;
|
|
|
import com.ym.mec.biz.service.SmsCodeService;
|
|
|
import com.ym.mec.common.controller.BaseController;
|
|
@@ -22,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -77,38 +81,50 @@ public class SmsCodeController extends BaseController {
|
|
|
return failed(SecurityConstants.VERIFY_FAILURE);
|
|
|
}
|
|
|
|
|
|
- @GetMapping(value = "/getLoginImage")
|
|
|
+ @RequestMapping("/getLoginImage")
|
|
|
@ApiOperation("获取登录图片验证码")
|
|
|
@ApiImplicitParam(name = "phone", value = "手机号", required = true, dataType = "String")
|
|
|
- public void getKaptchaImage(HttpServletResponse response,String phone) throws Exception {
|
|
|
+ public void getLoginImage(HttpServletRequest request, HttpServletResponse response,String phone) throws Exception {
|
|
|
if(StringUtils.isEmpty(phone)){
|
|
|
throw new BizException("请输入手机号");
|
|
|
}
|
|
|
- response.setDateHeader("Expires", 0);
|
|
|
-
|
|
|
-
|
|
|
- response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
|
|
|
-
|
|
|
- response.addHeader("Cache-Control", "post-check=0, pre-check=0");
|
|
|
-
|
|
|
- response.setHeader("Pragma", "no-cache");
|
|
|
-
|
|
|
- response.setContentType("image/jpeg");
|
|
|
-
|
|
|
- String capText = captchaProducer.createText();
|
|
|
-
|
|
|
- redisTemplate.opsForValue().set(Constants.KAPTCHA_SESSION_KEY + phone,capText,3, TimeUnit.MINUTES);
|
|
|
-
|
|
|
- BufferedImage bi = captchaProducer.createImage(capText);
|
|
|
- KaptchaServlet kaptchaServlet = new KaptchaServlet();
|
|
|
- kaptchaServlet.init();
|
|
|
- ServletOutputStream out = response.getOutputStream();
|
|
|
-
|
|
|
- try {
|
|
|
- ImageIO.write(bi, "jpg", out);
|
|
|
- out.flush();
|
|
|
- } finally {
|
|
|
- out.close();
|
|
|
- }
|
|
|
+ SpecCaptcha specCaptcha = new SpecCaptcha(125, 45, 5);
|
|
|
+ redisTemplate.opsForValue().set(Constants.KAPTCHA_SESSION_KEY + phone,specCaptcha.text(),3, TimeUnit.MINUTES);
|
|
|
+ CaptchaUtil.out(specCaptcha, request, response);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|