Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dsk-operate-sys-cscec
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fulixin
dsk-operate-sys-cscec
Commits
c58d2c8d
Commit
c58d2c8d
authored
Jul 14, 2023
by
danfuman
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev20230707' of
http://192.168.60.201/root/dsk-operate-sys
into dev20230707
parents
9dcddaf0
c7b5f678
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
2 deletions
+47
-2
CaptchaController.java
...java/com/dsk/web/controller/common/CaptchaController.java
+46
-1
application-dev.yml
dsk-admin/src/main/resources/application-dev.yml
+1
-1
No files found.
dsk-admin/src/main/java/com/dsk/web/controller/common/CaptchaController.java
View file @
c58d2c8d
package
com
.
dsk
.
web
.
controller
.
common
;
package
com
.
dsk
.
web
.
controller
.
common
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.awt.image.BufferedImage
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
@@ -72,7 +73,8 @@ public class CaptchaController
...
@@ -72,7 +73,8 @@ public class CaptchaController
else
if
(
"char"
.
equals
(
captchaType
))
else
if
(
"char"
.
equals
(
captchaType
))
{
{
capStr
=
code
=
captchaProducer
.
createText
();
capStr
=
code
=
captchaProducer
.
createText
();
image
=
captchaProducer
.
createImage
(
capStr
);
// image = captchaProducer.createImage(capStr);
image
=
captchaImage
(
capStr
);
}
}
redisCache
.
setCacheObject
(
verifyKey
,
code
,
Constants
.
CAPTCHA_EXPIRATION
,
TimeUnit
.
MINUTES
);
redisCache
.
setCacheObject
(
verifyKey
,
code
,
Constants
.
CAPTCHA_EXPIRATION
,
TimeUnit
.
MINUTES
);
...
@@ -91,4 +93,47 @@ public class CaptchaController
...
@@ -91,4 +93,47 @@ public class CaptchaController
ajax
.
put
(
"img"
,
Base64
.
encode
(
os
.
toByteArray
()));
ajax
.
put
(
"img"
,
Base64
.
encode
(
os
.
toByteArray
()));
return
ajax
;
return
ajax
;
}
}
private
static
final
int
WIDTH
=
120
;
// 图片宽度
private
static
final
int
HEIGHT
=
40
;
// 图片高度
private
static
final
int
CODE_LENGTH
=
4
;
// 验证码长度
private
BufferedImage
captchaImage
(
String
capStr
)
{
// 创建图片缓冲区
BufferedImage
image
=
new
BufferedImage
(
WIDTH
,
HEIGHT
,
BufferedImage
.
TYPE_INT_RGB
);
// 获取画笔
Graphics
graphics
=
image
.
getGraphics
();
// 绘制背景
graphics
.
setColor
(
Color
.
WHITE
);
graphics
.
fillRect
(
0
,
0
,
WIDTH
,
HEIGHT
);
// 绘制验证码
graphics
.
setFont
(
new
Font
(
"Arial"
,
Font
.
BOLD
,
28
));
for
(
int
i
=
0
;
i
<
capStr
.
length
();
i
++)
{
graphics
.
setColor
(
getRandomColor
());
graphics
.
drawString
(
String
.
valueOf
(
capStr
.
charAt
(
i
)),
(
i
+
1
)
*
(
WIDTH
/
(
CODE_LENGTH
+
1
)),
30
);
}
// 添加干扰线
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
graphics
.
setColor
(
getRandomColor
());
graphics
.
drawLine
((
int
)
(
Math
.
random
()
*
WIDTH
),
(
int
)
(
Math
.
random
()
*
HEIGHT
),
(
int
)
(
Math
.
random
()
*
WIDTH
),
(
int
)
(
Math
.
random
()
*
HEIGHT
));
}
// 释放资源
graphics
.
dispose
();
return
image
;
}
// 获取随机颜色
private
static
Color
getRandomColor
()
{
int
r
=
(
int
)
(
Math
.
random
()
*
256
);
int
g
=
(
int
)
(
Math
.
random
()
*
256
);
int
b
=
(
int
)
(
Math
.
random
()
*
256
);
return
new
Color
(
r
,
g
,
b
);
}
}
}
dsk-admin/src/main/resources/application-dev.yml
View file @
c58d2c8d
...
@@ -14,7 +14,7 @@ ruoyi:
...
@@ -14,7 +14,7 @@ ruoyi:
# 获取ip地址开关
# 获取ip地址开关
addressEnabled
:
false
addressEnabled
:
false
# 验证码类型 math 数组计算 char 字符验证
# 验证码类型 math 数组计算 char 字符验证
captchaType
:
math
captchaType
:
char
# 开发环境配置
# 开发环境配置
server
:
server
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment