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
f7456829
Commit
f7456829
authored
Jul 12, 2023
by
王亮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
temp commit(SMS).
parent
9522d2e7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
3 deletions
+72
-3
SmsController.java
...uantgroup/xyqb/controller/external/sms/SmsController.java
+31
-2
SmsServiceImpl.java
...a/cn/quantgroup/xyqb/service/sms/impl/SmsServiceImpl.java
+18
-1
SMSVerificationCodeStrategy.java
...antgroup/xyqb/service/v2/SMSVerificationCodeStrategy.java
+6
-0
SMSVoiceVerificationCodeStrategy.java
...oup/xyqb/service/v2/SMSVoiceVerificationCodeStrategy.java
+17
-0
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/sms/SmsController.java
View file @
f7456829
...
...
@@ -249,7 +249,14 @@ public class SmsController implements IBaseController {
}
private
JsonResult
sendVerificationCode2Voice
(
String
phoneNo
,
String
randomCode
,
String
usage
)
{
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSession
();
String
verificationCountKey
=
Constants
.
REDIS_VOICE_CODE_COUNT
+
phoneNo
;
if
(
sessionStruct
!=
null
&&
!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
verificationCountKey
=
Constants
.
REDIS_VOICE_CODE_COUNT
+
sessionStruct
.
getTenantId
()
+
"_"
+
phoneNo
;
}
Long
getVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
verificationCountKey
,
usage
,
1
);
redisTemplate
.
expire
(
verificationCountKey
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
if
(
getVerificationCount
>
PHONE_VOICE_MAX_PER_DAY
)
{
...
...
@@ -259,7 +266,6 @@ public class SmsController implements IBaseController {
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"手机号格式有误"
,
null
);
}
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSession
();
String
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
phoneNo
;
if
(
sessionStruct
!=
null
&&
!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
...
...
@@ -472,16 +478,30 @@ public class SmsController implements IBaseController {
if
(
StringUtils
.
isBlank
(
usage
))
{
return
JsonResult
.
buildErrorStateResult
(
"usage参数无效"
,
null
);
}
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSession
();
String
clientIp
=
getIp
();
log
.
info
(
"请求短信新版本接口:phoneNo:{},deviceId:{},usage:{},IP:{}"
,
phoneNo
,
deviceId
,
usage
,
clientIp
);
// 手机号计数器
String
verificationCountKey
=
Constants
.
REDIS_VOICE_CODE_COUNT
+
usage
;
if
(
sessionStruct
!=
null
&&
!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
verificationCountKey
=
Constants
.
REDIS_VOICE_CODE_COUNT
+
sessionStruct
.
getTenantId
()
+
"_"
+
usage
;
}
Long
getPhoneVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
verificationCountKey
,
phoneNo
,
1
);
redisTemplate
.
expire
(
verificationCountKey
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
// 设备号计数器
Long
getDeviceVerificationCount
=
0L
;
if
(
StringUtils
.
isNotBlank
(
deviceId
))
{
String
verificationDeviceCountKey
=
Constants
.
REDIS_VOICE_DEVICE_COUNT
+
deviceId
;
if
(
sessionStruct
!=
null
&&
!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
verificationDeviceCountKey
=
Constants
.
REDIS_VOICE_DEVICE_COUNT
+
sessionStruct
.
getTenantId
()
+
"_"
+
deviceId
;
}
getDeviceVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
Constants
.
REDIS_VOICE_DEVICE_COUNT
,
verificationDeviceCountKey
,
1
);
redisTemplate
.
expire
(
Constants
.
REDIS_VOICE_DEVICE_COUNT
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
}
...
...
@@ -489,6 +509,10 @@ public class SmsController implements IBaseController {
Long
getIPVerificationCount
=
0L
;
if
(
StringUtils
.
isNotBlank
(
clientIp
))
{
String
verificationIPCountKey
=
Constants
.
REDIS_VOICE_IP_COUNT
+
clientIp
;
if
(
sessionStruct
!=
null
&&
!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
verificationIPCountKey
=
Constants
.
REDIS_VOICE_IP_COUNT
+
sessionStruct
.
getTenantId
()
+
"_"
+
clientIp
;
}
getIPVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
Constants
.
REDIS_VOICE_IP_COUNT
,
verificationIPCountKey
,
1
);
redisTemplate
.
expire
(
Constants
.
REDIS_VOICE_IP_COUNT
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
}
...
...
@@ -508,7 +532,6 @@ public class SmsController implements IBaseController {
return
JsonResult
.
buildErrorStateResult
(
"您当前ip已经达到获取今天语音验证码上限"
,
null
);
}
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSession
();
String
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
phoneNo
;
if
(
sessionStruct
!=
null
&&
!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
...
...
@@ -565,7 +588,13 @@ public class SmsController implements IBaseController {
* @param phoneNo
*/
private
void
deleteRetSendCode
(
String
phoneNo
)
{
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSession
();
String
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
phoneNo
;
if
(
sessionStruct
!=
null
&&
!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
sessionStruct
.
getTenantId
()
+
"_"
+
phoneNo
;
}
redisTemplate
.
opsForHash
().
delete
(
verificationCountKey
,
Constants
.
REDIS_VERIFICATION_COUNT
);
}
...
...
src/main/java/cn/quantgroup/xyqb/service/sms/impl/SmsServiceImpl.java
View file @
f7456829
...
...
@@ -130,7 +130,11 @@ public class SmsServiceImpl implements ISmsService {
}
String
uniqueId
=
arr
[
0
];
String
code
=
arr
[
1
];
return
confirmSms
(
smsVerifyReq
.
getCode
(),
uniqueId
,
code
);
boolean
result
=
confirmSms
(
smsVerifyReq
.
getCode
(),
uniqueId
,
code
);
if
(
result
){
deleteCodeFromCache
(
smsVerifyReq
.
getPhoneNo
());
}
return
result
;
}
...
...
@@ -155,8 +159,14 @@ public class SmsServiceImpl implements ISmsService {
@Override
public
boolean
needResendCode
(
String
phoneNo
,
Long
threshold
,
boolean
isDelTryCount
)
{
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSession
();
String
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
phoneNo
;
if
(
sessionStruct
!=
null
&&
!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
sessionStruct
.
getTenantId
()
+
"_"
+
phoneNo
;
}
Long
getVerificationCount
=
stringRedisTemplate
.
opsForHash
().
increment
(
verificationCountKey
,
Constants
.
REDIS_VERIFICATION_COUNT
,
1
);
boolean
needResend
=
getVerificationCount
>=
threshold
;
if
(
needResend
)
{
...
...
@@ -171,7 +181,14 @@ public class SmsServiceImpl implements ISmsService {
@Override
public
void
deleteCodeFromCache
(
String
phoneNo
)
{
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSession
();
String
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
phoneNo
;
if
(
sessionStruct
!=
null
&&
!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
sessionStruct
.
getTenantId
()
+
"_"
+
phoneNo
;
}
stringRedisTemplate
.
opsForHash
().
delete
(
verificationCountKey
,
Constants
.
REDIS_VERIFICATION_COUNT
);
deleteOnlyCodeFromCache
(
phoneNo
);
...
...
src/main/java/cn/quantgroup/xyqb/service/v2/SMSVerificationCodeStrategy.java
View file @
f7456829
...
...
@@ -160,7 +160,13 @@ public class SMSVerificationCodeStrategy implements VerificationCodeStrategy {
* @param phoneNo 手机号码
*/
private
void
deleteRetSendCode
(
String
phoneNo
)
{
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSession
();
String
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
phoneNo
;
if
(
sessionStruct
!=
null
&&
!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
sessionStruct
.
getTenantId
()
+
"_"
+
phoneNo
;
}
redisTemplate
.
opsForHash
().
delete
(
verificationCountKey
,
Constants
.
REDIS_VERIFICATION_COUNT
);
}
...
...
src/main/java/cn/quantgroup/xyqb/service/v2/SMSVoiceVerificationCodeStrategy.java
View file @
f7456829
...
...
@@ -99,12 +99,22 @@ public class SMSVoiceVerificationCodeStrategy implements VerificationCodeStrateg
String
clientIp
=
sessionStruct
.
getIp
();
// 手机号计数器
String
verificationCountKey
=
Constants
.
REDIS_VOICE_CODE_COUNT
+
usage
;
if
(!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
verificationCountKey
=
Constants
.
REDIS_VOICE_CODE_COUNT
+
sessionStruct
.
getTenantId
()
+
"_"
+
usage
;
}
Long
getPhoneVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
verificationCountKey
,
phoneNo
,
1
);
redisTemplate
.
expire
(
verificationCountKey
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
// 设备号计数器
Long
getDeviceVerificationCount
=
0L
;
if
(
StringUtils
.
isNotBlank
(
sessionStruct
.
getScDeviceId
()))
{
String
verificationDeviceCountKey
=
Constants
.
REDIS_VOICE_DEVICE_COUNT
+
sessionStruct
.
getScDeviceId
();
if
(!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
verificationDeviceCountKey
=
Constants
.
REDIS_VOICE_DEVICE_COUNT
+
sessionStruct
.
getTenantId
()
+
"_"
+
sessionStruct
.
getScDeviceId
();
}
getDeviceVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
Constants
.
REDIS_VOICE_DEVICE_COUNT
,
verificationDeviceCountKey
,
1
);
redisTemplate
.
expire
(
Constants
.
REDIS_VOICE_DEVICE_COUNT
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
}
...
...
@@ -157,7 +167,14 @@ public class SMSVoiceVerificationCodeStrategy implements VerificationCodeStrateg
* @param phoneNo 手机号码
*/
private
void
deleteRetSendCode
(
String
phoneNo
)
{
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSession
();
String
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
phoneNo
;
if
(
sessionStruct
!=
null
&&
!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
verificationCountKey
=
Constants
.
REDIS_VERIFICATION_COUNT
+
sessionStruct
.
getTenantId
()
+
"_"
+
phoneNo
;
}
redisTemplate
.
opsForHash
().
delete
(
verificationCountKey
,
Constants
.
REDIS_VERIFICATION_COUNT
);
}
...
...
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