gaodm 6 年之前
父節點
當前提交
6c83c77a35
共有 1 個文件被更改,包括 6 次插入5 次删除
  1. 6 5
      user-service/src/main/java/com/diagbot/util/VerifyCodeUtils.java

+ 6 - 5
user-service/src/main/java/com/diagbot/util/VerifyCodeUtils.java

@@ -21,7 +21,7 @@ import java.util.Random;
  * @time: 2018/9/4 13:54
  */
 public class VerifyCodeUtils {
-    //使用到Algerian字体,系统里没有的话需要安装字体,字体只显示大写,去掉了1,0,i,o几个容易混淆的字符
+    //字体只显示大写,去掉了1,0,i,o几个容易混淆的字符
     public static final String VERIFY_CODES = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
     private static Random random = new Random();
 
@@ -141,7 +141,7 @@ public class VerifyCodeUtils {
         g2.setColor(c);// 设置背景色
         g2.fillRect(0, 2, w, h-4);
 
-        //绘制干扰线
+        //1.绘制干扰线
         Random random = new Random();
         g2.setColor(getRandColor(160, 200));// 设置线条的颜色
         for (int i = 0; i < 20; i++) {
@@ -152,7 +152,7 @@ public class VerifyCodeUtils {
             g2.drawLine(x, y, x + xl + 40, y + yl + 20);
         }
 
-        // 添加噪点
+        //2.添加噪点
         float yawpRate = 0.05f;// 噪声率
         int area = (int) (yawpRate * w * h);
         for (int i = 0; i < area; i++) {
@@ -171,8 +171,9 @@ public class VerifyCodeUtils {
         char[] chars = code.toCharArray();
         for(int i = 0; i < verifySize; i++){
             AffineTransform affine = new AffineTransform();
-            affine.setToRotation(Math.PI / 4 * rand.nextDouble() * (rand.nextBoolean() ? 1 : -1), (w / verifySize) * i + fontSize/2, h/2);
+            affine.setToRotation(Math.PI / 4 * rand.nextDouble() * (rand.nextBoolean() ? 1 : -1), (w / verifySize) * i + (h - 4) /2, h/2);
             g2.setTransform(affine);
+            g2.drawOval(random.nextInt(w), random.nextInt(h), 5 + random.nextInt(10), 5 + random.nextInt(10));
             g2.drawChars(chars, i, 1, ((w-10) / verifySize) * i + 5, h/2 + fontSize/2 - 10);
         }
 
@@ -266,7 +267,7 @@ public class VerifyCodeUtils {
      */
     public static Object[] createImage(){
         try{
-            int w = 80, h = 32;
+            int w = 125, h = 34;
             String verifyCode = generateVerifyCode(4);//生成四位随机码
             ByteArrayOutputStream bos = new ByteArrayOutputStream();
             outputImage(w, h, bos, verifyCode);