Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dsk-operate-sys-cscec
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
fulixin
dsk-operate-sys-cscec
Commits
0da9796c
Commit
0da9796c
authored
Aug 30, 2023
by
施翔轲
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增临时发送短信、校验短信接口,用于删除组织时提供校验
parent
fc0b6d73
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
6 deletions
+45
-6
CaptchaController.java
...java/com/dsk/web/controller/common/CaptchaController.java
+43
-4
Constants.java
...mmon/src/main/java/com/dsk/common/constant/Constants.java
+1
-1
DingTalkUtil.java
...mmon/src/main/java/com/dsk/common/utils/DingTalkUtil.java
+1
-1
No files found.
dsk-admin/src/main/java/com/dsk/web/controller/common/CaptchaController.java
View file @
0da9796c
...
...
@@ -10,6 +10,9 @@ import com.dsk.common.constant.Constants;
import
com.dsk.common.constant.GlobalConstants
;
import
com.dsk.common.core.domain.R
;
import
com.dsk.common.enums.CaptchaType
;
import
com.dsk.common.exception.user.CaptchaExpireException
;
import
com.dsk.common.helper.LoginHelper
;
import
com.dsk.common.utils.MessageUtils
;
import
com.dsk.common.utils.StringUtils
;
import
com.dsk.common.utils.email.MailUtils
;
import
com.dsk.common.utils.redis.RedisUtils
;
...
...
@@ -17,6 +20,8 @@ import com.dsk.common.utils.reflect.ReflectUtils;
import
com.dsk.common.utils.spring.SpringUtils
;
import
com.dsk.framework.config.properties.CaptchaProperties
;
import
com.dsk.framework.config.properties.MailProperties
;
import
com.dsk.system.domain.SysUser
;
import
com.dsk.system.mapper.SysUserMapper
;
import
com.dsk.system.service.ISysConfigService
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -29,6 +34,7 @@ import org.springframework.expression.ExpressionParser;
import
org.springframework.expression.spel.standard.SpelExpressionParser
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.validation.constraints.NotBlank
;
...
...
@@ -52,16 +58,17 @@ public class CaptchaController {
private
final
CaptchaProperties
captchaProperties
;
private
final
ISysConfigService
configService
;
private
final
MailProperties
mailProperties
;
private
final
SysUserMapper
userMapper
;
/**
* 短信验证码
*
发送
短信验证码
*
* @param phonenumber 用户手机号
*/
@GetMapping
(
"/captchaSms"
)
public
R
<
Void
>
smsCaptcha
(
@NotBlank
(
message
=
"{user.phonenumber.not.blank}"
)
String
phonenumber
)
{
String
key
=
GlobalConstants
.
CAPTCHA_CODE_KEY
+
phonenumber
;
String
code
=
RandomUtil
.
randomNumbers
(
4
);
String
code
=
RandomUtil
.
randomNumbers
(
6
);
RedisUtils
.
setCacheObject
(
key
,
code
,
Duration
.
ofMinutes
(
Constants
.
CAPTCHA_EXPIRATION
));
// 验证码模板id 自行处理 (查数据库或写死均可)
String
templateId
=
""
;
...
...
@@ -77,7 +84,39 @@ public class CaptchaController {
}
/**
* 邮箱验证码
* 开发需要,临时发送短信验证码
*/
@GetMapping
(
"/getTempSmsCode"
)
public
R
<
Void
>
getTempSmsCode
()
{
SysUser
sysUser
=
userMapper
.
selectUserById
(
LoginHelper
.
getUserId
());
String
key
=
GlobalConstants
.
CAPTCHA_CODE_KEY
+
sysUser
.
getPhonenumber
();
String
code
=
RandomUtil
.
randomNumbers
(
6
);
RedisUtils
.
setCacheObject
(
key
,
code
,
Duration
.
ofMinutes
(
Constants
.
CAPTCHA_EXPIRATION
));
return
R
.
ok
(
"验证码:"
+
code
);
}
/**
* 开发需要,临时校验短信验证码
*
* @param smsCode 验证码
*/
@PostMapping
(
"/checkSmsCode"
)
public
R
<
Boolean
>
checkSmsCode
(
String
smsCode
)
{
SysUser
sysUser
=
userMapper
.
selectUserById
(
LoginHelper
.
getUserId
());
String
key
=
GlobalConstants
.
CAPTCHA_CODE_KEY
+
sysUser
.
getPhonenumber
();
String
code
=
RedisUtils
.
getCacheObject
(
key
);
if
(
StringUtils
.
isBlank
(
code
))
{
throw
new
CaptchaExpireException
();
}
if
(
code
.
equals
(
smsCode
))
{
RedisUtils
.
deleteObject
(
key
);
return
R
.
ok
(
"校验成功"
);
}
return
R
.
fail
(
"验证码错误"
);
}
/**
* 发送邮箱验证码
*
* @param email 邮箱
*/
...
...
@@ -126,7 +165,7 @@ public class CaptchaController {
Expression
exp
=
parser
.
parseExpression
(
StringUtils
.
remove
(
code
,
"="
));
code
=
exp
.
getValue
(
String
.
class
);
}
log
.
info
(
"图形验证码:"
+
code
);
log
.
info
(
"图形验证码:"
+
code
);
RedisUtils
.
setCacheObject
(
verifyKey
,
code
,
Duration
.
ofMinutes
(
Constants
.
CAPTCHA_EXPIRATION
));
ajax
.
put
(
"uuid"
,
uuid
);
ajax
.
put
(
"img"
,
captcha
.
getImageBase64
());
...
...
dsk-common/src/main/java/com/dsk/common/constant/Constants.java
View file @
0da9796c
...
...
@@ -65,7 +65,7 @@ public interface Constants {
/**
* 验证码有效期(分钟)
*/
Integer
CAPTCHA_EXPIRATION
=
2
;
Integer
CAPTCHA_EXPIRATION
=
5
;
/**
* 令牌
...
...
dsk-common/src/main/java/com/dsk/common/utils/DingTalkUtil.java
View file @
0da9796c
...
...
@@ -21,7 +21,7 @@ public class DingTalkUtil {
* 钉钉机器人发消息地址(配置机器人的webhook)
* 此处大家可以配置到配置文件等等方式
*/
private
static
final
String
MSG_URL
=
"https://oapi.dingtalk.com/robot/send?access_token=
d348d1f6ee759e03e6ee214622164c9bda653565a62e92b8685577e8796bcdfb
"
;
private
static
final
String
MSG_URL
=
"https://oapi.dingtalk.com/robot/send?access_token=
ab6a16dacc0f7e8051bf5b34d425382ffa22621cf3876d81a5331ab30a1bbb14
"
;
/**
* 通知具体人
...
...
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