|
@@ -1,6 +1,7 @@
|
|
|
package cn.com.qmth.examcloud.core.basic.base.util;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import org.springframework.util.Base64Utils;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
import javax.script.ScriptEngine;
|
|
@@ -8,6 +9,7 @@ import javax.script.ScriptEngineManager;
|
|
|
import java.awt.*;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.io.Serializable;
|
|
|
import java.util.Random;
|
|
@@ -44,17 +46,15 @@ public class VerifyCode {
|
|
|
}
|
|
|
|
|
|
// 随机生成三个数字、并组合成一个数学公式
|
|
|
-// String verifyCode = new StringBuilder()
|
|
|
-// .append(random.nextInt(10))
|
|
|
-// .append(OPS[random.nextInt(2)])
|
|
|
-// .append(random.nextInt(10))
|
|
|
-// .append(OPS[random.nextInt(2)])
|
|
|
-// .append(random.nextInt(10))
|
|
|
-// .append(OPS[random.nextInt(2)])
|
|
|
-// .append(random.nextInt(10))
|
|
|
-// .toString();
|
|
|
-
|
|
|
- String verifyCode = "1+2+3+4";
|
|
|
+ String verifyCode = new StringBuilder()
|
|
|
+ .append(random.nextInt(10))
|
|
|
+ .append(OPS[random.nextInt(2)])
|
|
|
+ .append(random.nextInt(10))
|
|
|
+ .append(OPS[random.nextInt(2)])
|
|
|
+ .append(random.nextInt(10))
|
|
|
+ .append(OPS[random.nextInt(2)])
|
|
|
+ .append(random.nextInt(10))
|
|
|
+ .toString();
|
|
|
|
|
|
graphics.setColor(new Color(0, 0, 255));
|
|
|
graphics.setFont(new Font("Candara", Font.BOLD, 22));
|
|
@@ -118,4 +118,21 @@ public class VerifyCode {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /*public static void main(String[] args) throws Exception {
|
|
|
+ final String dir = "/home/verifyCodes";
|
|
|
+ new File(dir).mkdirs();
|
|
|
+
|
|
|
+ for (int n = 1; n <= 1; n++) {
|
|
|
+ Result result = VerifyCode.generateVerifyCode();
|
|
|
+
|
|
|
+ final String imgPath = String.format("Img_%s.jpg", n);
|
|
|
+ File imgFile = new File(dir + "/" + imgPath);
|
|
|
+ ImageIO.write(result.getImage(), "JPEG", imgFile);
|
|
|
+
|
|
|
+ byte[] bytes = imageToBytes(result.getImage());
|
|
|
+ String base64 = Base64Utils.encodeToString(bytes);
|
|
|
+ System.out.println(base64);
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
}
|