Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
nyx
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
发现
nyx
Commits
dab0c2c4
Commit
dab0c2c4
authored
Aug 02, 2020
by
jscat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nyx_app, 添加二维码生成及测试程序
btw: 为什么不放到weapp上,因为目前没有一个完美的qrcode lib支持各种机型
parent
3717e29c
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
159 行增加
和
3 行删除
+159
-3
增值产品-小程序及app/nyx_app_key/api/pom.xml
+19
-1
增值产品-小程序及app/nyx_app_key/api/src/main/java/cn/com/fun/nyxkey/api/service/Rockwell_ossService.java
+2
-1
增值产品-小程序及app/nyx_app_key/api/src/main/java/cn/com/fun/nyxkey/api/service/impl/Rockwell_ossServiceImpl.java
+105
-1
增值产品-小程序及app/nyx_app_key/api/src/test/java/cn/com/fun/nyxkey/api/ServiceTest.java
+33
-0
没有找到文件。
增值产品-小程序及app/nyx_app_key/api/pom.xml
查看文件 @
dab0c2c4
<?xml
version="1.0" encoding="UTF-8"?>
<?xml
version="1.0" encoding="UTF-8"?>
...
...
@@ -25,6 +25,12 @@
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<!-- Junit依赖 -->
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<!--
MyBatis-Spring-Boot-Starter will:
* Autodetect an existing DataSource.
...
...
@@ -178,6 +184,18 @@
<scope>
compile
</scope>
</dependency>
<!--二维码-->
<dependency>
<groupId>
com.google.zxing
</groupId>
<artifactId>
core
</artifactId>
<version>
3.3.3
</version>
</dependency>
<dependency>
<groupId>
com.google.zxing
</groupId>
<artifactId>
javase
</artifactId>
<version>
3.3.3
</version>
</dependency>
</dependencies>
<build>
...
...
增值产品-小程序及app/nyx_app_key/api/src/main/java/cn/com/fun/nyxkey/api/service/Rockwell_ossService.java
查看文件 @
dab0c2c4
packa
ge
cn
.
com
.
fun
.
nyxkey
.
api
.
service
;
packa
ge
cn
.
com
.
fun
.
nyxkey
.
api
.
service
;
...
...
@@ -15,5 +15,6 @@ import java.util.List;
public
interface
Rockwell_ossService
{
JSONResult
Rockwell_ossServiceGetToken
(
String
userName
,
String
tokenName
);
void
testQrcode
();
}
增值产品-小程序及app/nyx_app_key/api/src/main/java/cn/com/fun/nyxkey/api/service/impl/Rockwell_ossServiceImpl.java
查看文件 @
dab0c2c4
packa
ge
cn
.
com
.
fun
.
nyxkey
.
api
.
service
.
impl
;
packa
ge
cn
.
com
.
fun
.
nyxkey
.
api
.
service
.
impl
;
...
...
@@ -13,6 +13,8 @@ import com.aliyun.oss.OSSClientBuilder;
import
com.aliyun.oss.common.utils.BinaryUtil
;
import
com.aliyun.oss.model.MatchMode
;
import
com.aliyun.oss.model.PolicyConditions
;
import
com.aliyun.oss.model.PutObjectRequest
;
import
com.aliyun.oss.model.PutObjectResult
;
import
com.aliyuncs.DefaultAcsClient
;
import
com.aliyuncs.auth.sts.AssumeRoleRequest
;
import
com.aliyuncs.auth.sts.AssumeRoleResponse
;
...
...
@@ -21,6 +23,11 @@ import com.aliyuncs.http.MethodType;
import
com.aliyuncs.http.ProtocolType
;
import
com.aliyuncs.profile.DefaultProfile
;
import
com.aliyuncs.profile.IClientProfile
;
import
com.google.zxing.BarcodeFormat
;
import
com.google.zxing.WriterException
;
import
com.google.zxing.client.j2se.MatrixToImageWriter
;
import
com.google.zxing.common.BitMatrix
;
import
com.google.zxing.qrcode.QRCodeWriter
;
import
org.apache.commons.lang3.StringUtils
;
import
org.checkerframework.checker.units.qual.K
;
import
org.codehaus.jettison.json.JSONObject
;
...
...
@@ -33,6 +40,7 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.sql.DataSource
;
...
...
@@ -285,4 +293,100 @@ public class Rockwell_ossServiceImpl implements Rockwell_ossService {
return
data
.
toString
();
}
/*
java boot 生成二维码并上传到阿里云oss
https://blog.csdn.net/tang05709/article/details/107136388?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-2&spm=1001.2101.3001.4242
*/
public
String
ossUpload
(
MultipartFile
file
,
String
fileKey
)
throws
IOException
{
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
aliyunOssEndpoint
,
aliyunOssAccessKeyID
,
aliyunOssAccessKeySecret
);
PutObjectResult
res
=
ossClient
.
putObject
(
aliyunOssBucket
,
fileKey
,
new
ByteArrayInputStream
(
file
.
getBytes
()));
ossClient
.
shutdown
();
if
(
res
!=
null
)
{
return
fileKey
;
}
return
null
;
}
public
String
ossUploadByteStream
(
String
fileKey
,
byte
[]
bytes
)
{
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
aliyunOssEndpoint
,
aliyunOssAccessKeyID
,
aliyunOssAccessKeySecret
);
PutObjectRequest
putObjectRequest
=
new
PutObjectRequest
(
aliyunOssBucket
,
fileKey
,
new
ByteArrayInputStream
(
bytes
));
PutObjectResult
res
=
ossClient
.
putObject
(
putObjectRequest
);
ossClient
.
shutdown
();
if
(
res
!=
null
)
{
return
fileKey
;
}
return
null
;
}
public
Map
<
String
,
String
>
getPolicy
(
String
dir
)
throws
UnsupportedEncodingException
{
OSS
ossClient
=
new
OSSClientBuilder
().
build
(
aliyunOssEndpoint
,
aliyunOssAccessKeyID
,
aliyunOssAccessKeySecret
);
PolicyConditions
policyConds
=
new
PolicyConditions
();
policyConds
.
addConditionItem
(
PolicyConditions
.
COND_CONTENT_LENGTH_RANGE
,
0
,
1048576000
);
policyConds
.
addConditionItem
(
MatchMode
.
StartWith
,
PolicyConditions
.
COND_KEY
,
dir
);
String
endpoint
=
aliyunOssEndpoint
;
// 请填写您的 endpoint。
String
bucket
=
aliyunOssBucket
;
// 请填写您的 bucketname 。
String
host
=
"https://"
+
bucket
+
"."
+
endpoint
;
// host的格式为 bucketname.endpoint
long
expireTime
=
30
;
long
expireEndTime
=
System
.
currentTimeMillis
()
+
expireTime
*
1000
;
Date
expiration
=
new
Date
(
expireEndTime
);
String
postPolicy
=
ossClient
.
generatePostPolicy
(
expiration
,
policyConds
);
byte
[]
binaryData
=
postPolicy
.
getBytes
(
"utf-8"
);
String
encodedPolicy
=
BinaryUtil
.
toBase64String
(
binaryData
);
String
postSignature
=
ossClient
.
calculatePostSignature
(
postPolicy
);
Map
<
String
,
String
>
respMap
=
new
LinkedHashMap
<
String
,
String
>();
respMap
.
put
(
"accessid"
,
aliyunOssAccessKeyID
);
respMap
.
put
(
"policy"
,
encodedPolicy
);
respMap
.
put
(
"signature"
,
postSignature
);
respMap
.
put
(
"dir"
,
dir
);
respMap
.
put
(
"fileName"
,
UUID
.
randomUUID
().
toString
());
respMap
.
put
(
"host"
,
host
);
respMap
.
put
(
"expire"
,
String
.
valueOf
(
expireEndTime
/
1000
));
respMap
.
put
(
"callback"
,
""
);
ossClient
.
shutdown
();
return
respMap
;
}
public
String
getBucketUrl
()
{
String
endpoint
=
aliyunOssEndpoint
;
// 请填写您的 endpoint。
String
bucket
=
aliyunOssBucket
;
// 请填写您的 bucketname 。
String
host
=
"https://"
+
bucket
+
"."
+
endpoint
;
// host的格式为 bucketname.endpoint
return
host
;
}
public
String
getQrcode
(
String
text
,
int
width
,
int
height
,
String
filekey
)
{
try
{
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
QRCodeWriter
qrCodeWriter
=
new
QRCodeWriter
();
BitMatrix
bitMatrix
=
qrCodeWriter
.
encode
(
text
,
BarcodeFormat
.
QR_CODE
,
width
,
height
);
MatrixToImageWriter
.
writeToStream
(
bitMatrix
,
"png"
,
os
);
byte
[]
bytes
=
os
.
toByteArray
();
String
url
=
ossUploadByteStream
(
filekey
,
bytes
);
if
(
url
==
null
)
{
return
null
;
}
return
url
;
}
catch
(
WriterException
|
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
public
void
testQrcode
(){
String
filekey
=
aliyunOssDir
+
"this_is_ohlkw.png"
;
String
text
=
"this_is_ohlkw"
;
getQrcode
(
text
,
200
,
200
,
filekey
);
}
}
增值产品-小程序及app/nyx_app_key/api/src/test/java/cn/com/fun/nyxkey/api/ServiceTest.java
0 → 100644
查看文件 @
dab0c2c4
package
cn
.
com
.
fun
.
nyxkey
.
api
;
package
cn
.
com
.
fun
.
nyxkey
.
api
;
import
cn.com.fun.nyxkey.api.service.Rockwell_keyService
;
import
cn.com.fun.nyxkey.api.service.Rockwell_ossService
;
import
javafx.application.Application
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
/*
javax.websocket.server.ServerContainer not available
在SpringBoot项目中集成了WebSocket,在进行单元测试的时候,出现了以下错误:
javax.websocket.server.ServerContainer not available
https://blog.csdn.net/chunjusu2447/article/details/100820520
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
public
class
ServiceTest
{
@Autowired
Rockwell_ossService
rockwell_ossService
;
@Test
public
void
test
(){
rockwell_ossService
.
testQrcode
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论