From 10d7b3239e4baec952b9ee8a3e948399916d336c Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期一, 20 十月 2025 08:23:58 +0800
Subject: [PATCH] 13
---
src/main/java/com/zy/common/utils/RandomValidateCodeUtil.java | 22 ++++++++++++++++++++--
1 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/main/java/com/zy/common/utils/RandomValidateCodeUtil.java b/src/main/java/com/zy/common/utils/RandomValidateCodeUtil.java
index 87ff1d5..ab4269c 100644
--- a/src/main/java/com/zy/common/utils/RandomValidateCodeUtil.java
+++ b/src/main/java/com/zy/common/utils/RandomValidateCodeUtil.java
@@ -11,7 +11,7 @@
public class RandomValidateCodeUtil {
public static final Map<String, String> code = new ConcurrentHashMap<>();
-
+
private static String randString = "0123456789ABCDEFGHJKLMNPRSTUVWXYZ";//闅忔満浜х敓鏁板瓧涓庡瓧姣嶇粍鍚堢殑瀛楃涓�
private static int width = 60;// 鍥剧墖瀹�
private static int height = 27;// 鍥剧墖楂�
@@ -39,6 +39,24 @@
int g = fc + random.nextInt(bc - fc - 14);
int b = fc + random.nextInt(bc - fc - 18);
return new Color(r, g, b);
+ }
+
+ public static void init() {
+ BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
+ Graphics g = image.getGraphics();// 浜х敓Image瀵硅薄鐨凣raphics瀵硅薄,鏀瑰璞″彲浠ュ湪鍥惧儚涓婅繘琛屽悇绉嶇粯鍒舵搷浣�
+ g.fillRect(0, 0, width, height);//鍥剧墖澶у皬
+ g.setFont(new Font("Times New Roman", Font.PLAIN, 18));//瀛椾綋澶у皬
+ g.setColor(getRandColor(110, 133));//瀛椾綋棰滆壊
+ // 缁樺埗骞叉壈绾�
+ for (int i = 0; i <= lineSize; i++) {
+ drowLine(g);
+ }
+ // 缁樺埗闅忔満瀛楃
+ String randomString = "";
+ for (int i = 1; i <= stringNum; i++) {
+ randomString = drowString(g, randomString, i);
+ }
+ g.dispose();
}
/**
@@ -79,7 +97,7 @@
.length())));
randomString += rand;
g.translate(random.nextInt(3), random.nextInt(3));
- g.drawString(rand, 13 * (i-1)+2, 16);
+ g.drawString(rand, 13 * (i - 1) + 2, 16);
return randomString;
}
--
Gitblit v1.9.1