Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
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
head_group
xyqb-user2
Commits
68105c03
Commit
68105c03
authored
Aug 29, 2017
by
Java—红包—徐 然
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复服务器5次验证码错误 需要重新获取验证码
parent
7ac26e5e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
2 deletions
+37
-2
SmsController.java
...uantgroup/xyqb/controller/internal/sms/SmsController.java
+19
-2
UserController.java
...ntgroup/xyqb/controller/internal/user/UserController.java
+18
-0
No files found.
src/main/java/cn/quantgroup/xyqb/controller/internal/sms/SmsController.java
View file @
68105c03
...
...
@@ -148,6 +148,7 @@ public class SmsController implements IBaseController {
//smsService.getSmsSender().sendConfirmableMessage(confirmableMsg);
smsService
.
getSmsSender
().
sendMsg
(
message
);
redisTemplate
.
opsForValue
().
set
(
key
,
uniqueId
+
":"
+
randomCode
,
EXPIRE_MINUTES
,
TimeUnit
.
MINUTES
);
deleteRetSendCode
(
phoneNo
);
//删除用户重置密码,多次错误逻辑
return
JsonResult
.
buildSuccessResult
(
"发送成功"
,
uniqueId
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"发送短信验证码失败"
);
...
...
@@ -176,7 +177,7 @@ public class SmsController implements IBaseController {
try
{
smsService
.
getSmsSender
().
sendMsg
(
message
);
redisTemplate
.
opsForValue
().
set
(
key
,
uniqueId
+
":"
+
randomCode
,
EXPIRE_MINUTES
,
TimeUnit
.
MINUTES
);
deleteRetSendCode
(
phoneNo
);
//删除用户重置密码,多次错误逻辑
return
JsonResult
.
buildSuccessResult
(
"发送成功"
,
uniqueId
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"发送语音短信验证码失败"
);
...
...
@@ -256,6 +257,7 @@ public class SmsController implements IBaseController {
//smsService.getSmsSender().sendConfirmableMessage(confirmableMsg);
smsService
.
getSmsSender
().
sendMsg
(
message
);
redisTemplate
.
opsForValue
().
set
(
key
,
uniqueId
+
":"
+
randomCode
,
EXPIRE_MINUTES
,
TimeUnit
.
MINUTES
);
deleteRetSendCode
(
phoneNo
);
//删除用户重置密码,多次错误逻辑
if
(
needImageVlidate
(
verificationIPCountKey
,
deviceId
,
phoneNo
)){
return
JsonResult
.
buildSuccessResult
(
"发送成功"
,
uniqueId
,
0003
L
);
}
...
...
@@ -270,6 +272,7 @@ public class SmsController implements IBaseController {
* 新版本语音验证码
*/
private
JsonResult
sendVerificationCode2VoiceNew
(
String
phoneNo
,
String
usage
,
String
deviceId
)
{
String
verificationCountKey
=
Constants
.
REDIS_VOICE_CODE_COUNT
+
phoneNo
;
Long
getVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
verificationCountKey
,
usage
.
toString
(),
1
);
if
(
getVerificationCount
>
5
)
{
...
...
@@ -296,7 +299,7 @@ public class SmsController implements IBaseController {
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"手机号格式有误"
,
null
);
}
String
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_
VOICE_
CODE
+
phoneNo
;
String
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
phoneNo
;
long
expire
=
redisTemplate
.
getExpire
(
key
,
TimeUnit
.
MINUTES
);
if
(
expire
>=
EXPIRE_MINUTES
-
1
)
{
return
JsonResult
.
buildSuccessResult
(
"发送成功"
,
null
);
...
...
@@ -307,7 +310,9 @@ public class SmsController implements IBaseController {
try
{
smsService
.
getSmsSender
().
sendMsg
(
message
);
redisTemplate
.
opsForValue
().
set
(
key
,
uniqueId
+
":"
+
randomCode
,
EXPIRE_MINUTES
,
TimeUnit
.
MINUTES
);
deleteRetSendCode
(
phoneNo
);
//删除用户重置密码,多次错误逻辑
if
(
needImageVlidate
(
verificationIPCountKey
,
deviceId
,
phoneNo
)){
return
JsonResult
.
buildSuccessResult
(
"发送成功"
,
uniqueId
,
0003
L
);
}
return
JsonResult
.
buildSuccessResult
(
"发送成功"
,
uniqueId
);
...
...
@@ -330,4 +335,16 @@ public class SmsController implements IBaseController {
}
return
need
;
}
/**
* 删除用户重置密码是短信验证错误
* @param phoneNo
*/
private
void
deleteRetSendCode
(
String
phoneNo
){
String
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
phoneNo
;
redisTemplate
.
opsForHash
().
delete
(
verificationCountKey
,
Constants
.
REDIS_VERIFICATION_COUNT
);
String
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
phoneNo
;
redisTemplate
.
delete
(
key
);
}
}
src/main/java/cn/quantgroup/xyqb/controller/internal/user/UserController.java
View file @
68105c03
...
...
@@ -352,6 +352,9 @@ public class UserController implements IBaseController {
return
JsonResult
.
buildErrorStateResult
(
"密码应为6-12位"
,
null
);
}
if
(!
smsService
.
validRegisterOrResetPasswdVerificationCode
(
phoneNo
,
verificationCode
))
{
if
(
needRetSendCode
(
phoneNo
)){
return
JsonResult
.
buildErrorStateResult
(
"错误次数过多,请重新获取短信验证码"
,
null
);
}
return
JsonResult
.
buildErrorStateResult
(
"短信验证码错误"
,
null
);
}
if
(!
userService
.
resetPassword
(
phoneNo
,
password
))
{
...
...
@@ -363,6 +366,21 @@ public class UserController implements IBaseController {
return
JsonResult
.
buildSuccessResult
(
null
,
null
);
}
/**
* 是否需要重新发送短信验证码
* @param phoneNo
* @return
*/
private
boolean
needRetSendCode
(
@RequestParam
String
phoneNo
)
{
boolean
needRetSend
=
false
;
String
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
phoneNo
;
Long
getVerificationCount
=
stringRedisTemplate
.
opsForHash
().
increment
(
verificationCountKey
,
Constants
.
REDIS_VERIFICATION_COUNT
,
1
);
if
(
getVerificationCount
>
5
){
return
needRetSend
=
true
;
}
return
needRetSend
;
}
/**
* 检查token是否已经过期不存在了
*
...
...
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