Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fzm-joying
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
lei
fzm-joying
Commits
f5a76b3d
Commit
f5a76b3d
authored
Jul 08, 2021
by
tangtuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nft证书接口编写
parent
9a4346df
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
351 additions
and
1 deletion
+351
-1
StpAdminUtil.java
...-admin/src/main/java/com/fzm/admin/auth/StpAdminUtil.java
+2
-0
pom.xml
joying-common/pom.xml
+4
-0
NftCertificateVo.java
.../main/java/com/fzm/common/entity/vo/NftCertificateVo.java
+60
-0
BufferedImageLuminanceSource.java
...va/com/fzm/common/model/BufferedImageLuminanceSource.java
+91
-0
QRCodeUtil.java
...common/src/main/java/com/fzm/common/utils/QRCodeUtil.java
+163
-0
pom.xml
joying-portal/pom.xml
+0
-1
NftController.java
...rc/main/java/com/fzm/portal/controller/NftController.java
+25
-0
pom.xml
pom.xml
+6
-0
No files found.
joying-admin/src/main/java/com/fzm/admin/auth/StpAdminUtil.java
View file @
f5a76b3d
...
...
@@ -5,6 +5,7 @@ import cn.dev33.satoken.session.SaSession;
import
cn.dev33.satoken.stp.SaLoginModel
;
import
cn.dev33.satoken.stp.SaTokenInfo
;
import
cn.dev33.satoken.stp.StpLogic
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
...
...
@@ -13,6 +14,7 @@ import java.util.List;
*
* @author kong
*/
@Component
public
class
StpAdminUtil
{
/**
...
...
joying-common/pom.xml
View file @
f5a76b3d
...
...
@@ -84,6 +84,10 @@
<groupId>
com.github.pagehelper
</groupId>
<artifactId>
pagehelper-spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
com.google.zxing
</groupId>
<artifactId>
core
</artifactId>
</dependency>
</dependencies>
<properties>
...
...
joying-common/src/main/java/com/fzm/common/entity/vo/NftCertificateVo.java
0 → 100644
View file @
f5a76b3d
package
com
.
fzm
.
common
.
entity
.
vo
;
import
cn.hutool.core.date.DateUtil
;
import
com.fzm.common.entity.Nft
;
import
com.fzm.common.entity.User
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.Date
;
/**
* @author tangtuo
* @date 2021/7/1 10:35
*/
@Data
public
class
NftCertificateVo
{
@ApiModelProperty
(
"主键"
)
private
Integer
id
;
@ApiModelProperty
(
"名称"
)
private
String
name
;
@ApiModelProperty
(
"发行人"
)
private
String
publisher
;
@ApiModelProperty
(
"发行人地址"
)
private
String
wallet
;
@ApiModelProperty
(
"剧本hash"
)
private
String
fileHash
;
@ApiModelProperty
(
"nft哈希"
)
private
String
nftHash
;
@ApiModelProperty
(
"存证时间"
)
private
Date
publishTime
;
@ApiModelProperty
(
"二维码"
)
private
String
qrCode
;
@ApiModelProperty
(
"剧本审核状态 0-未审核 1-已审核"
)
private
Integer
examineStatus
;
@ApiModelProperty
(
"版权证明: 0-未认证 1-已认证"
)
private
Integer
copyrightStatus
;
public
NftCertificateVo
(
Nft
nft
,
User
user
,
String
qrCode
)
{
this
.
name
=
nft
.
getName
();
this
.
fileHash
=
nft
.
getFileHash
();
this
.
nftHash
=
nft
.
getNftHash
();
this
.
id
=
nft
.
getId
();
this
.
publisher
=
user
.
getNickname
();
this
.
publishTime
=
nft
.
getPublishTime
();
this
.
wallet
=
user
.
getWallet
();
this
.
qrCode
=
qrCode
;
this
.
examineStatus
=
0
;
this
.
copyrightStatus
=
0
;
}
}
joying-common/src/main/java/com/fzm/common/model/BufferedImageLuminanceSource.java
0 → 100644
View file @
f5a76b3d
package
com
.
fzm
.
common
.
model
;
import
java.awt.Graphics2D
;
import
java.awt.geom.AffineTransform
;
import
java.awt.image.BufferedImage
;
import
com.google.zxing.LuminanceSource
;
public
class
BufferedImageLuminanceSource
extends
LuminanceSource
{
private
final
BufferedImage
image
;
private
final
int
left
;
private
final
int
top
;
public
BufferedImageLuminanceSource
(
BufferedImage
image
)
{
this
(
image
,
0
,
0
,
image
.
getWidth
(),
image
.
getHeight
());
}
public
BufferedImageLuminanceSource
(
BufferedImage
image
,
int
left
,
int
top
,
int
width
,
int
height
)
{
super
(
width
,
height
);
int
sourceWidth
=
image
.
getWidth
();
int
sourceHeight
=
image
.
getHeight
();
if
(
left
+
width
>
sourceWidth
||
top
+
height
>
sourceHeight
)
{
throw
new
IllegalArgumentException
(
"Crop rectangle does not fit within image data."
);
}
for
(
int
y
=
top
;
y
<
top
+
height
;
y
++)
{
for
(
int
x
=
left
;
x
<
left
+
width
;
x
++)
{
if
((
image
.
getRGB
(
x
,
y
)
&
0xFF000000
)
==
0
)
{
image
.
setRGB
(
x
,
y
,
0xFFFFFFFF
);
// = white
}
}
}
this
.
image
=
new
BufferedImage
(
sourceWidth
,
sourceHeight
,
BufferedImage
.
TYPE_BYTE_GRAY
);
this
.
image
.
getGraphics
().
drawImage
(
image
,
0
,
0
,
null
);
this
.
left
=
left
;
this
.
top
=
top
;
}
public
byte
[]
getRow
(
int
y
,
byte
[]
row
)
{
if
(
y
<
0
||
y
>=
getHeight
())
{
throw
new
IllegalArgumentException
(
"Requested row is outside the image: "
+
y
);
}
int
width
=
getWidth
();
if
(
row
==
null
||
row
.
length
<
width
)
{
row
=
new
byte
[
width
];
}
image
.
getRaster
().
getDataElements
(
left
,
top
+
y
,
width
,
1
,
row
);
return
row
;
}
public
byte
[]
getMatrix
()
{
int
width
=
getWidth
();
int
height
=
getHeight
();
int
area
=
width
*
height
;
byte
[]
matrix
=
new
byte
[
area
];
image
.
getRaster
().
getDataElements
(
left
,
top
,
width
,
height
,
matrix
);
return
matrix
;
}
@Override
public
boolean
isCropSupported
()
{
return
true
;
}
@Override
public
LuminanceSource
crop
(
int
left
,
int
top
,
int
width
,
int
height
)
{
return
new
BufferedImageLuminanceSource
(
image
,
this
.
left
+
left
,
this
.
top
+
top
,
width
,
height
);
}
@Override
public
boolean
isRotateSupported
()
{
return
true
;
}
@Override
public
LuminanceSource
rotateCounterClockwise
()
{
int
sourceWidth
=
image
.
getWidth
();
int
sourceHeight
=
image
.
getHeight
();
AffineTransform
transform
=
new
AffineTransform
(
0.0
,
-
1.0
,
1.0
,
0.0
,
0.0
,
sourceWidth
);
BufferedImage
rotatedImage
=
new
BufferedImage
(
sourceHeight
,
sourceWidth
,
BufferedImage
.
TYPE_BYTE_GRAY
);
Graphics2D
g
=
rotatedImage
.
createGraphics
();
g
.
drawImage
(
image
,
transform
,
null
);
g
.
dispose
();
int
width
=
getWidth
();
return
new
BufferedImageLuminanceSource
(
rotatedImage
,
top
,
sourceWidth
-
(
left
+
width
),
getHeight
(),
width
);
}
}
\ No newline at end of file
joying-common/src/main/java/com/fzm/common/utils/QRCodeUtil.java
0 → 100644
View file @
f5a76b3d
package
com
.
fzm
.
common
.
utils
;
import
java.awt.BasicStroke
;
import
java.awt.Graphics
;
import
java.awt.Graphics2D
;
import
java.awt.Image
;
import
java.awt.Shape
;
import
java.awt.geom.RoundRectangle2D
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.Hashtable
;
import
javax.imageio.ImageIO
;
import
com.fzm.common.model.BufferedImageLuminanceSource
;
import
com.google.zxing.BarcodeFormat
;
import
com.google.zxing.BinaryBitmap
;
import
com.google.zxing.DecodeHintType
;
import
com.google.zxing.EncodeHintType
;
import
com.google.zxing.MultiFormatReader
;
import
com.google.zxing.MultiFormatWriter
;
import
com.google.zxing.Result
;
import
com.google.zxing.common.BitMatrix
;
import
com.google.zxing.common.HybridBinarizer
;
import
com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
;
import
sun.misc.BASE64Encoder
;
public
class
QRCodeUtil
{
private
static
final
String
CHARSET
=
"utf-8"
;
private
static
final
String
FORMAT_NAME
=
"JPG"
;
// 二维码尺寸
private
static
final
int
QRCODE_SIZE
=
300
;
// LOGO宽度
private
static
final
int
WIDTH
=
60
;
// LOGO高度
private
static
final
int
HEIGHT
=
60
;
private
static
BufferedImage
createImage
(
String
content
,
String
imgPath
,
boolean
needCompress
)
throws
Exception
{
Hashtable
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
,
QRCODE_SIZE
,
QRCODE_SIZE
,
hints
);
int
width
=
bitMatrix
.
getWidth
();
int
height
=
bitMatrix
.
getHeight
();
BufferedImage
image
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
for
(
int
x
=
0
;
x
<
width
;
x
++)
{
for
(
int
y
=
0
;
y
<
height
;
y
++)
{
image
.
setRGB
(
x
,
y
,
bitMatrix
.
get
(
x
,
y
)
?
0xFF000000
:
0xFFFFFFFF
);
}
}
if
(
imgPath
==
null
||
""
.
equals
(
imgPath
))
{
return
image
;
}
// 插入图片
QRCodeUtil
.
insertImage
(
image
,
imgPath
,
needCompress
);
return
image
;
}
private
static
void
insertImage
(
BufferedImage
source
,
String
imgPath
,
boolean
needCompress
)
throws
Exception
{
File
file
=
new
File
(
imgPath
);
if
(!
file
.
exists
())
{
System
.
err
.
println
(
""
+
imgPath
+
" 该文件不存在!"
);
return
;
}
Image
src
=
ImageIO
.
read
(
new
File
(
imgPath
));
int
width
=
src
.
getWidth
(
null
);
int
height
=
src
.
getHeight
(
null
);
if
(
needCompress
)
{
// 压缩LOGO
if
(
width
>
WIDTH
)
{
width
=
WIDTH
;
}
if
(
height
>
HEIGHT
)
{
height
=
HEIGHT
;
}
Image
image
=
src
.
getScaledInstance
(
width
,
height
,
Image
.
SCALE_SMOOTH
);
BufferedImage
tag
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
Graphics
g
=
tag
.
getGraphics
();
g
.
drawImage
(
image
,
0
,
0
,
null
);
// 绘制缩小后的图
g
.
dispose
();
src
=
image
;
}
// 插入LOGO
Graphics2D
graph
=
source
.
createGraphics
();
int
x
=
(
QRCODE_SIZE
-
width
)
/
2
;
int
y
=
(
QRCODE_SIZE
-
height
)
/
2
;
graph
.
drawImage
(
src
,
x
,
y
,
width
,
height
,
null
);
Shape
shape
=
new
RoundRectangle2D
.
Float
(
x
,
y
,
width
,
width
,
6
,
6
);
graph
.
setStroke
(
new
BasicStroke
(
3
f
));
graph
.
draw
(
shape
);
graph
.
dispose
();
}
/**
* @param content 二维码内容
* @param imgPath 嵌入二维码的图片路径
* @param needCompress 是否压缩
* @return
* @throws Exception
*/
public
static
String
encode
(
String
content
,
String
imgPath
,
boolean
needCompress
)
throws
Exception
{
BufferedImage
image
=
QRCodeUtil
.
createImage
(
content
,
imgPath
,
needCompress
);
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
//io流
try
{
ImageIO
.
write
(
image
,
"png"
,
baos
);
//写入流中
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
byte
[]
bytes
=
baos
.
toByteArray
();
//转换成字节
BASE64Encoder
encoder
=
new
BASE64Encoder
();
String
png_base64
=
encoder
.
encodeBuffer
(
bytes
).
trim
();
//转换成base64串
png_base64
=
png_base64
.
replaceAll
(
"\n"
,
""
).
replaceAll
(
"\r"
,
""
);
//删除 \r\n
System
.
out
.
println
(
"值为:"
+
"data:image/jpg;base64,"
+
png_base64
);
return
"data:image/jpg;base64,"
+
png_base64
;
}
// 被注释的方法
/*
* public static void encode(String content, String destPath, boolean
* needCompress) throws Exception { QRCodeUtil.encode(content, null, destPath,
* needCompress); }
*/
public
static
void
encode
(
String
content
)
throws
Exception
{
QRCodeUtil
.
encode
(
content
,
null
,
false
);
}
public
static
void
encode
(
String
content
,
String
imgPath
,
OutputStream
output
,
boolean
needCompress
)
throws
Exception
{
BufferedImage
image
=
QRCodeUtil
.
createImage
(
content
,
imgPath
,
needCompress
);
ImageIO
.
write
(
image
,
FORMAT_NAME
,
output
);
}
public
static
void
encode
(
String
content
,
OutputStream
output
)
throws
Exception
{
QRCodeUtil
.
encode
(
content
,
null
,
output
,
false
);
}
public
static
String
decode
(
File
file
)
throws
Exception
{
BufferedImage
image
;
image
=
ImageIO
.
read
(
file
);
if
(
image
==
null
)
{
return
null
;
}
BufferedImageLuminanceSource
source
=
new
BufferedImageLuminanceSource
(
image
);
BinaryBitmap
bitmap
=
new
BinaryBitmap
(
new
HybridBinarizer
(
source
));
Result
result
;
Hashtable
hints
=
new
Hashtable
();
hints
.
put
(
DecodeHintType
.
CHARACTER_SET
,
CHARSET
);
result
=
new
MultiFormatReader
().
decode
(
bitmap
,
hints
);
String
resultStr
=
result
.
getText
();
return
resultStr
;
}
public
static
String
decode
(
String
path
)
throws
Exception
{
return
QRCodeUtil
.
decode
(
new
File
(
path
));
}
}
\ No newline at end of file
joying-portal/pom.xml
View file @
f5a76b3d
...
...
@@ -40,7 +40,6 @@
<artifactId>
joying-common
</artifactId>
<version>
1.0.0
</version>
</dependency>
</dependencies>
<build>
...
...
joying-portal/src/main/java/com/fzm/portal/controller/NftController.java
View file @
f5a76b3d
...
...
@@ -7,6 +7,7 @@ import com.fzm.common.constant.SystemConstant;
import
com.fzm.common.entity.Nft
;
import
com.fzm.common.entity.User
;
import
com.fzm.common.entity.vo.CollectionNftVo
;
import
com.fzm.common.entity.vo.NftCertificateVo
;
import
com.fzm.common.entity.vo.NftVo
;
import
com.fzm.common.enums.ResultCode
;
import
com.fzm.common.exception.GlobalException
;
...
...
@@ -15,6 +16,7 @@ import com.fzm.common.service.CategoryService;
import
com.fzm.common.service.NftService
;
import
com.fzm.common.service.UserService
;
import
com.fzm.common.utils.OssUtil
;
import
com.fzm.common.utils.QRCodeUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
...
...
@@ -49,6 +51,12 @@ public class NftController {
@Resource
private
CategoryService
categoryService
;
/**
* 存证二维码跳转地址
* todo 修改成动态前端路由
*/
private
static
final
String
path
=
"https://chain.33.cn/document/60"
;
@SaCheckLogin
@PostMapping
(
"/publish"
)
...
...
@@ -144,4 +152,21 @@ public class NftController {
}
@SaCheckLogin
@GetMapping
(
"/certificate/{id}"
)
@ApiOperation
(
value
=
"nft证书"
)
public
ResponseModel
<
NftCertificateVo
>
certificate
(
@PathVariable
Integer
id
)
throws
Exception
{
Nft
nft
=
nftService
.
getById
(
id
);
if
(
nft
==
null
)
{
throw
GlobalException
.
newException
(
ResultCode
.
DATA_ERROR
,
"没找到此nft的详情"
);
}
int
userId
=
StpUtil
.
getLoginIdAsInt
();
if
(!
nft
.
getUserId
().
equals
(
userId
))
{
throw
GlobalException
.
newException
(
ResultCode
.
FORBIDDEN
,
"您无权查看别人的nft证书"
);
}
User
user
=
userService
.
getById
(
userId
);
String
qrCode
=
QRCodeUtil
.
encode
(
path
,
null
,
false
);
NftCertificateVo
vo
=
new
NftCertificateVo
(
nft
,
user
,
qrCode
);
return
ResponseModel
.
success
(
vo
);
}
}
pom.xml
View file @
f5a76b3d
...
...
@@ -93,6 +93,12 @@
<artifactId>
pagehelper-spring-boot-starter
</artifactId>
<version>
1.3.0
</version>
</dependency>
<!-- 二维码生成工具 -->
<dependency>
<groupId>
com.google.zxing
</groupId>
<artifactId>
core
</artifactId>
<version>
3.3.0
</version>
</dependency>
</dependencies>
</dependencyManagement>
...
...
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