|
|
@ -1,12 +1,14 @@ |
|
|
|
package com.jiagutech.ams.controller; |
|
|
|
|
|
|
|
import cn.hutool.captcha.CaptchaUtil; |
|
|
|
import cn.hutool.captcha.ShearCaptcha; |
|
|
|
import cn.hutool.captcha.LineCaptcha; |
|
|
|
import cn.hutool.core.img.ImgUtil; |
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
import cn.hutool.core.util.RandomUtil; |
|
|
|
import com.jiagutech.ams.constant.Constants; |
|
|
|
import com.jiagutech.ams.constant.GlobalConstants; |
|
|
|
import com.jiagutech.ams.model.response.CaptchaVO; |
|
|
|
import com.jiagutech.ams.model.common.R; |
|
|
|
import com.jiagutech.ams.model.response.CaptchaVO; |
|
|
|
import io.swagger.v3.oas.annotations.Operation; |
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
@ -15,6 +17,7 @@ import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
import java.time.Duration; |
|
|
|
|
|
|
|
/** |
|
|
@ -39,13 +42,13 @@ public class CommonController { |
|
|
|
String uuid = IdUtil.simpleUUID(); |
|
|
|
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + uuid; |
|
|
|
|
|
|
|
ShearCaptcha shearCaptcha = CaptchaUtil.createShearCaptcha(150, 40, 5, 4); |
|
|
|
|
|
|
|
String code = shearCaptcha.getCode(); |
|
|
|
|
|
|
|
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(150, 40, 4, 50); |
|
|
|
String code = RandomUtil.randomNumbers(4); |
|
|
|
Image image = lineCaptcha.createImage(code); |
|
|
|
String base64 = ImgUtil.toBase64(image, "jpg"); |
|
|
|
redisTemplate.opsForValue().set(verifyKey, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION)); |
|
|
|
captchaVo.setUuid(uuid); |
|
|
|
captchaVo.setImg(shearCaptcha.getImageBase64()); |
|
|
|
captchaVo.setImg(base64); |
|
|
|
return R.ok(captchaVo); |
|
|
|
} |
|
|
|
} |
|
|
|