Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
eMall_api
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
杨硕
eMall_api
Commits
1303f885
Commit
1303f885
authored
Jul 20, 2023
by
gaoyingwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改二维码生成
parent
1dbb9775
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
6 deletions
+89
-6
ApplicationExceptionEnum.java
.../emall/flash/bean/exception/ApplicationExceptionEnum.java
+3
-1
CyQrCodeUtil.java
...ore/src/main/java/com/emall/flash/utils/CyQrCodeUtil.java
+71
-1
Qrcode.java
emall-core/src/main/java/com/emall/flash/utils/Qrcode.java
+3
-3
pom.xml
emall-generator/pom.xml
+11
-0
UserController.java
...ava/com/emall/flash/mobile/controller/UserController.java
+1
-1
No files found.
emall-core/src/main/java/com/emall/flash/bean/exception/ApplicationExceptionEnum.java
View file @
1303f885
...
...
@@ -35,7 +35,9 @@ public enum ApplicationExceptionEnum implements ServiceExceptionEnum{
REQUEST_TOO_MANY
(
500
,
"请求频繁,请稍后重试"
),
TASK_CONFIG_ERROR
(
500
,
"定时任务配置错误"
),
DELETE_MODEL_ERROR
(
500
,
"已分配商圈,不能删除"
);
DELETE_MODEL_ERROR
(
500
,
"已分配商圈,不能删除"
),
QRCODE_ERROR
(
500
,
"二维码生成失败"
);
ApplicationExceptionEnum
(
int
code
,
String
message
)
{
this
.
code
=
code
;
...
...
emall-core/src/main/java/com/emall/flash/utils/CyQrCodeUtil.java
View file @
1303f885
package
com
.
emall
.
flash
.
utils
;
import
com.emall.flash.bean.exception.ApplicationException
;
import
com.emall.flash.bean.exception.ApplicationExceptionEnum
;
import
com.google.zxing.BarcodeFormat
;
import
com.google.zxing.EncodeHintType
;
import
com.google.zxing.MultiFormatWriter
;
import
com.google.zxing.common.BitMatrix
;
import
com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.imageio.ImageIO
;
import
java.awt.*
;
import
java.awt.geom.Rectangle2D
;
import
java.awt.image.BufferedImage
;
import
java.io.UnsupportedEncodingException
;
import
java.io.*
;
import
java.util.Hashtable
;
import
java.util.List
;
import
java.util.Map
;
public
class
CyQrCodeUtil
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
CyQrCodeUtil
.
class
);
...
...
@@ -44,4 +56,62 @@ public class CyQrCodeUtil {
throw
var8
;
}
}
public
static
InputStream
getCode2
(
String
urlCode
,
int
qrWidth
,
int
qrHeight
){
ByteArrayInputStream
stream
=
null
;
//需要编码的内容
String
png_base64
=
null
;
//返回二维码 并且构造支付包web支付对象
ByteArrayOutputStream
baOp
=
new
ByteArrayOutputStream
();
try
{
BufferedImage
bufImg
=
createImage
(
urlCode
,
qrWidth
,
qrHeight
);
// 生成二维码QRCode图片
ImageIO
.
write
(
bufImg
,
"png"
,
baOp
);
byte
[]
bytes
=
baOp
.
toByteArray
();
//转换成字节
stream
=
new
ByteArrayInputStream
(
bytes
);
File
file
=
new
File
(
"D:/3.png"
);
// if (!file.getParentFile().exists()){
// //文件夹不存在 生成
// file.getParentFile().mkdirs();
// }
FileOutputStream
fos
=
null
;
BufferedOutputStream
bos
=
null
;
fos
=
new
FileOutputStream
(
file
);
fos
.
write
(
bytes
);
bos
=
new
BufferedOutputStream
(
fos
);
bos
.
write
(
bytes
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
throw
new
ApplicationException
(
ApplicationExceptionEnum
.
QRCODE_ERROR
);
}
return
stream
;
}
private
static
final
String
CHARSET
=
"utf-8"
;
public
static
BufferedImage
createImage
(
String
content
,
int
qrWidth
,
int
qrHeight
)
throws
Exception
{
Map
<
EncodeHintType
,
Object
>
hints
=
new
Hashtable
<>();
hints
.
put
(
EncodeHintType
.
ERROR_CORRECTION
,
ErrorCorrectionLevel
.
H
);
hints
.
put
(
EncodeHintType
.
CHARACTER_SET
,
CHARSET
);
hints
.
put
(
EncodeHintType
.
MARGIN
,
1
);
BitMatrix
bitMatrix
=
new
MultiFormatWriter
().
encode
(
content
,
BarcodeFormat
.
QR_CODE
,
qrWidth
,
qrHeight
,
hints
);
qrWidth
=
bitMatrix
.
getWidth
();
qrHeight
=
bitMatrix
.
getHeight
();
//创建二维码
BufferedImage
image
=
new
BufferedImage
(
qrWidth
,
qrHeight
,
BufferedImage
.
TYPE_INT_RGB
);
for
(
int
x
=
0
;
x
<
qrWidth
;
x
++)
{
for
(
int
y
=
0
;
y
<
qrHeight
;
y
++)
{
image
.
setRGB
(
x
,
y
,
bitMatrix
.
get
(
x
,
y
)
?
0xFF000000
:
0xFFFFFFFF
);
}
}
//在二维码下方增加文字显示
BufferedImage
bi
=
new
BufferedImage
(
qrWidth
,
qrHeight
,
BufferedImage
.
TYPE_INT_RGB
);
Graphics2D
g2
=
bi
.
createGraphics
();
g2
.
setBackground
(
new
Color
(
0xFF
,
0xFF
,
0xFF
));
//通过使用当前绘图表面的背景色进行填充来清除指定的矩形。
g2
.
clearRect
(
0
,
0
,
qrWidth
,
qrHeight
);
g2
.
drawImage
(
image
,
0
,
0
,
qrWidth
,
qrHeight
,
null
);
//x,y为image图片的位置
image
=
bi
;
return
image
;
}
}
emall-core/src/main/java/com/emall/flash/utils/Qrcode.java
View file @
1303f885
...
...
@@ -347,8 +347,8 @@ public class Qrcode {
for
(
int
a
=
0
;
a
<
15
;
++
a
)
{
byte
content
=
Byte
.
parseByte
(
formatInformationArray
[
formatInformationValue
].
substring
(
a
,
a
+
1
));
matrixContent
[
formatInformationX1
[
i
]
&
255
][
formatInformationY1
[
a
]
&
255
]
=
(
byte
)(
content
*
255
);
matrixContent
[
formatInformationX2
[
i
]
&
255
][
formatInformationY2
[
a
]
&
255
]
=
(
byte
)(
content
*
255
);
matrixContent
[
formatInformationX1
[
a
]
&
255
][
formatInformationY1
[
a
]
&
255
]
=
(
byte
)(
content
*
255
);
matrixContent
[
formatInformationX2
[
a
]
&
255
][
formatInformationY2
[
a
]
&
255
]
=
(
byte
)(
content
*
255
);
}
boolean
[][]
out
=
new
boolean
[
modules1Side
][
modules1Side
];
...
...
@@ -628,4 +628,4 @@ public class Qrcode {
return
res
;
}
}
\ No newline at end of file
}
emall-generator/pom.xml
View file @
1303f885
...
...
@@ -63,6 +63,17 @@
<version>
4.12
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.google.zxing
</groupId>
<artifactId>
core
</artifactId>
<version>
2.2
</version>
</dependency>
<dependency>
<groupId>
com.google.zxing
</groupId>
<artifactId>
javase
</artifactId>
<version>
2.2
</version>
</dependency>
</dependencies>
...
...
emall-mobile-api/src/main/java/com/emall/flash/mobile/controller/UserController.java
View file @
1303f885
...
...
@@ -157,7 +157,7 @@ public class UserController extends BaseController {
//返回二维码 并且构造支付包web支付对象
ByteArrayOutputStream
baOp
=
new
ByteArrayOutputStream
();
try
{
BufferedImage
bufImg
=
CyQrCodeUtil
.
qRCodeCommon
(
id
);
BufferedImage
bufImg
=
CyQrCodeUtil
.
createImage
(
id
,
235
,
235
);
// 生成二维码QRCode图片
ImageIO
.
write
(
bufImg
,
"png"
,
baOp
);
byte
[]
bytes
=
baOp
.
toByteArray
();
//转换成字节
...
...
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