Bläddra i källkod

update VerifyCode

deason 5 år sedan
förälder
incheckning
5399d05b17

+ 11 - 9
examcloud-core-basic-base/src/main/java/cn/com/qmth/examcloud/core/basic/base/util/VerifyCode.java

@@ -17,14 +17,14 @@ import java.util.Random;
  */
 public class VerifyCode {
 
-    private static final char[] OPS = new char[]{'+', '-', '*'};
+    private static final char[] OPS = new char[]{'+', '-'};
 
     /**
      * 生成验证码图片
      */
     public static Result generateVerifyCode() {
-        int width = 80;
-        int height = 32;
+        int width = 100;
+        int height = 40;
 
         BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
 
@@ -37,7 +37,7 @@ public class VerifyCode {
 
         // 生成N个干扰点
         Random random = new Random();
-        for (int i = 0; i < 50; i++) {
+        for (int i = 0; i < 500; i++) {
             int x = random.nextInt(width);
             int y = random.nextInt(height);
             graphics.drawOval(x, y, 0, 0);
@@ -46,15 +46,17 @@ public class VerifyCode {
         // 随机生成三个数字、并组合成一个数学公式
         String verifyCode = new StringBuilder()
                 .append(random.nextInt(10))
-                .append(OPS[random.nextInt(3)])
+                .append(OPS[random.nextInt(2)])
                 .append(random.nextInt(10))
-                .append(OPS[random.nextInt(3)])
+                .append(OPS[random.nextInt(2)])
+                .append(random.nextInt(10))
+                .append(OPS[random.nextInt(2)])
                 .append(random.nextInt(10))
                 .toString();
 
-        graphics.setColor(new Color(0, 100, 0));
-        graphics.setFont(new Font("Candara", Font.BOLD, 24));
-        graphics.drawString(verifyCode, 8, 24);
+        graphics.setColor(new Color(0, 0, 255));
+        graphics.setFont(new Font("Candara", Font.BOLD, 22));
+        graphics.drawString(verifyCode, 15, 24);
         graphics.dispose();
 
         Integer result;