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
0cb1a5ce
Commit
0cb1a5ce
authored
Aug 15, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
65dbfc3c
2290d191
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
173 additions
and
34 deletions
+173
-34
ch-dao/src/main/java/com/wwdz/ch/db/impl/ItemDaoImpl.java
ch-dao/src/main/java/com/wwdz/ch/db/impl/ItemDaoImpl.java
+1
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/request/ItemRequestDto.java
...in/java/com/wwdz/ch/wx/entity/request/ItemRequestDto.java
+1
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/vo/FavoritesResponseVo.java
...in/java/com/wwdz/ch/wx/entity/vo/FavoritesResponseVo.java
+2
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FavoritesServiceImpl.java
...c/main/java/com/wwdz/ch/wx/impl/FavoritesServiceImpl.java
+36
-4
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
+39
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
+6
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/WxLoginServiceImpl.java
...src/main/java/com/wwdz/ch/wx/impl/WxLoginServiceImpl.java
+32
-23
ch-wx-api/src/main/java/com/wwdz/ch/wx/interceptor/LoginInterceptor.java
...ain/java/com/wwdz/ch/wx/interceptor/LoginInterceptor.java
+1
-6
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/ItemService.java
...api/src/main/java/com/wwdz/ch/wx/service/ItemService.java
+2
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/UserTokenManager.java
...rc/main/java/com/wwdz/ch/wx/service/UserTokenManager.java
+25
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/WxLoginService.java
.../src/main/java/com/wwdz/ch/wx/service/WxLoginService.java
+2
-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
+26
-0
No files found.
ch-dao/src/main/java/com/wwdz/ch/db/impl/ItemDaoImpl.java
View file @
0cb1a5ce
...
@@ -47,6 +47,7 @@ public class ItemDaoImpl implements ItemDao {
...
@@ -47,6 +47,7 @@ public class ItemDaoImpl implements ItemDao {
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getId
(),
criteria
::
andIdEqualTo
);
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getId
(),
criteria
::
andIdEqualTo
);
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getName
(),
criteria
::
andNameLike
);
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getName
(),
criteria
::
andNameLike
);
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getCid
(),
criteria
::
andCidEqualTo
);
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getCid
(),
criteria
::
andCidEqualTo
);
JdbcHelper
.
ifPresent
(
coinRequestDto
.
getIds
(),
criteria:
:
andIdIn
);
return
itemMapper
.
selectByExample
(
example
);
return
itemMapper
.
selectByExample
(
example
);
}
}
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/request/ItemRequestDto.java
View file @
0cb1a5ce
...
@@ -31,4 +31,5 @@ public class ItemRequestDto implements Entity {
...
@@ -31,4 +31,5 @@ public class ItemRequestDto implements Entity {
private
String
price
;
private
String
price
;
private
Integer
page
;
private
Integer
page
;
private
Integer
size
;
private
Integer
size
;
private
String
path
;
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/entity/vo/FavoritesResponseVo.java
View file @
0cb1a5ce
...
@@ -4,6 +4,7 @@ import com.xxdxxs.entity.Entity;
...
@@ -4,6 +4,7 @@ import com.xxdxxs.entity.Entity;
import
lombok.Data
;
import
lombok.Data
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
@Data
@Data
public
class
FavoritesResponseVo
implements
Entity
{
public
class
FavoritesResponseVo
implements
Entity
{
...
@@ -14,6 +15,6 @@ public class FavoritesResponseVo implements Entity {
...
@@ -14,6 +15,6 @@ public class FavoritesResponseVo implements Entity {
private
Date
addTime
;
private
Date
addTime
;
private
Date
updateTime
;
private
Date
updateTime
;
private
Boolean
deleted
;
private
Boolean
deleted
;
private
String
images
;
private
List
<
String
>
images
;
private
long
count
;
private
long
count
;
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/FavoritesServiceImpl.java
View file @
0cb1a5ce
...
@@ -19,6 +19,7 @@ import com.wwdz.ch.wx.entity.vo.FavoritesResponseVo;
...
@@ -19,6 +19,7 @@ import com.wwdz.ch.wx.entity.vo.FavoritesResponseVo;
import
com.wwdz.ch.wx.entity.vo.ItemResponseVo
;
import
com.wwdz.ch.wx.entity.vo.ItemResponseVo
;
import
com.wwdz.ch.wx.service.FavoritesService
;
import
com.wwdz.ch.wx.service.FavoritesService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -26,7 +27,10 @@ import org.springframework.stereotype.Service;
...
@@ -26,7 +27,10 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Service
@Service
...
@@ -90,7 +94,26 @@ public class FavoritesServiceImpl implements FavoritesService {
...
@@ -90,7 +94,26 @@ public class FavoritesServiceImpl implements FavoritesService {
vo
.
setSort
(
favorites
.
getSort
());
vo
.
setSort
(
favorites
.
getSort
());
vo
.
setDeleted
(
favorites
.
getDeleted
());
vo
.
setDeleted
(
favorites
.
getDeleted
());
vo
.
setAddTime
(
favorites
.
getAddTime
());
vo
.
setAddTime
(
favorites
.
getAddTime
());
vo
.
setImages
(
favorites
.
getImages
());
vo
.
setImages
(
new
ArrayList
<>());
// 获取藏品的图片
List
<
FavoritesItemsRelation
>
favoritesItemsRelations
=
favoritesItemsRelationDao
.
listByFavoritesId
(
favorites
.
getId
(),
null
);
if
(
CollectionUtils
.
isNotEmpty
(
favoritesItemsRelations
))
{
CoinRequestDto
coinRequestDto
=
new
CoinRequestDto
();
coinRequestDto
.
setIds
(
favoritesItemsRelations
.
stream
()
.
map
(
FavoritesItemsRelation:
:
getItemId
).
collect
(
Collectors
.
toList
()));
List
<
Item
>
items
=
itemDao
.
findList
(
coinRequestDto
);
items
=
items
.
stream
().
filter
(
s
->
StringUtils
.
isNotBlank
(
s
.
getImages
())).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isNotEmpty
(
items
))
{
List
<
String
>
images
=
new
ArrayList
<>();
int
i
=
0
;
while
(
Objects
.
nonNull
(
items
.
get
(
i
))
&&
i
<
4
)
{
String
[]
image
=
items
.
get
(
i
).
getImages
().
split
(
";"
);
images
.
add
(
image
[
0
]);
i
++;
}
vo
.
setImages
(
images
);
}
}
vo
.
setUpdateTime
(
favorites
.
getUpdateTime
());
vo
.
setUpdateTime
(
favorites
.
getUpdateTime
());
vo
.
setCount
(
favoritesItemsRelationDao
.
countByFavoritesId
(
favorites
.
getId
()));
vo
.
setCount
(
favoritesItemsRelationDao
.
countByFavoritesId
(
favorites
.
getId
()));
agentTranceResponseVo
.
setDetail
(
vo
);
agentTranceResponseVo
.
setDetail
(
vo
);
...
@@ -119,7 +142,7 @@ public class FavoritesServiceImpl implements FavoritesService {
...
@@ -119,7 +142,7 @@ public class FavoritesServiceImpl implements FavoritesService {
vo
.
setSort
(
favorites
.
getSort
());
vo
.
setSort
(
favorites
.
getSort
());
vo
.
setDeleted
(
favorites
.
getDeleted
());
vo
.
setDeleted
(
favorites
.
getDeleted
());
vo
.
setAddTime
(
favorites
.
getAddTime
());
vo
.
setAddTime
(
favorites
.
getAddTime
());
vo
.
setImages
(
favorites
.
getImages
());
//
vo.setImages(favorites.getImages());
vo
.
setUpdateTime
(
favorites
.
getUpdateTime
());
vo
.
setUpdateTime
(
favorites
.
getUpdateTime
());
vo
.
setCount
(
favoritesItemsRelationDao
.
countByFavoritesId
(
favorites
.
getId
()));
vo
.
setCount
(
favoritesItemsRelationDao
.
countByFavoritesId
(
favorites
.
getId
()));
result
.
add
(
vo
);
result
.
add
(
vo
);
...
@@ -193,8 +216,17 @@ public class FavoritesServiceImpl implements FavoritesService {
...
@@ -193,8 +216,17 @@ public class FavoritesServiceImpl implements FavoritesService {
if
(
Objects
.
isNull
(
favorites
))
{
if
(
Objects
.
isNull
(
favorites
))
{
return
Result
.
failed
(
"数据异常,记录不存在"
);
return
Result
.
failed
(
"数据异常,记录不存在"
);
}
}
FavoritesResponseVo
vo
=
new
FavoritesResponseVo
();
vo
.
setId
(
favorites
.
getId
());
vo
.
setTitle
(
favorites
.
getTitle
());
vo
.
setDescription
(
favorites
.
getDescription
());
vo
.
setSort
(
favorites
.
getSort
());
vo
.
setDeleted
(
favorites
.
getDeleted
());
vo
.
setAddTime
(
favorites
.
getAddTime
());
vo
.
setUpdateTime
(
favorites
.
getUpdateTime
());
vo
.
setCount
(
favoritesItemsRelationDao
.
countByFavoritesId
(
favorites
.
getId
()));
logger
.
info
(
"【请求结束】查看收藏册详情成功"
);
logger
.
info
(
"【请求结束】查看收藏册详情成功"
);
return
Result
.
success
(
favorites
);
return
Result
.
success
(
vo
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"查看收藏册详情失败,原因:"
+
e
.
getMessage
(),
e
);
logger
.
error
(
"查看收藏册详情失败,原因:"
+
e
.
getMessage
(),
e
);
return
Result
.
failed
(
"查看收藏册详情失败"
);
return
Result
.
failed
(
"查看收藏册详情失败"
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
View file @
0cb1a5ce
...
@@ -11,6 +11,12 @@ import com.wwdz.ch.wx.entity.vo.AgentTranceResponseVo;
...
@@ -11,6 +11,12 @@ import com.wwdz.ch.wx.entity.vo.AgentTranceResponseVo;
import
com.wwdz.ch.wx.entity.vo.ItemResponseVo
;
import
com.wwdz.ch.wx.entity.vo.ItemResponseVo
;
import
com.wwdz.ch.wx.service.ItemService
;
import
com.wwdz.ch.wx.service.ItemService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -18,6 +24,8 @@ import org.springframework.stereotype.Service;
...
@@ -18,6 +24,8 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.util.*
;
import
java.util.*
;
@Service
@Service
...
@@ -43,6 +51,10 @@ public class ItemServiceImpl implements ItemService {
...
@@ -43,6 +51,10 @@ public class ItemServiceImpl implements ItemService {
CoinRequestDto
coinRequestDto
=
new
CoinRequestDto
();
CoinRequestDto
coinRequestDto
=
new
CoinRequestDto
();
coinRequestDto
.
setPage
(
dto
.
getPage
());
coinRequestDto
.
setPage
(
dto
.
getPage
());
coinRequestDto
.
setLimit
(
dto
.
getSize
());
coinRequestDto
.
setLimit
(
dto
.
getSize
());
coinRequestDto
.
setIsExcluded
(
1
);
if
(
StringUtils
.
isNotBlank
(
dto
.
getName
()))
{
coinRequestDto
.
setName
(
dto
.
getName
());
}
PageInfo
<
Item
>
page
=
itemDao
.
findByPage
(
coinRequestDto
);
PageInfo
<
Item
>
page
=
itemDao
.
findByPage
(
coinRequestDto
);
PageInfo
<
AgentTranceResponseVo
>
result
=
new
PageInfo
<>();
PageInfo
<
AgentTranceResponseVo
>
result
=
new
PageInfo
<>();
result
.
setPageNum
(
page
.
getPageNum
());
result
.
setPageNum
(
page
.
getPageNum
());
...
@@ -194,6 +206,10 @@ public class ItemServiceImpl implements ItemService {
...
@@ -194,6 +206,10 @@ public class ItemServiceImpl implements ItemService {
if
(
dto
.
getUserId
().
equals
(
0L
))
{
if
(
dto
.
getUserId
().
equals
(
0L
))
{
return
Result
.
failed
(
"您尚未登录,请先登录"
);
return
Result
.
failed
(
"您尚未登录,请先登录"
);
}
}
// 判断是否收藏过
if
(
favoritesItemsRelationDao
.
isCollected
(
dto
.
getUserId
(),
dto
.
getId
()))
{
Result
.
failed
(
"您已经收藏过该藏品"
);
}
// 查找默认收藏册
// 查找默认收藏册
Favorites
favorites
=
favoritesDao
.
defaultFavorites
(
dto
.
getUserId
());
Favorites
favorites
=
favoritesDao
.
defaultFavorites
(
dto
.
getUserId
());
if
(
Objects
.
isNull
(
favorites
))
{
if
(
Objects
.
isNull
(
favorites
))
{
...
@@ -268,4 +284,27 @@ public class ItemServiceImpl implements ItemService {
...
@@ -268,4 +284,27 @@ public class ItemServiceImpl implements ItemService {
return
Result
.
failed
(
"修改藏品失败"
);
return
Result
.
failed
(
"修改藏品失败"
);
}
}
}
}
@Override
public
Result
test
()
{
try
{
String
url
=
"https://cdn.wanwudezhi.com/static/web-static/video/53596700878a572ca4fae35243aaa819.mp4?vframe/jpg/offset/0"
;
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
HttpGet
get
=
new
HttpGet
(
url
);
HttpResponse
response
=
httpClient
.
execute
(
get
);
HttpEntity
entity
=
response
.
getEntity
();
InputStream
inputStream
=
entity
.
getContent
();
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
4096
];
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
outputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
byte
[]
bytes
=
outputStream
.
toByteArray
();
return
Result
.
success
(
Base64
.
getEncoder
().
encodeToString
(
bytes
));
}
catch
(
Exception
e
)
{
logger
.
error
(
"error"
,
e
);
return
Result
.
failed
(
e
.
getMessage
());
}
}
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
View file @
0cb1a5ce
...
@@ -126,6 +126,9 @@ public class UserServiceImpl implements UserService {
...
@@ -126,6 +126,9 @@ public class UserServiceImpl implements UserService {
}
}
}
}
// 先登出其他
userTokenManager
.
removeToken
(
user
.
getId
());
// token
// token
UserToken
userToken
=
null
;
UserToken
userToken
=
null
;
try
{
try
{
...
@@ -248,6 +251,9 @@ public class UserServiceImpl implements UserService {
...
@@ -248,6 +251,9 @@ public class UserServiceImpl implements UserService {
}
}
}
}
// 先登出其他
userTokenManager
.
removeToken
(
user
.
getId
());
// token
// token
UserToken
userToken
=
null
;
UserToken
userToken
=
null
;
try
{
try
{
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/WxLoginServiceImpl.java
View file @
0cb1a5ce
...
@@ -11,7 +11,7 @@ import com.wwdz.ch.wx.entity.request.UserRequestDto;
...
@@ -11,7 +11,7 @@ import com.wwdz.ch.wx.entity.request.UserRequestDto;
import
com.wwdz.ch.wx.service.WxLoginService
;
import
com.wwdz.ch.wx.service.WxLoginService
;
import
com.wwdz.ch.wx.util.RedisUtil
;
import
com.wwdz.ch.wx.util.RedisUtil
;
import
com.xxdxxs.utils.JsonUtils
;
import
com.xxdxxs.utils.JsonUtils
;
import
com.xxdxxs.utils
.StringUtils
;
import
org.apache.commons.lang3
.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -32,6 +32,7 @@ public class WxLoginServiceImpl implements WxLoginService {
...
@@ -32,6 +32,7 @@ public class WxLoginServiceImpl implements WxLoginService {
private
static
final
String
GET_ACCESS_TOKEN_URL
=
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"
;
private
static
final
String
GET_ACCESS_TOKEN_URL
=
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"
;
private
static
final
String
GET_PHONE_URL
=
"https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s"
;
private
static
final
String
GET_PHONE_URL
=
"https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s"
;
private
static
final
String
GET_WXACODE_URL
=
"https://api.weixin.qq.com/wxa/getwxacode?access_token=%s"
;
@Autowired
@Autowired
private
WxMaService
wxMaService
;
private
WxMaService
wxMaService
;
...
@@ -43,27 +44,9 @@ public class WxLoginServiceImpl implements WxLoginService {
...
@@ -43,27 +44,9 @@ public class WxLoginServiceImpl implements WxLoginService {
public
String
getPhone
(
UserRequestDto
dto
)
{
public
String
getPhone
(
UserRequestDto
dto
)
{
String
phone
=
""
;
String
phone
=
""
;
if
(
dto
.
getType
()
==
1
)
{
if
(
dto
.
getType
()
==
1
)
{
logger
.
info
(
"开始获取access_token----------------"
);
String
accessToken
=
getAccessToken
();
String
accessToken
=
""
;
if
(
StringUtils
.
isBlank
(
accessToken
))
{
if
(
redisUtil
.
hasKey
(
CacheCodeConstants
.
WX_ACCESS_TOKEN
))
{
return
"false"
;
accessToken
=
redisUtil
.
get
(
CacheCodeConstants
.
WX_ACCESS_TOKEN
).
toString
();
}
else
{
try
{
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
"false"
;
}
accessToken
=
JsonUtils
.
getValueByPath
(
res
,
"access_token"
);
String
expiresIn
=
JsonUtils
.
getValueByPath
(
res
,
"expires_in"
);
redisUtil
.
set
(
CacheCodeConstants
.
WX_ACCESS_TOKEN
,
accessToken
,
Long
.
parseLong
(
expiresIn
));
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取accessToken出错"
,
e
);
return
"false"
;
}
}
}
logger
.
info
(
"开始获取phone-----------------------"
);
logger
.
info
(
"开始获取phone-----------------------"
);
...
@@ -90,7 +73,7 @@ public class WxLoginServiceImpl implements WxLoginService {
...
@@ -90,7 +73,7 @@ public class WxLoginServiceImpl implements WxLoginService {
logger
.
error
(
"获取用户登录信息失败"
,
e
);
logger
.
error
(
"获取用户登录信息失败"
,
e
);
return
"sessionFalse"
;
return
"sessionFalse"
;
}
}
if
(
StringUtils
.
is
Empty
(
sessionKey
))
{
if
(
StringUtils
.
is
Blank
(
sessionKey
))
{
logger
.
error
(
"微信登录,调用官方接口失败:{}"
,
dto
.
getCode
());
logger
.
error
(
"微信登录,调用官方接口失败:{}"
,
dto
.
getCode
());
return
"sessionFalse"
;
return
"sessionFalse"
;
}
}
...
@@ -107,4 +90,30 @@ public class WxLoginServiceImpl implements WxLoginService {
...
@@ -107,4 +90,30 @@ public class WxLoginServiceImpl implements WxLoginService {
}
}
return
phone
;
return
phone
;
}
}
@Override
public
String
getAccessToken
()
{
logger
.
info
(
"开始获取access_token----------------"
);
try
{
if
(
redisUtil
.
hasKey
(
CacheCodeConstants
.
WX_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
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取access_token失败"
,
e
);
return
null
;
}
}
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/interceptor/LoginInterceptor.java
View file @
0cb1a5ce
...
@@ -14,7 +14,6 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -14,7 +14,6 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Objects
;
@Component
@Component
public
class
LoginInterceptor
implements
HandlerInterceptor
{
public
class
LoginInterceptor
implements
HandlerInterceptor
{
...
@@ -32,12 +31,8 @@ public class LoginInterceptor implements HandlerInterceptor {
...
@@ -32,12 +31,8 @@ public class LoginInterceptor implements HandlerInterceptor {
logger
.
info
(
"请求头名称:"
+
JSON
.
toJSONString
(
request
.
getHeaderNames
()));
logger
.
info
(
"请求头名称:"
+
JSON
.
toJSONString
(
request
.
getHeaderNames
()));
String
token
=
request
.
getHeader
(
"Authorization"
);
String
token
=
request
.
getHeader
(
"Authorization"
);
logger
.
info
(
"token的值是:"
+
token
);
logger
.
info
(
"token的值是:"
+
token
);
if
(
StringUtils
.
isBlank
(
token
))
{
return
true
;
}
if
(
StringUtils
.
isNotBlank
(
token
))
{
if
(
StringUtils
.
isNotBlank
(
token
))
{
Long
userId
=
userTokenManager
.
getUserId
(
token
);
if
(
userTokenManager
.
checkLogin
(
token
))
{
if
(
Objects
.
nonNull
(
userId
))
{
return
true
;
return
true
;
}
}
}
}
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/ItemService.java
View file @
0cb1a5ce
...
@@ -17,4 +17,6 @@ public interface ItemService {
...
@@ -17,4 +17,6 @@ public interface ItemService {
Result
cancel
(
ItemRequestDto
dto
);
Result
cancel
(
ItemRequestDto
dto
);
Result
update
(
ItemRequestDto
dto
);
Result
update
(
ItemRequestDto
dto
);
Result
test
();
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/UserTokenManager.java
View file @
0cb1a5ce
...
@@ -4,12 +4,14 @@ import com.google.gson.Gson;
...
@@ -4,12 +4,14 @@ import com.google.gson.Gson;
import
com.wwdz.ch.core.util.CharUtil
;
import
com.wwdz.ch.core.util.CharUtil
;
import
com.wwdz.ch.wx.dao.UserToken
;
import
com.wwdz.ch.wx.dao.UserToken
;
import
com.wwdz.ch.wx.util.RedisUtil
;
import
com.wwdz.ch.wx.util.RedisUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Objects
;
/**
/**
* 维护用户token
* 维护用户token
...
@@ -46,6 +48,29 @@ public class UserTokenManager {
...
@@ -46,6 +48,29 @@ public class UserTokenManager {
return
userToken
.
getUserId
();
return
userToken
.
getUserId
();
}
}
public
boolean
checkLogin
(
String
token
)
{
String
key
=
TOKEN_PREFIX
+
token
;
Object
tokenObj
=
redisUtil
.
get
(
key
);
if
(
Objects
.
isNull
(
tokenObj
))
{
return
false
;
}
UserToken
userToken
=
gson
.
fromJson
(
tokenObj
.
toString
(),
UserToken
.
class
);
if
(
userToken
.
getExpireTime
().
isBefore
(
LocalDateTime
.
now
()))
{
redisUtil
.
del
(
key
);
String
idKey
=
TOKEN_ID_PREFIX
+
userToken
.
getUserId
();
redisUtil
.
del
(
idKey
);
return
false
;
}
String
idKey
=
TOKEN_ID_PREFIX
+
userToken
.
getUserId
();
Object
idObj
=
redisUtil
.
get
(
idKey
);
if
(
Objects
.
isNull
(
idObj
))
{
return
false
;
}
UserToken
idUserToken
=
gson
.
fromJson
(
idObj
.
toString
(),
UserToken
.
class
);
String
idToken
=
idUserToken
.
getToken
();
return
StringUtils
.
equals
(
token
,
idToken
);
}
public
UserToken
generateToken
(
Long
id
)
{
public
UserToken
generateToken
(
Long
id
)
{
UserToken
userToken
=
null
;
UserToken
userToken
=
null
;
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/service/WxLoginService.java
View file @
0cb1a5ce
...
@@ -4,4 +4,6 @@ import com.wwdz.ch.wx.entity.request.UserRequestDto;
...
@@ -4,4 +4,6 @@ import com.wwdz.ch.wx.entity.request.UserRequestDto;
public
interface
WxLoginService
{
public
interface
WxLoginService
{
String
getPhone
(
UserRequestDto
dto
);
String
getPhone
(
UserRequestDto
dto
);
String
getAccessToken
();
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxItemController.java
View file @
0cb1a5ce
...
@@ -4,6 +4,7 @@ import com.wwdz.ch.core.type.Result;
...
@@ -4,6 +4,7 @@ import com.wwdz.ch.core.type.Result;
import
com.wwdz.ch.wx.entity.request.ItemRequestDto
;
import
com.wwdz.ch.wx.entity.request.ItemRequestDto
;
import
com.wwdz.ch.wx.entity.request.KlDataRequestDto
;
import
com.wwdz.ch.wx.entity.request.KlDataRequestDto
;
import
com.wwdz.ch.wx.service.ItemService
;
import
com.wwdz.ch.wx.service.ItemService
;
import
com.wwdz.ch.wx.service.WxLoginService
;
import
com.xxdxxs.utils.JsonUtils
;
import
com.xxdxxs.utils.JsonUtils
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
@@ -15,6 +16,9 @@ import org.springframework.web.bind.annotation.RequestBody;
...
@@ -15,6 +16,9 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.HashMap
;
import
java.util.Map
;
@RestController
@RestController
@RequestMapping
(
"/wx/item"
)
@RequestMapping
(
"/wx/item"
)
public
class
WxItemController
{
public
class
WxItemController
{
...
@@ -22,6 +26,8 @@ public class WxItemController {
...
@@ -22,6 +26,8 @@ public class WxItemController {
@Autowired
@Autowired
private
ItemService
itemService
;
private
ItemService
itemService
;
@Autowired
private
WxLoginService
wxLoginService
;
@ApiOperation
(
value
=
"分页查询"
)
@ApiOperation
(
value
=
"分页查询"
)
@PostMapping
(
"/page"
)
@PostMapping
(
"/page"
)
...
@@ -29,6 +35,7 @@ public class WxItemController {
...
@@ -29,6 +35,7 @@ public class WxItemController {
String
json
=
klDataRequestDto
.
getKl_data
();
String
json
=
klDataRequestDto
.
getKl_data
();
logger
.
info
(
"【请求开始】藏品列表首页,请求参数,kl_data:{}"
,
json
);
logger
.
info
(
"【请求开始】藏品列表首页,请求参数,kl_data:{}"
,
json
);
String
userId
=
JsonUtils
.
getValueByPath
(
json
,
"userId"
);
String
userId
=
JsonUtils
.
getValueByPath
(
json
,
"userId"
);
String
name
=
JsonUtils
.
getValueByPath
(
json
,
"name"
);
String
page
=
JsonUtils
.
getValueByPath
(
json
,
"page"
);
String
page
=
JsonUtils
.
getValueByPath
(
json
,
"page"
);
String
size
=
JsonUtils
.
getValueByPath
(
json
,
"size"
);
String
size
=
JsonUtils
.
getValueByPath
(
json
,
"size"
);
if
(
StringUtils
.
isBlank
(
page
))
{
if
(
StringUtils
.
isBlank
(
page
))
{
...
@@ -45,6 +52,7 @@ public class WxItemController {
...
@@ -45,6 +52,7 @@ public class WxItemController {
}
}
dto
.
setPage
(
Integer
.
parseInt
(
page
));
dto
.
setPage
(
Integer
.
parseInt
(
page
));
dto
.
setSize
(
Integer
.
parseInt
(
size
));
dto
.
setSize
(
Integer
.
parseInt
(
size
));
dto
.
setName
(
name
);
return
itemService
.
page
(
dto
);
return
itemService
.
page
(
dto
);
}
}
...
@@ -202,4 +210,22 @@ public class WxItemController {
...
@@ -202,4 +210,22 @@ public class WxItemController {
dto
.
setId
(
Long
.
parseLong
(
id
));
dto
.
setId
(
Long
.
parseLong
(
id
));
return
itemService
.
cancel
(
dto
);
return
itemService
.
cancel
(
dto
);
}
}
@ApiOperation
(
value
=
"小程序授权码"
)
@PostMapping
(
"/getAccessToken"
)
public
Result
getAccessToken
()
{
String
accessToken
=
wxLoginService
.
getAccessToken
();
if
(
StringUtils
.
isBlank
(
accessToken
))
{
return
Result
.
failed
(
"获取access_token失败"
);
}
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"access_token"
,
accessToken
);
return
Result
.
success
(
map
);
}
@ApiOperation
(
value
=
"小程序授权码"
)
@PostMapping
(
"/test"
)
public
Result
test
()
{
return
itemService
.
test
();
}
}
}
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