This commit is contained in:
linlinjava
2021-03-14 13:24:57 +08:00
parent ba439aa710
commit e9182f2c66

View File

@@ -25,7 +25,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import sun.misc.BASE64Encoder;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
@@ -75,10 +74,8 @@ public class AdminAuthController {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(image, "jpeg", outputStream);
BASE64Encoder encoder = new BASE64Encoder();
String base64 = encoder.encode(outputStream.toByteArray());
String captchaBase64 = "data:image/jpeg;base64," + base64.replaceAll("\r\n", "");
return captchaBase64;
String base64 = Base64.getEncoder().encodeToString(outputStream.toByteArray());
return "data:image/jpeg;base64," + base64.replaceAll("\r\n", "");
} catch (IOException e) {
return null;
}