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
0a01f627
Commit
0a01f627
authored
Aug 24, 2023
by
shiyu
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
c3a5f553
3d65d66d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
25 deletions
+51
-25
ch-wx-api/src/main/java/com/wwdz/ch/wx/constant/CacheCodeConstants.java
...main/java/com/wwdz/ch/wx/constant/CacheCodeConstants.java
+13
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
+6
-6
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
+30
-16
ch-wx-api/src/main/java/com/wwdz/ch/wx/manager/UserTokenManager.java
...rc/main/java/com/wwdz/ch/wx/manager/UserTokenManager.java
+2
-2
No files found.
ch-wx-api/src/main/java/com/wwdz/ch/wx/constant/CacheCodeConstants.java
View file @
0a01f627
...
...
@@ -7,7 +7,19 @@ public class CacheCodeConstants {
/**
* 微信接口调用凭证access_token
*/
public
static
final
String
WX_ACCESS_TOKEN
=
"quanku:wx:access_token"
;
public
static
final
String
WX_ACCESS_TOKEN
=
"cjxc:wx:access_token"
;
/**
* 缓存用户登录验证码
* <p>{0}:手机号</p>
*/
public
static
final
String
USER_LOGIN_SMS_KEY
=
"cjxc:wx:user:sms:login:{0}"
;
/**
* 缓存用户修改密码验证码
* <p>{0}:手机号</p>
*/
public
static
final
String
USER_UPDATE_SMS_KEY
=
"cjxc:wx:user:sms:update:{0}"
;
/**
* 短信验证码类型枚举
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
View file @
0a01f627
...
...
@@ -2,10 +2,7 @@ package com.wwdz.ch.wx.impl;
import
com.github.pagehelper.PageInfo
;
import
com.qiniu.storage.model.FileInfo
;
import
com.wwdz.ch.core.consts.CommConsts
;
import
com.wwdz.ch.core.consts.CommonEnum
;
import
com.wwdz.ch.core.consts.MediaTypeEnum
;
import
com.wwdz.ch.core.consts.ResultCode
;
import
com.wwdz.ch.core.consts.*
;
import
com.wwdz.ch.core.storage.QiniuStorage
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.MediaUtil
;
...
...
@@ -74,7 +71,7 @@ public class ItemServiceImpl implements ItemService {
if
(
StringUtils
.
isNotBlank
(
dto
.
getName
()))
{
EsSearchRequestDto
esSearchRequestDto
=
new
EsSearchRequestDto
();
esSearchRequestDto
.
setPage
(
1
);
esSearchRequestDto
.
setSize
(
1000
);
esSearchRequestDto
.
setSize
(
1000
0
);
esSearchRequestDto
.
setContent
(
dto
.
getName
());
EsPageInfo
esPageInfo
=
itemEsDao
.
findList
(
esSearchRequestDto
);
if
(
Objects
.
nonNull
(
esPageInfo
)
&&
CollectionUtils
.
isNotEmpty
(
esPageInfo
.
getDataList
()))
{
...
...
@@ -93,7 +90,9 @@ public class ItemServiceImpl implements ItemService {
if
(
name
.
length
()
>
15
)
{
name
=
name
.
substring
(
0
,
15
);
}
if
(
name
.
contains
(
dto
.
getName
()))
{
set
.
add
(
name
);
}
});
// 取16个名称
if
(
set
.
size
()
<=
16
)
{
...
...
@@ -204,6 +203,7 @@ public class ItemServiceImpl implements ItemService {
item
.
setSourceType
(
CommonEnum
.
SourceTypeEnum
.
USER_UPLOAD
.
getCode
());
item
.
setSource
(
CommonEnum
.
SourceEnum
.
USER_UPLOAD
.
getCode
());
item
.
setIsDeleted
(
false
);
item
.
setKind
(
ItemKindEnum
.
COIN
.
getCode
());
itemDao
.
insert
(
item
);
// 新增用户和藏品关联记录
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/UserServiceImpl.java
View file @
0a01f627
package
com.wwdz.ch.wx.impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.wwdz.ch.core.captcha.CaptchaCodeManager
;
import
com.wwdz.ch.core.consts.ResultCode
;
import
com.wwdz.ch.core.notify.AliSmsSender
;
import
com.wwdz.ch.core.notify.NotifyService
;
...
...
@@ -14,16 +13,17 @@ import com.wwdz.ch.core.util.UUID;
import
com.wwdz.ch.core.util.bcrypt.BCryptPasswordEncoder
;
import
com.wwdz.ch.db.dao.UserDao
;
import
com.wwdz.ch.db.domain.User
;
import
com.wwdz.ch.db.dto.request.FavoritesRequestDto
;
import
com.wwdz.ch.wx.constant.CacheCodeConstants
;
import
com.wwdz.ch.wx.dao.UserInfo
;
import
com.wwdz.ch.wx.dao.UserToken
;
import
com.wwdz.ch.db.dto.request.FavoritesRequestDto
;
import
com.wwdz.ch.wx.entity.request.UserRequestDto
;
import
com.wwdz.ch.wx.manager.UserTokenManager
;
import
com.wwdz.ch.wx.service.FavoritesService
;
import
com.wwdz.ch.wx.service.UserService
;
import
com.wwdz.ch.wx.manager.UserTokenManager
;
import
com.wwdz.ch.wx.service.WxLoginService
;
import
com.wwdz.ch.wx.util.IpUtil
;
import
com.wwdz.ch.wx.util.RedisUtil
;
import
com.wwdz.ch.wx.util.StringUtil
;
import
com.wwdz.ch.wx.util.WxResponseCode
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -37,6 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
javax.servlet.http.HttpServletRequest
;
import
java.text.MessageFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
...
...
@@ -58,6 +59,8 @@ public class UserServiceImpl implements UserService {
private
FavoritesService
favoritesService
;
@Autowired
private
WxLoginService
wxLoginService
;
@Autowired
private
RedisUtil
redisUtil
;
@Value
(
"${avatar-url}"
)
private
String
avatarUrl
;
...
...
@@ -181,6 +184,16 @@ public class UserServiceImpl implements UserService {
logger
.
error
(
"请求验证码出错:{}"
,
WxResponseCode
.
AUTH_CAPTCHA_UNSUPPORT
.
desc
());
return
Result
.
failed
(
WxResponseCode
.
AUTH_CAPTCHA_UNSUPPORT
.
desc
());
}
String
key
=
""
;
if
(
dto
.
getSmsType
().
equals
(
CacheCodeConstants
.
SmsTypeEnum
.
LOGIN
.
getCode
()))
{
key
=
MessageFormat
.
format
(
CacheCodeConstants
.
USER_LOGIN_SMS_KEY
,
dto
.
getMobile
());
}
else
{
key
=
MessageFormat
.
format
(
CacheCodeConstants
.
USER_UPDATE_SMS_KEY
,
dto
.
getMobile
());
}
if
(
redisUtil
.
hasKey
(
key
))
{
return
Result
.
failed
(
"验证码请求过于频繁"
);
}
String
activeProfile
=
applicationContext
.
getEnvironment
().
getActiveProfiles
()[
0
];
String
code
=
"123456"
;
if
(!
StringUtils
.
equals
(
"dev"
,
activeProfile
))
{
...
...
@@ -190,16 +203,11 @@ public class UserServiceImpl implements UserService {
code
=
CharUtil
.
getRandomNum
(
6
);
SmsResult
smsResult
=
aliSmsSender
.
sendWithTemplate
(
dto
.
getMobile
(),
code
);
if
(
smsResult
!=
null
)
{
logger
.
info
(
"*****
腾讯
云短信发送->请求验证码,短信发送结果:{}"
,
JSONObject
.
toJSONString
(
smsResult
));
logger
.
info
(
"*****
阿里
云短信发送->请求验证码,短信发送结果:{}"
,
JSONObject
.
toJSONString
(
smsResult
));
}
}
boolean
successful
=
CaptchaCodeManager
.
addToCache
(
dto
.
getSmsType
()
+
dto
.
getMobile
(),
code
,
1
);
if
(!
successful
)
{
logger
.
error
(
"请求验证码出错:{}"
,
WxResponseCode
.
AUTH_CAPTCHA_FREQUENCY
.
desc
());
return
Result
.
failed
(
WxResponseCode
.
AUTH_CAPTCHA_FREQUENCY
.
desc
());
}
redisUtil
.
set
(
key
,
code
,
60
);
logger
.
info
(
"【请求结束】请求验证码成功"
);
return
Result
.
success
();
}
catch
(
Exception
e
)
{
...
...
@@ -212,11 +220,12 @@ public class UserServiceImpl implements UserService {
@Override
public
Result
loginByMobile
(
UserRequestDto
dto
,
HttpServletRequest
request
)
{
try
{
String
mobileCode
=
CaptchaCodeManager
.
getCachedCaptcha
(
CacheCodeConstants
.
SmsTypeEnum
.
LOGIN
.
getCode
()
+
dto
.
getMobile
());
if
(
StringUtils
.
isBlank
(
mobileCode
))
{
String
key
=
MessageFormat
.
format
(
CacheCodeConstants
.
USER_LOGIN_SMS_KEY
,
dto
.
getMobile
());
Object
object
=
redisUtil
.
get
(
key
);
if
(
Objects
.
isNull
(
object
))
{
return
Result
.
failed
(
"验证码已过期"
);
}
if
(!
StringUtils
.
equals
(
dto
.
getSmsCode
(),
mobileCode
))
{
if
(!
StringUtils
.
equals
(
dto
.
getSmsCode
(),
object
.
toString
()
))
{
return
Result
.
failed
(
"验证码不正确"
);
}
...
...
@@ -294,6 +303,8 @@ public class UserServiceImpl implements UserService {
result
.
put
(
"userInfo"
,
userInfo
);
logger
.
info
(
"【请求结束】手机号登录,响应结果:{}"
,
JSONObject
.
toJSONString
(
result
));
// 清除验证码缓存
redisUtil
.
del
(
key
);
return
Result
.
success
(
result
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"手机号登录失败"
,
e
);
...
...
@@ -392,11 +403,12 @@ public class UserServiceImpl implements UserService {
if
(!
StringUtils
.
equals
(
user
.
getMobile
(),
dto
.
getBeforeMobile
()))
{
return
Result
.
failed
(
"原手机号码不正确"
);
}
String
mobileCode
=
CaptchaCodeManager
.
getCachedCaptcha
(
CacheCodeConstants
.
SmsTypeEnum
.
UPDATE
.
getCode
()
+
dto
.
getAfterMobile
());
if
(
StringUtils
.
isBlank
(
mobileCode
))
{
String
key
=
MessageFormat
.
format
(
CacheCodeConstants
.
USER_UPDATE_SMS_KEY
,
dto
.
getAfterMobile
());
Object
object
=
redisUtil
.
get
(
key
);
if
(
Objects
.
isNull
(
object
))
{
return
Result
.
failed
(
"验证码已过期"
);
}
if
(!
StringUtils
.
equals
(
dto
.
getSmsCode
(),
mobileCode
))
{
if
(!
StringUtils
.
equals
(
dto
.
getSmsCode
(),
object
.
toString
()
))
{
return
Result
.
failed
(
"验证码不正确"
);
}
if
(
userDao
.
isExistedByMobile
(
dto
.
getBeforeMobile
(),
dto
.
getAfterMobile
()))
{
...
...
@@ -405,6 +417,8 @@ public class UserServiceImpl implements UserService {
user
.
setMobile
(
dto
.
getAfterMobile
());
userDao
.
updateById
(
user
);
logger
.
info
(
"【请求结束】用户修改手机号成功"
);
// 清除验证码缓存
redisUtil
.
del
(
key
);
return
Result
.
success
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"用户修改手机号失败"
,
e
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/manager/UserTokenManager.java
View file @
0a01f627
...
...
@@ -24,9 +24,9 @@ public class UserTokenManager {
private
Gson
gson
=
new
Gson
();
private
static
final
String
TOKEN_PREFIX
=
"token_prefix:"
;
private
static
final
String
TOKEN_PREFIX
=
"
cjxc:wx:token:
token_prefix:"
;
private
static
final
String
TOKEN_ID_PREFIX
=
"token_id_prefix:"
;
private
static
final
String
TOKEN_ID_PREFIX
=
"
cjxc:wx:token:
token_id_prefix:"
;
private
static
Map
<
String
,
UserToken
>
tokenMap
=
new
HashMap
<>();
private
static
Map
<
Long
,
UserToken
>
idMap
=
new
HashMap
<>();
private
static
long
SURVIVAL_TIME
=
86400
;
...
...
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