Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
7279c75e
Commit
7279c75e
authored
Aug 17, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
b73c4f2e
669a137c
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
262 additions
and
164 deletions
+262
-164
ch-core/src/main/java/com/wwdz/ch/core/consts/CommConsts.java
...ore/src/main/java/com/wwdz/ch/core/consts/CommConsts.java
+6
-1
ch-core/src/main/java/com/wwdz/ch/core/storage/AliyunStorage.java
...src/main/java/com/wwdz/ch/core/storage/AliyunStorage.java
+14
-10
ch-core/src/main/java/com/wwdz/ch/core/storage/LocalStorage.java
.../src/main/java/com/wwdz/ch/core/storage/LocalStorage.java
+5
-0
ch-core/src/main/java/com/wwdz/ch/core/storage/QiniuStorage.java
.../src/main/java/com/wwdz/ch/core/storage/QiniuStorage.java
+33
-16
ch-core/src/main/java/com/wwdz/ch/core/storage/Storage.java
ch-core/src/main/java/com/wwdz/ch/core/storage/Storage.java
+8
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FavoritesServiceImpl.java
...c/main/java/com/wwdz/ch/wx/impl/FavoritesServiceImpl.java
+26
-13
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FootPrintServiceImpl.java
...c/main/java/com/wwdz/ch/wx/impl/FootPrintServiceImpl.java
+35
-46
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
+71
-57
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/WxLoginServiceImpl.java
...src/main/java/com/wwdz/ch/wx/impl/WxLoginServiceImpl.java
+25
-17
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/FootPrintService.java
...rc/main/java/com/wwdz/ch/wx/service/FootPrintService.java
+0
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/ItemService.java
...api/src/main/java/com/wwdz/ch/wx/service/ItemService.java
+1
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/util/StringUtil.java
ch-wx-api/src/main/java/com/wwdz/ch/wx/util/StringUtil.java
+36
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxItemController.java
...pi/src/main/java/com/wwdz/ch/wx/web/WxItemController.java
+2
-2
No files found.
ch-core/src/main/java/com/wwdz/ch/core/consts/CommConsts.java
View file @
7279c75e
...
...
@@ -25,5 +25,10 @@ public interface CommConsts {
/**
* 上传视频目录
*/
public
static
final
String
UPLOAD_PRE_VEDIO_DIRECTORY
=
"quanku/vedio/"
;
public
static
final
String
UPLOAD_PRE_VIDEO_DIRECTORY
=
"quanku/video/"
;
/**
* 上传微信小程序码目录
*/
public
static
final
String
UPLOAD_PRE_WXACODE_DIRECTORY
=
"quanku/wxacode/"
;
}
ch-core/src/main/java/com/wwdz/ch/core/storage/AliyunStorage.java
View file @
7279c75e
package
com.wwdz.ch.core.storage
;
import
java.io.InputStream
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.nio.file.Path
;
import
java.util.stream.Stream
;
import
com.aliyun.oss.OSSClient
;
import
com.aliyun.oss.model.ObjectMetadata
;
import
com.aliyun.oss.model.PutObjectRequest
;
import
com.aliyun.oss.model.PutObjectResult
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.UrlResource
;
import
com.aliyun.oss.OSSClient
;
import
com.aliyun.oss.model.ObjectMetadata
;
import
com.aliyun.oss.model.PutObjectRequest
;
import
com.aliyun.oss.model.PutObjectResult
;
import
java.io.InputStream
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.nio.file.Path
;
import
java.util.stream.Stream
;
public
class
AliyunStorage
implements
Storage
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
AliyunStorage
.
class
);
...
...
@@ -135,4 +134,9 @@ public class AliyunStorage implements Storage {
public
String
generateUrl
(
String
keyName
)
{
return
getBaseUrl
()
+
keyName
;
}
@Override
public
Object
checkFile
(
String
keyName
)
{
return
null
;
}
}
ch-core/src/main/java/com/wwdz/ch/core/storage/LocalStorage.java
View file @
7279c75e
...
...
@@ -101,4 +101,9 @@ public class LocalStorage implements Storage {
String
url
=
address
+
keyName
;
return
url
;
}
@Override
public
Object
checkFile
(
String
keyName
)
{
return
null
;
}
}
\ No newline at end of file
ch-core/src/main/java/com/wwdz/ch/core/storage/QiniuStorage.java
View file @
7279c75e
package
com.wwdz.ch.core.storage
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.nio.file.Path
;
import
java.util.Base64
;
import
java.util.stream.Stream
;
import
com.qiniu.common.QiniuException
;
import
com.qiniu.http.Response
;
import
com.qiniu.storage.BucketManager
;
import
com.qiniu.storage.Configuration
;
import
com.qiniu.storage.UploadManager
;
import
com.qiniu.storage.model.FileInfo
;
import
com.qiniu.util.Auth
;
import
com.wwdz.ch.core.consts.CommConsts
;
import
com.wwdz.ch.core.consts.MediaTypeEnum
;
import
com.wwdz.ch.core.util.MediaUtil
;
...
...
@@ -19,14 +17,15 @@ import org.apache.commons.logging.LogFactory;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.UrlResource
;
import
com.qiniu.common.QiniuException
;
import
com.qiniu.http.Response
;
import
com.qiniu.storage.BucketManager
;
import
com.qiniu.storage.Configuration
;
import
com.qiniu.storage.UploadManager
;
import
com.qiniu.util.Auth
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.nio.file.Path
;
import
java.util.Base64
;
import
java.util.stream.Stream
;
public
class
QiniuStorage
implements
Storage
{
...
...
@@ -201,6 +200,24 @@ public class QiniuStorage implements Storage {
return
endpoint
+
"/"
+
keyName
;
}
@Override
public
Object
checkFile
(
String
keyName
)
{
if
(
bucketManager
==
null
)
{
if
(
auth
==
null
)
{
auth
=
Auth
.
create
(
accessKey
,
secretKey
);
}
bucketManager
=
new
BucketManager
(
auth
,
new
Configuration
());
}
FileInfo
fileInfo
=
null
;
try
{
fileInfo
=
bucketManager
.
stat
(
bucketName
,
keyName
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
fileInfo
;
}
/**
* 原图片地址没尺寸信息的加上尺寸信息重新上传
...
...
ch-core/src/main/java/com/wwdz/ch/core/storage/Storage.java
View file @
7279c75e
...
...
@@ -34,4 +34,12 @@ public interface Storage {
void
delete
(
String
keyName
);
String
generateUrl
(
String
keyName
);
/**
* 获取文件
*
* @param keyName
* @return
*/
Object
checkFile
(
String
keyName
);
}
\ No newline at end of file
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FavoritesServiceImpl.java
View file @
7279c75e
...
...
@@ -18,6 +18,7 @@ import com.wwdz.ch.wx.entity.vo.AgentTranceResponseVo;
import
com.wwdz.ch.wx.entity.vo.FavoritesResponseVo
;
import
com.wwdz.ch.wx.entity.vo.ItemResponseVo
;
import
com.wwdz.ch.wx.service.FavoritesService
;
import
com.wwdz.ch.wx.util.StringUtil
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
...
...
@@ -276,12 +277,22 @@ public class FavoritesServiceImpl implements FavoritesService {
for
(
FavoritesItemsRelation
relation
:
relationPage
.
getList
())
{
ItemResponseVo
vo
=
new
ItemResponseVo
();
Item
item
=
itemDao
.
findDetails
(
relation
.
getItemId
());
// 设置基本信息
vo
.
setId
(
relation
.
getItemId
());
vo
.
setName
(
item
.
getName
());
vo
.
setImages
(
item
.
getImages
());
vo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
()
*
100
));
vo
.
setDetail
(
item
.
getDetail
());
// 设置价格
if
(
item
.
getPrice
()
%
100
==
0
)
{
vo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
()
/
100
));
}
else
{
vo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
().
doubleValue
()
/
100
));
}
vo
.
setPrice
(
StringUtil
.
formatAmount
(
vo
.
getPrice
()));
// 设置是否收藏或是否是自己发布的
vo
.
setIsCollected
(
favoritesItemsRelationDao
.
isCollected
(
dto
.
getUserId
(),
relation
.
getItemId
())
?
1
:
0
);
vo
.
setIsMine
(
userItemsRelationDao
.
isExisted
(
dto
.
getUserId
(),
item
.
getId
())
?
1
:
0
);
// 设置收藏数
long
count
=
favoritesItemsRelationDao
.
countByItemId
(
item
.
getId
());
if
(
item
.
getSourceType
().
equals
(
CommonEnum
.
SourceTypeEnum
.
USER_UPLOAD
.
getCode
()))
{
count
--;
...
...
@@ -291,26 +302,26 @@ public class FavoritesServiceImpl implements FavoritesService {
}
else
{
vo
.
setCollectCount
(
String
.
format
(
"%.1f"
,
(
double
)
count
/
1000
)
+
"k"
);
}
// 设置图片或视频
Map
<
String
,
Object
>
homePageMap
=
new
HashMap
<>();
String
[]
image
=
item
.
getImages
().
split
(
";"
);
homePageMap
.
put
(
"url"
,
image
[
0
]);
homePageMap
.
put
(
"type"
,
2
);
homePageMap
.
put
(
"width"
,
"0"
);
homePageMap
.
put
(
"height"
,
"0"
);
if
(
StringUtils
.
isNotBlank
(
item
.
getVideos
()))
{
String
[]
vedioImage
=
item
.
getVideos
().
split
(
";"
);
if
(
vedioImage
[
0
].
contains
(
","
))
{
String
[]
image
=
vedioImage
[
0
].
split
(
","
);
homePageMap
=
getImageMap
(
image
[
1
]);
homePageMap
.
put
(
"url"
,
image
[
1
]);
String
[]
video
=
vedioImage
[
0
].
split
(
","
);
homePageMap
=
getImageMap
(
video
[
1
]);
homePageMap
.
put
(
"url"
,
video
[
1
]);
homePageMap
.
put
(
"type"
,
1
);
}
}
else
{
String
[]
image
=
item
.
getImages
().
split
(
";"
);
if
(
image
[
0
].
contains
(
"_"
))
{
homePageMap
=
getImageMap
(
image
[
0
]);
homePageMap
.
put
(
"url"
,
image
[
0
]);
homePageMap
.
put
(
"type"
,
2
);
}
else
{
homePageMap
.
put
(
"type"
,
2
);
homePageMap
.
put
(
"url"
,
image
[
0
]);
homePageMap
.
put
(
"width"
,
"0"
);
homePageMap
.
put
(
"height"
,
"0"
);
}
}
vo
.
setHomePageImage
(
homePageMap
);
...
...
@@ -424,9 +435,11 @@ public class FavoritesServiceImpl implements FavoritesService {
.
map
(
UserItemsRelation:
:
getItemId
).
collect
(
Collectors
.
toList
());
List
<
Long
>
itemIds
=
dto
.
getItemIds
().
stream
()
.
filter
(
usersItemsIds:
:
contains
).
collect
(
Collectors
.
toList
());
CoinRequestDto
coinRequestDto
=
new
CoinRequestDto
();
coinRequestDto
.
setIds
(
itemIds
);
itemDao
.
deleteUserItems
(
coinRequestDto
);
if
(
CollectionUtils
.
isNotEmpty
(
itemIds
))
{
CoinRequestDto
coinRequestDto
=
new
CoinRequestDto
();
coinRequestDto
.
setIds
(
itemIds
);
itemDao
.
deleteUserItems
(
coinRequestDto
);
}
}
// 删除收藏册和钱币的关联
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FootPrintServiceImpl.java
View file @
7279c75e
...
...
@@ -12,6 +12,7 @@ import com.wwdz.ch.wx.entity.request.FootPrintRequestDto;
import
com.wwdz.ch.wx.entity.vo.FootPrintResponseVo
;
import
com.wwdz.ch.wx.entity.vo.ItemResponseVo
;
import
com.wwdz.ch.wx.service.FootPrintService
;
import
com.wwdz.ch.wx.util.StringUtil
;
import
com.xxdxxs.utils.DateUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -20,7 +21,6 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
...
...
@@ -71,13 +71,23 @@ public class FootPrintServiceImpl implements FootPrintService {
for
(
Footprint
footprint
:
list
)
{
Item
item
=
itemDao
.
findDetails
(
footprint
.
getItemId
());
ItemResponseVo
itemResponseVo
=
new
ItemResponseVo
();
// 设置基本信息
itemResponseVo
.
setId
(
footprint
.
getId
());
itemResponseVo
.
setItemId
(
item
.
getId
());
itemResponseVo
.
setName
(
item
.
getName
());
itemResponseVo
.
setImages
(
item
.
getImages
());
itemResponseVo
.
setDetail
(
item
.
getDetail
());
itemResponseVo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
()
/
100
));
// 设置价格
if
(
item
.
getPrice
()
%
100
==
0
)
{
itemResponseVo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
()
/
100
));
}
else
{
itemResponseVo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
().
doubleValue
()
/
100
));
}
itemResponseVo
.
setPrice
(
StringUtil
.
formatAmount
(
itemResponseVo
.
getPrice
()));
// 设置是否收藏或是否是自己发布的
itemResponseVo
.
setIsCollected
(
favoritesItemsRelationDao
.
isCollected
(
dto
.
getUserId
(),
footprint
.
getItemId
())
?
1
:
0
);
itemResponseVo
.
setIsMine
(
userItemsRelationDao
.
isExisted
(
dto
.
getUserId
(),
item
.
getId
())
?
1
:
0
);
// 设置收藏数
long
count
=
favoritesItemsRelationDao
.
countByItemId
(
item
.
getId
());
if
(
item
.
getSourceType
().
equals
(
CommonEnum
.
SourceTypeEnum
.
USER_UPLOAD
.
getCode
()))
{
count
--;
...
...
@@ -87,26 +97,26 @@ public class FootPrintServiceImpl implements FootPrintService {
}
else
{
itemResponseVo
.
setCollectCount
(
String
.
format
(
"%.1f"
,
(
double
)
count
/
1000
)
+
"k"
);
}
// 设置图片或视频
Map
<
String
,
Object
>
homePageMap
=
new
HashMap
<>();
String
[]
image
=
item
.
getImages
().
split
(
";"
);
homePageMap
.
put
(
"url"
,
image
[
0
]);
homePageMap
.
put
(
"type"
,
2
);
homePageMap
.
put
(
"width"
,
"0"
);
homePageMap
.
put
(
"height"
,
"0"
);
if
(
StringUtils
.
isNotBlank
(
item
.
getVideos
()))
{
String
[]
vedioImage
=
item
.
getVideos
().
split
(
";"
);
if
(
vedioImage
[
0
].
contains
(
","
))
{
String
[]
image
=
vedioImage
[
0
].
split
(
","
);
homePageMap
=
getImageMap
(
image
[
1
]);
homePageMap
.
put
(
"url"
,
image
[
1
]);
String
[]
video
=
vedioImage
[
0
].
split
(
","
);
homePageMap
=
getImageMap
(
video
[
1
]);
homePageMap
.
put
(
"url"
,
video
[
1
]);
homePageMap
.
put
(
"type"
,
1
);
}
}
else
{
String
[]
image
=
item
.
getImages
().
split
(
";"
);
if
(
image
[
0
].
contains
(
"_"
))
{
homePageMap
=
getImageMap
(
image
[
0
]);
homePageMap
.
put
(
"url"
,
image
[
0
]);
homePageMap
.
put
(
"type"
,
2
);
}
else
{
homePageMap
.
put
(
"type"
,
2
);
homePageMap
.
put
(
"url"
,
image
[
0
]);
homePageMap
.
put
(
"width"
,
"0"
);
homePageMap
.
put
(
"height"
,
"0"
);
}
}
itemResponseVo
.
setHomePageImage
(
homePageMap
);
...
...
@@ -190,18 +200,23 @@ public class FootPrintServiceImpl implements FootPrintService {
for
(
Footprint
footprint
:
list
)
{
Item
item
=
itemDao
.
findDetails
(
footprint
.
getItemId
());
ItemResponseVo
itemResponseVo
=
new
ItemResponseVo
();
// 设置基本信息
itemResponseVo
.
setId
(
footprint
.
getId
());
itemResponseVo
.
setItemId
(
item
.
getId
());
itemResponseVo
.
setName
(
item
.
getName
());
itemResponseVo
.
setImages
(
item
.
getImages
());
itemResponseVo
.
setDetail
(
item
.
getDetail
());
// 设置价格
if
(
item
.
getPrice
()
%
100
==
0
)
{
itemResponseVo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
()
/
100
));
}
else
{
itemResponseVo
.
setPrice
(
String
.
valueOf
(
item
.
getPrice
().
doubleValue
()
/
100
));
}
itemResponseVo
.
setPrice
(
StringUtil
.
formatAmount
(
itemResponseVo
.
getPrice
()));
// 设置是否收藏或是否是自己发布的
itemResponseVo
.
setIsCollected
(
favoritesItemsRelationDao
.
isCollected
(
dto
.
getUserId
(),
footprint
.
getItemId
())
?
1
:
0
);
itemResponseVo
.
setIsMine
(
userItemsRelationDao
.
isExisted
(
dto
.
getUserId
(),
item
.
getId
())
?
1
:
0
);
// 设置收藏数
long
count
=
favoritesItemsRelationDao
.
countByItemId
(
item
.
getId
());
if
(
item
.
getSourceType
().
equals
(
CommonEnum
.
SourceTypeEnum
.
USER_UPLOAD
.
getCode
()))
{
count
--;
...
...
@@ -211,26 +226,26 @@ public class FootPrintServiceImpl implements FootPrintService {
}
else
{
itemResponseVo
.
setCollectCount
(
String
.
format
(
"%.1f"
,
(
double
)
count
/
1000
)
+
"k"
);
}
// 设置图片或视频
Map
<
String
,
Object
>
homePageMap
=
new
HashMap
<>();
String
[]
image
=
item
.
getImages
().
split
(
";"
);
homePageMap
.
put
(
"url"
,
image
[
0
]);
homePageMap
.
put
(
"type"
,
2
);
homePageMap
.
put
(
"width"
,
"0"
);
homePageMap
.
put
(
"height"
,
"0"
);
if
(
StringUtils
.
isNotBlank
(
item
.
getVideos
()))
{
String
[]
vedioImage
=
item
.
getVideos
().
split
(
";"
);
if
(
vedioImage
[
0
].
contains
(
","
))
{
String
[]
image
=
vedioImage
[
0
].
split
(
","
);
homePageMap
=
getImageMap
(
image
[
1
]);
homePageMap
.
put
(
"url"
,
image
[
1
]);
String
[]
video
=
vedioImage
[
0
].
split
(
","
);
homePageMap
=
getImageMap
(
video
[
1
]);
homePageMap
.
put
(
"url"
,
video
[
1
]);
homePageMap
.
put
(
"type"
,
1
);
}
}
else
{
String
[]
image
=
item
.
getImages
().
split
(
";"
);
if
(
image
[
0
].
contains
(
"_"
))
{
homePageMap
=
getImageMap
(
image
[
0
]);
homePageMap
.
put
(
"url"
,
image
[
0
]);
homePageMap
.
put
(
"type"
,
2
);
}
else
{
homePageMap
.
put
(
"type"
,
2
);
homePageMap
.
put
(
"url"
,
image
[
0
]);
homePageMap
.
put
(
"width"
,
"0"
);
homePageMap
.
put
(
"height"
,
"0"
);
}
}
itemResponseVo
.
setHomePageImage
(
homePageMap
);
...
...
@@ -287,32 +302,6 @@ public class FootPrintServiceImpl implements FootPrintService {
}
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
Result
add
(
FootPrintRequestDto
dto
)
{
try
{
Footprint
footprint
=
footPrintDao
.
selectByUserIdItem
(
dto
.
getUserId
(),
dto
.
getItemId
());
Date
now
=
new
Date
();
if
(
Objects
.
isNull
(
footprint
))
{
Footprint
newVo
=
new
Footprint
();
newVo
.
setUserId
(
dto
.
getUserId
());
newVo
.
setItemId
(
dto
.
getItemId
());
newVo
.
setDeleted
(
false
);
newVo
.
setAddTime
(
now
);
newVo
.
setUpdateTime
(
now
);
footPrintDao
.
insert
(
newVo
);
}
else
{
footprint
.
setUpdateTime
(
now
);
footPrintDao
.
upateTime
(
footprint
);
}
return
Result
.
success
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"用户浏览藏品后添加或更新足迹失败"
,
e
);
TransactionAspectSupport
.
currentTransactionStatus
().
setRollbackOnly
();
return
Result
.
failed
();
}
}
private
Map
<
String
,
Object
>
getImageMap
(
String
image
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
String
[]
_image
=
image
.
split
(
"_"
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
View file @
7279c75e
This diff is collapsed.
Click to expand it.
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/WxLoginServiceImpl.java
View file @
7279c75e
...
...
@@ -6,7 +6,6 @@ import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import
cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo
;
import
com.alibaba.fastjson.JSON
;
import
com.wwdz.ch.core.util.OkHttpUtil
;
import
com.wwdz.ch.wx.constant.CacheCodeConstants
;
import
com.wwdz.ch.wx.entity.request.UserRequestDto
;
import
com.wwdz.ch.wx.service.WxLoginService
;
import
com.wwdz.ch.wx.util.RedisUtil
;
...
...
@@ -93,23 +92,32 @@ public class WxLoginServiceImpl implements WxLoginService {
public
String
getAccessToken
()
{
logger
.
info
(
"开始获取access_token----------------"
);
try
{
if
(
redisUtil
.
hasKey
(
CacheCodeConstants
.
WX_ACCESS_TOKEN
))
{
logger
.
info
(
"从redis获取access_token成功"
);
return
redisUtil
.
get
(
CacheCodeConstants
.
WX_ACCESS_TOKEN
).
toString
();
}
else
{
String
accessTokenUrl
=
String
.
format
(
GET_ACCESS_TOKEN_URL
,
appid
,
secret
);
String
res
=
OkHttpUtil
.
builder
().
url
(
accessTokenUrl
)
.
get
().
sync
();
logger
.
info
(
"获取access_token结果:"
+
res
);
if
(!
res
.
contains
(
"access_token"
))
{
logger
.
error
(
"获取accessToken出错,返回结果是:"
+
res
);
return
null
;
}
String
accessToken
=
JsonUtils
.
getValueByPath
(
res
,
"access_token"
);
String
expiresIn
=
JsonUtils
.
getValueByPath
(
res
,
"expires_in"
);
redisUtil
.
set
(
CacheCodeConstants
.
WX_ACCESS_TOKEN
,
accessToken
,
Long
.
parseLong
(
expiresIn
));
return
accessToken
;
// if (redisUtil.hasKey(CacheCodeConstants.WX_ACCESS_TOKEN)) {
// logger.info("从redis获取access_token成功");
// return redisUtil.get(CacheCodeConstants.WX_ACCESS_TOKEN).toString();
// } else {
// String accessTokenUrl = String.format(GET_ACCESS_TOKEN_URL, appid, secret);
// String res = OkHttpUtil.builder().url(accessTokenUrl)
// .get().sync();
// logger.info("获取access_token结果:" + res);
// if (!res.contains("access_token")) {
// logger.error("获取accessToken出错,返回结果是:" + res);
// return null;
// }
// String accessToken = JsonUtils.getValueByPath(res, "access_token");
// String expiresIn = JsonUtils.getValueByPath(res, "expires_in");
// redisUtil.set(CacheCodeConstants.WX_ACCESS_TOKEN, accessToken, Long.parseLong(expiresIn));
// return accessToken;
// }
String
accessTokenUrl
=
String
.
format
(
GET_ACCESS_TOKEN_URL
,
appid
,
secret
);
String
res
=
OkHttpUtil
.
builder
().
url
(
accessTokenUrl
)
.
get
().
sync
();
logger
.
info
(
"获取access_token结果:"
+
res
);
if
(!
res
.
contains
(
"access_token"
))
{
logger
.
error
(
"获取accessToken出错,返回结果是:"
+
res
);
return
null
;
}
return
JsonUtils
.
getValueByPath
(
res
,
"access_token"
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取access_token失败"
,
e
);
return
null
;
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/FootPrintService.java
View file @
7279c75e
...
...
@@ -7,5 +7,4 @@ public interface FootPrintService {
Result
listAll
(
FootPrintRequestDto
dto
);
Result
page
(
FootPrintRequestDto
dto
);
Result
delete
(
FootPrintRequestDto
dto
);
Result
add
(
FootPrintRequestDto
dto
);
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/ItemService.java
View file @
7279c75e
...
...
@@ -22,7 +22,7 @@ public interface ItemService {
Result
update
(
ItemRequestDto
dto
);
void
getWxacode
(
String
page
,
String
scene
,
HttpServletResponse
response
);
Result
getWxacode
(
String
page
,
String
scene
,
HttpServletResponse
response
);
Result
getWxLink
(
String
pageUrl
);
Result
uploadImage
(
MultipartFile
file
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/util/StringUtil.java
View file @
7279c75e
...
...
@@ -5,6 +5,12 @@ import java.util.Random;
public
class
StringUtil
{
private
static
final
String
ALLOWED_CHARACTERS
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
;
/**
* 获取随机任意长度的字符串
*
* @param length
* @return
*/
public
static
String
generateRandomString
(
int
length
)
{
Random
random
=
new
Random
();
StringBuilder
sb
=
new
StringBuilder
(
length
);
...
...
@@ -13,4 +19,34 @@ public class StringUtil {
}
return
sb
.
toString
();
}
/**
* 格式化金额
*
* @param amount
* @return
*/
public
static
String
formatAmount
(
String
amount
)
{
String
minMoney
=
null
;
String
intMoney
=
null
;
if
(
amount
.
contains
(
"."
))
{
minMoney
=
amount
.
substring
(
amount
.
indexOf
(
"."
));
intMoney
=
amount
.
substring
(
0
,
amount
.
indexOf
(
"."
));
}
else
{
intMoney
=
amount
;
}
StringBuilder
sb
=
new
StringBuilder
();
int
j
=
1
;
for
(
int
i
=
intMoney
.
length
()
-
1
;
i
>=
0
;
i
--)
{
sb
.
insert
(
0
,
intMoney
.
charAt
(
i
));
if
(
j
%
3
==
0
&&
i
!=
0
)
{
sb
.
insert
(
0
,
","
);
}
j
++;
}
if
(
amount
.
contains
(
"."
))
{
return
sb
+
minMoney
;
}
return
sb
.
toString
();
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxItemController.java
View file @
7279c75e
...
...
@@ -245,8 +245,8 @@ public class WxItemController {
@ApiOperation
(
value
=
"小程序码"
)
@GetMapping
(
"/getWxacode"
)
public
void
getWxacode
(
String
page
,
String
scene
,
HttpServletResponse
response
)
{
itemService
.
getWxacode
(
page
,
scene
,
response
);
public
Result
getWxacode
(
String
page
,
String
scene
,
HttpServletResponse
response
)
{
return
itemService
.
getWxacode
(
page
,
scene
,
response
);
}
@ApiOperation
(
value
=
"小程序链接"
)
...
...
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