mirror of https://github.com/elunez/eladmin
修复算术类型验证码在 Java 15+ 的兼容问题 (#607)
(cherry picked from commit cdbc3a8faaf5958489758608329aa70095b37bb3)pull/608/head^2
parent
01d1aa9721
commit
a49bd6d127
|
@ -80,7 +80,7 @@ public class LoginProperties {
|
|||
switch (loginCode.getCodeType()) {
|
||||
case arithmetic:
|
||||
// 算术类型 https://gitee.com/whvse/EasyCaptcha
|
||||
captcha = new ArithmeticCaptcha(loginCode.getWidth(), loginCode.getHeight());
|
||||
captcha = new FixedArithmeticCaptcha(loginCode.getWidth(), loginCode.getHeight());
|
||||
// 几位数运算,默认是两位
|
||||
captcha.setLen(loginCode.getLength());
|
||||
break;
|
||||
|
@ -109,4 +109,27 @@ public class LoginProperties {
|
|||
}
|
||||
return captcha;
|
||||
}
|
||||
|
||||
static class FixedArithmeticCaptcha extends ArithmeticCaptcha {
|
||||
public FixedArithmeticCaptcha(int width, int height) {
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected char[] alphas() {
|
||||
// 生成随机数字和运算符
|
||||
int n1 = num(1, 10), n2 = num(1, 10);
|
||||
int opt = num(3);
|
||||
|
||||
// 计算结果
|
||||
int res = new int[]{n1 + n2, n1 - n2, n1 * n2}[opt];
|
||||
// 转换为字符运算符
|
||||
char optChar = "+-x".charAt(opt);
|
||||
|
||||
this.setArithmeticString(String.format("%s%c%s=?", n1, optChar, n2));
|
||||
this.chars = String.valueOf(res);
|
||||
|
||||
return chars.toCharArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue