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
960c7164
Commit
960c7164
authored
Jul 12, 2023
by
王亮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
temp commit(SMS).
parent
f7456829
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
15 deletions
+45
-15
SMSReq.java
...ain/java/cn/quantgroup/xyqb/controller/req/v2/SMSReq.java
+2
-0
SMSV2controller.java
...ava/cn/quantgroup/xyqb/controller/v2/SMSV2controller.java
+17
-4
SmsServiceImpl.java
...a/cn/quantgroup/xyqb/service/sms/impl/SmsServiceImpl.java
+2
-5
SMSVerificationCodeStrategy.java
...antgroup/xyqb/service/v2/SMSVerificationCodeStrategy.java
+24
-6
No files found.
src/main/java/cn/quantgroup/xyqb/controller/req/v2/SMSReq.java
View file @
960c7164
...
...
@@ -2,6 +2,7 @@ package cn.quantgroup.xyqb.controller.req.v2;
import
lombok.Data
;
import
javax.validation.constraints.Max
;
import
javax.validation.constraints.Size
;
@Data
...
...
@@ -9,6 +10,7 @@ public class SMSReq {
/**
* 0:是短信,1是语音,默认值是0
*/
@Max
(
1
)
private
Integer
type
=
0
;
/**
...
...
src/main/java/cn/quantgroup/xyqb/controller/v2/SMSV2controller.java
View file @
960c7164
...
...
@@ -2,6 +2,8 @@ package cn.quantgroup.xyqb.controller.v2;
import
cn.quantgroup.xyqb.controller.req.v2.SMSReq
;
import
cn.quantgroup.xyqb.controller.req.v2.SMSVerifyReq
;
import
cn.quantgroup.xyqb.exception.BizException
;
import
cn.quantgroup.xyqb.exception.BizExceptionEnum
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.SMSCodeBean
;
import
cn.quantgroup.xyqb.service.v2.VerificationCodeContext
;
...
...
@@ -10,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.validation.Valid
;
@RestController
@RequestMapping
(
"/v2/sms"
)
public
class
SMSV2controller
{
...
...
@@ -22,21 +26,30 @@ public class SMSV2controller {
/**
* 统一获取短信验证码
*
* @return JsonResult<SMSCodeBean>
* @see <a href="http://yapi.quantgroups.com/project/17/interface/api/65709">统一获取短信验证码</a>
*/
@PostMapping
(
"/code"
)
public
JsonResult
<
SMSCodeBean
>
getCode
(
@RequestBody
SMSReq
smsReq
){
public
JsonResult
<
SMSCodeBean
>
getCode
(
@Valid
@RequestBody
SMSReq
smsReq
)
{
if
(
smsReq
.
getCodeLength
()
!=
null
&&
(
smsReq
.
getCodeLength
()
<
4
||
smsReq
.
getCodeLength
()
>
10
))
{
throw
new
BizException
(
BizExceptionEnum
.
ERROR_PARAM
,
"密码长度只能在4到10位之间"
);
}
if
(
smsReq
.
getSceneType
()!=
null
&&(
smsReq
.
getSceneType
()<
0
||
smsReq
.
getSceneType
()>
2
)){
throw
new
BizException
(
BizExceptionEnum
.
ERROR_PARAM
,
"请输入有效的场景值"
);
}
return
JsonResult
.
buildSuccessResultGeneric
(
verificationCodeContext
.
send
(
smsReq
));
}
/**
* 统一验证短信验证码
*
* @return JsonResult<Boolean>
* @see <a href="http://yapi.quantgroups.com/project/17/interface/api/65829">...</a>
*/
@PostMapping
(
"/verify"
)
public
JsonResult
<
Boolean
>
verify
(
@
RequestBody
SMSVerifyReq
smsVerifyReq
)
{
public
JsonResult
<
Boolean
>
verify
(
@
Valid
@RequestBody
SMSVerifyReq
smsVerifyReq
)
{
return
JsonResult
.
buildSuccessResultGeneric
(
verificationCodeContext
.
verify
(
smsVerifyReq
));
}
...
...
src/main/java/cn/quantgroup/xyqb/service/sms/impl/SmsServiceImpl.java
View file @
960c7164
...
...
@@ -109,17 +109,14 @@ public class SmsServiceImpl implements ISmsService {
// return true;
// }
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSession
();
String
key
;
String
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
smsVerifyReq
.
getPhoneNo
()
;
if
(
sessionStruct
==
null
)
{
throw
new
BizException
(
BizExceptionEnum
.
UN_EXIT_TENANT_ID
);
}
if
(
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
smsVerifyReq
.
getPhoneNo
();
}
else
{
if
(!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
sessionStruct
.
getTenantId
()
+
"_"
+
smsVerifyReq
.
getPhoneNo
();
}
String
randomCode
=
stringRedisTemplate
.
opsForValue
().
get
(
key
);
if
(
StringUtils
.
isBlank
(
randomCode
))
{
return
false
;
...
...
src/main/java/cn/quantgroup/xyqb/service/v2/SMSVerificationCodeStrategy.java
View file @
960c7164
...
...
@@ -93,20 +93,38 @@ public class SMSVerificationCodeStrategy implements VerificationCodeStrategy {
private
boolean
sendVerificationCode2New
(
String
phoneNo
,
String
randomCode
,
String
smsMerchant
)
{
SessionStruct
sessionStruct
=
XyqbSessionContextHolder
.
getXSession
();
String
clientIp
=
sessionStruct
.
getIp
();
String
getPhoneVerificationCountKey
=
Constants
.
REDIS_SMS_CODE_COUNT
;
if
(!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
getPhoneVerificationCountKey
=
Constants
.
REDIS_SMS_CODE_COUNT
+
sessionStruct
.
getTenantId
()
+
":"
;
}
// 手机号计数器
Long
getPhoneVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
Constants
.
REDIS_SMS_CODE_COUNT
,
phoneNo
,
1
);
redisTemplate
.
expire
(
Constants
.
REDIS_SMS_CODE_COUNT
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
Long
getPhoneVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
getPhoneVerificationCountKey
,
phoneNo
,
1
);
redisTemplate
.
expire
(
getPhoneVerificationCountKey
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
// 设备号计数器
String
getDeviceVerificationCountKey
=
Constants
.
REDIS_SMS_DEVICE_COUNT
;
if
(!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
getDeviceVerificationCountKey
=
Constants
.
REDIS_SMS_DEVICE_COUNT
+
sessionStruct
.
getTenantId
()
+
":"
;
}
Long
getDeviceVerificationCount
=
0L
;
if
(
StringUtils
.
isNotBlank
(
sessionStruct
.
getScDeviceId
()))
{
getDeviceVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
Constants
.
REDIS_SMS_DEVICE_COUNT
,
sessionStruct
.
getScDeviceId
(),
1
);
redisTemplate
.
expire
(
Constants
.
REDIS_SMS_DEVICE_COUNT
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
getDeviceVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
getDeviceVerificationCountKey
,
sessionStruct
.
getScDeviceId
(),
1
);
redisTemplate
.
expire
(
getDeviceVerificationCountKey
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
}
// IP计数器
String
getIPVerificationCountKey
=
Constants
.
REDIS_SMS_IP_COUNT
;
if
(!
UserConstant
.
defaultTenantId
.
equals
(
sessionStruct
.
getTenantId
()))
{
getIPVerificationCountKey
=
Constants
.
REDIS_SMS_IP_COUNT
+
sessionStruct
.
getTenantId
()
+
":"
;
}
Long
getIPVerificationCount
=
0L
;
if
(
StringUtils
.
isNotBlank
(
clientIp
))
{
getIPVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
Constants
.
REDIS_SMS_IP_COUNT
,
clientIp
,
1
);
redisTemplate
.
expire
(
Constants
.
REDIS_SMS_IP_COUNT
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
getIPVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
getIPVerificationCountKey
,
clientIp
,
1
);
redisTemplate
.
expire
(
getIPVerificationCountKey
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
}
// 手机号上限检查
if
(
getPhoneVerificationCount
>
PHONE_MAX_PER_DAY
)
{
...
...
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