| | |
| | | import com.wf.captcha.base.Captcha; |
| | | import com.wf.captcha.utils.CaptchaUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | |
| | | * |
| | | * @throws Exception |
| | | */ |
| | | @GetMapping(SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{deviceId}") |
| | | @GetMapping(value=SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{deviceId}",produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) |
| | | public void createCode(@PathVariable String deviceId, HttpServletResponse response) throws Exception { |
| | | Assert.notNull(deviceId, "机器码不能为空"); |
| | | // 设置请求头为输出图片类型 |
| | | CaptchaUtil.setHeader(response); |
| | | // 三个参数分别为宽、高、位数 |
| | | // GifCaptcha gifCaptcha = new GifCaptcha(100, 35, 4,new Font("actionj", 1, 32)); |
| | | GifCaptcha gifCaptcha = new GifCaptcha(100, 35, 4); |
| | | // gifCaptcha.setFont(Captcha.FONT_1); |
| | | // 设置类型:字母数字混合 |
| | | gifCaptcha.setCharType(Captcha.TYPE_DEFAULT); |
| | | // 保存验证码 |