Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_42566577
o2oa
提交
c890a846
o2oa
项目概览
weixin_42566577
/
o2oa
与 Fork 源项目一致
Fork自
浙江兰德纵横网络技术股份有限公司 / o2oa
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
o2oa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c890a846
编写于
9月 27, 2021
作者:
O
o2sword
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
图片验证码优化
上级
1e9c1f76
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
23 deletion
+44
-23
o2server/pom.xml
o2server/pom.xml
+5
-5
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/captcha/V2Create.java
...ain/java/com/x/program/center/jaxrs/captcha/V2Create.java
+39
-18
未找到文件。
o2server/pom.xml
浏览文件 @
c890a846
...
...
@@ -364,8 +364,8 @@
<artifactId>
cache-ri-impl
</artifactId>
</dependency>
<dependency>
<groupId>
com.github.
whvcs
e
</groupId>
<artifactId>
easy-c
aptcha
</artifactId>
<groupId>
com.github.
penggl
e
</groupId>
<artifactId>
k
aptcha
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.hadoop
</groupId>
...
...
@@ -1084,9 +1084,9 @@
<version>
1.1.1
</version>
</dependency>
<dependency>
<groupId>
com.github.
whvcs
e
</groupId>
<artifactId>
easy-c
aptcha
</artifactId>
<version>
1.6
.2
</version>
<groupId>
com.github.
penggl
e
</groupId>
<artifactId>
k
aptcha
</artifactId>
<version>
2.3
.2
</version>
</dependency>
<dependency>
<groupId>
org.apache.hadoop
</groupId>
...
...
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/captcha/V2Create.java
浏览文件 @
c890a846
package
com.x.program.center.jaxrs.captcha
;
import
java.awt.
Font
;
import
java.awt.
image.BufferedImage
;
import
java.io.ByteArrayOutputStream
;
import
java.util.Base64
;
import
java.util.Properties
;
import
org.apache.commons.lang3.StringUtils
;
import
com.google.code.kaptcha.Constants
;
import
com.google.code.kaptcha.Producer
;
import
com.google.code.kaptcha.impl.DefaultKaptcha
;
import
com.google.code.kaptcha.util.Config
;
import
com.wf.captcha.SpecCaptcha
;
import
com.x.base.core.container.EntityManagerContainer
;
import
com.x.base.core.container.factory.EntityManagerContainerFactory
;
import
com.x.base.core.entity.annotation.CheckPersistType
;
import
com.x.base.core.project.annotation.FieldDescribe
;
import
com.x.base.core.project.config.Config
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.program.center.core.entity.Captcha
;
import
javax.imageio.ImageIO
;
class
V2Create
extends
BaseAction
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
V2Create
.
class
);
...
...
@@ -23,30 +28,28 @@ class V2Create extends BaseAction {
ActionResult
<
Wo
>
execute
(
Integer
width
,
Integer
height
)
throws
Exception
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
ActionResult
<
Wo
>
result
=
new
ActionResult
<>();
if
(
width
<=
80
&&
width
>
800
)
{
if
(
width
<=
80
||
width
>
800
)
{
width
=
80
;
}
if
(
width
<=
30
&&
width
>
800
)
{
width
=
30
;
}
SpecCaptcha
specCaptcha
=
new
SpecCaptcha
(
width
,
height
,
4
);
specCaptcha
.
setCharType
(
com
.
wf
.
captcha
.
base
.
Captcha
.
TYPE_ONLY_NUMBER
);
if
(
StringUtils
.
isNotBlank
(
Config
.
person
().
getCaptchaFont
()))
{
specCaptcha
.
setFont
(
new
Font
(
Config
.
person
().
getCaptchaFont
(),
Font
.
PLAIN
,
32
));
if
(
height
<=
30
||
height
>
800
)
{
height
=
30
;
}
Producer
producer
=
createProducer
(
width
,
height
);
// 生成随机字符串
String
verifyCode
=
producer
.
createText
();
// 生成图片
BufferedImage
bufferedImage
=
producer
.
createImage
(
verifyCode
);
ByteArrayOutputStream
stream
=
new
ByteArrayOutputStream
();
ImageIO
.
write
(
bufferedImage
,
"png"
,
stream
);
emc
.
beginTransaction
(
Captcha
.
class
);
Captcha
captcha
=
new
Captcha
();
captcha
.
setAnswer
(
specCaptcha
.
text
()
);
captcha
.
setAnswer
(
verifyCode
);
emc
.
persist
(
captcha
,
CheckPersistType
.
all
);
emc
.
commit
();
Wo
wo
=
new
Wo
();
wo
.
setId
(
captcha
.
getId
());
try
(
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
())
{
wo
.
setImage
(
specCaptcha
.
toBase64
(
""
));
}
wo
.
setImage
(
Base64
.
getEncoder
().
encodeToString
(
stream
.
toByteArray
()));
result
.
setData
(
wo
);
return
result
;
}
...
...
@@ -77,4 +80,22 @@ class V2Create extends BaseAction {
}
}
private
static
Producer
createProducer
(
Integer
width
,
Integer
height
)
{
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
Constants
.
KAPTCHA_BORDER
,
"no"
);
properties
.
setProperty
(
Constants
.
KAPTCHA_BORDER_COLOR
,
"105,179,90"
);
properties
.
setProperty
(
Constants
.
KAPTCHA_TEXTPRODUCER_FONT_COLOR
,
"black"
);
properties
.
setProperty
(
Constants
.
KAPTCHA_IMAGE_WIDTH
,
width
.
toString
());
properties
.
setProperty
(
Constants
.
KAPTCHA_IMAGE_HEIGHT
,
height
.
toString
());
properties
.
setProperty
(
Constants
.
KAPTCHA_TEXTPRODUCER_CHAR_LENGTH
,
"4"
);
properties
.
setProperty
(
Constants
.
KAPTCHA_TEXTPRODUCER_FONT_SIZE
,
"40"
);
properties
.
setProperty
(
Constants
.
KAPTCHA_TEXTPRODUCER_FONT_NAMES
,
"宋体,楷体,微软雅黑"
);
properties
.
setProperty
(
Constants
.
KAPTCHA_TEXTPRODUCER_CHAR_STRING
,
"1234567890"
);
//properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "5");
Config
config
=
new
Config
(
properties
);
DefaultKaptcha
defaultKaptcha
=
new
DefaultKaptcha
();
defaultKaptcha
.
setConfig
(
config
);
return
defaultKaptcha
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录