|
|
@@ -1,7 +1,7 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
import com.izouma.nineth.dto.Captcha;
|
|
|
-import com.wf.captcha.SpecCaptcha;
|
|
|
+import com.pig4cloud.captcha.ArithmeticCaptcha;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.ehcache.UserManagedCache;
|
|
|
@@ -24,10 +24,20 @@ public class CaptchaService {
|
|
|
|
|
|
public Captcha gen() throws IOException, FontFormatException {
|
|
|
String key = UUID.randomUUID().toString();
|
|
|
- SpecCaptcha specCaptcha = new SpecCaptcha(90 * 2, 32 * 2, 5);
|
|
|
- specCaptcha.setFont(com.wf.captcha.base.Captcha.FONT_7, 24 * 2);
|
|
|
- String code = specCaptcha.text().toLowerCase();
|
|
|
- String image = specCaptcha.toBase64();
|
|
|
+// SpecCaptcha specCaptcha = new SpecCaptcha(90 * 2, 32 * 2, 5);
|
|
|
+// specCaptcha.setFont(com.wf.captcha.base.Captcha.FONT_7, 24 * 2);
|
|
|
+// String code = specCaptcha.text().toLowerCase();
|
|
|
+// String image = specCaptcha.toBase64();
|
|
|
+// captchaCache.put(key, code);
|
|
|
+
|
|
|
+ // 算术类型
|
|
|
+ ArithmeticCaptcha captcha = new ArithmeticCaptcha(130, 48);
|
|
|
+ captcha.setLen(3); // 几位数运算,默认是两位
|
|
|
+ captcha.getArithmeticString(); // 获取运算的公式:3+2=?
|
|
|
+ captcha.supportAlgorithmSign(2); // 可设置支持的算法:2 表示只生成带加减法的公式
|
|
|
+ captcha.setDifficulty(50); // 设置计算难度,参与计算的每一个整数的最大值
|
|
|
+ String code = captcha.text(); // 获取运算的结果:5
|
|
|
+ String image = captcha.toBase64(); // 输出验证码
|
|
|
captchaCache.put(key, code);
|
|
|
return new Captcha(key, image);
|
|
|
}
|