Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
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
youjj
cloud-platform
Commits
15930c13
Commit
15930c13
authored
Dec 21, 2019
by
jiaorz
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master-captcha-branch' into dev
parents
16f9f6b9
ea76b244
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
2 deletions
+78
-2
base64Change.java
.../java/com/xxfc/platform/universal/utils/base64Change.java
+76
-0
AbstractCaptcha.java
.../com/xxfc/platform/universal/service/AbstractCaptcha.java
+2
-2
No files found.
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/utils/base64Change.java
0 → 100644
View file @
15930c13
package
com
.
xxfc
.
platform
.
universal
.
utils
;
import
org.apache.commons.lang3.StringUtils
;
import
sun.misc.BASE64Decoder
;
import
sun.misc.BASE64Encoder
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.*
;
public
class
base64Change
{
/**
* @param imgStr base64编码字符串
* @param path 图片路径-具体到文件
*/
public
static
boolean
generateImage
(
String
imgStr
,
String
path
)
{
if
(
imgStr
==
null
)
return
false
;
BASE64Decoder
decoder
=
new
BASE64Decoder
();
try
{
// 解密
byte
[]
b
=
decoder
.
decodeBuffer
(
imgStr
);
// 处理数据
for
(
int
i
=
0
;
i
<
b
.
length
;
++
i
)
{
if
(
b
[
i
]
<
0
)
{
b
[
i
]
+=
256
;
}
}
OutputStream
out
=
new
FileOutputStream
(
path
);
out
.
write
(
b
);
out
.
flush
();
out
.
close
();
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
public
static
void
main
(
String
[]
args
)
{
String
path
=
"d:\\1.jpg"
;
String
imgFile
=
"D:\\Downloads\\light_yan-captcha-master\\captcha\\images\\pic-click\\bg5.png"
;
//待处理的图片
String
imgpath
=
GetImageStr
(
imgFile
);
System
.
out
.
println
(
generateImage
(
imgpath
,
path
));
}
//图片转化成base64字符串
public
static
String
GetImageStr
(
String
imgFile
)
{
//将图片文件转化为字节数组字符串,并对其进行Base64编码处理
// 地址也有写成"F:/deskBG/86619-107.jpg"形式的
try
{
return
encodeToString
(
imgFile
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
String
encodeToString
(
String
imagePath
)
throws
IOException
{
String
type
=
StringUtils
.
substring
(
imagePath
,
imagePath
.
lastIndexOf
(
"."
)
+
1
);
BufferedImage
image
=
ImageIO
.
read
(
new
File
(
imagePath
));
String
imageString
=
null
;
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
try
{
ImageIO
.
write
(
image
,
type
,
bos
);
byte
[]
imageBytes
=
bos
.
toByteArray
();
BASE64Encoder
encoder
=
new
BASE64Encoder
();
imageString
=
encoder
.
encode
(
imageBytes
);
bos
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
imageString
;
}
}
\ No newline at end of file
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/AbstractCaptcha.java
View file @
15930c13
...
...
@@ -70,13 +70,13 @@ public abstract class AbstractCaptcha {
protected
String
getImageToBase64Str
(
BufferedImage
templateImage
){
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
try
{
ImageIO
.
write
(
templateImage
,
"
jp
g"
,
baos
);
ImageIO
.
write
(
templateImage
,
"
pn
g"
,
baos
);
}
catch
(
IOException
e
)
{
throw
new
CaptchaException
(
"ImageIO.write is error"
,
e
);
}
byte
[]
bytes
=
baos
.
toByteArray
();
BASE64Encoder
encoder
=
new
BASE64Encoder
();
return
encoder
.
encodeBuffer
(
bytes
).
trim
();
return
encoder
.
encodeBuffer
(
bytes
).
trim
()
.
replaceAll
(
"\n"
,
""
).
replaceAll
(
"\r"
,
""
)
;
}
public
String
getJigsawUrlOrPath
()
{
...
...
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