Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cnooc_zydeepen-cggl_expert-manage-miniapp
Overview
Overview
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
孙德龙
cnooc_zydeepen-cggl_expert-manage-miniapp
Commits
c1ddbc56
Commit
c1ddbc56
authored
Nov 17, 2025
by
刘红梅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
发送短信代码22
parent
337d1896
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
13 deletions
+23
-13
src/main/java/com/cnooc/expert/auth/service/SmsService.java
+2
-2
src/main/java/com/cnooc/expert/auth/service/impl/LoginServiceImpl.java
+1
-1
src/main/java/com/cnooc/expert/auth/service/impl/SmsServiceImpl.java
+16
-10
src/main/java/com/cnooc/expert/system/entity/vo/LoginVO.java
+4
-0
No files found.
src/main/java/com/cnooc/expert/auth/service/SmsService.java
View file @
c1ddbc56
...
...
@@ -17,9 +17,9 @@ public interface SmsService {
* @param phone 手机号
* @return 是否发送成功
*/
boolean
sendSmsCode
(
String
phone
);
boolean
sendSmsCode
(
String
phone
,
int
smsTemplateType
);
boolean
sendGlySmsCode
(
String
phone
);
boolean
sendGlySmsCode
(
String
phone
,
int
smsTemplateType
);
boolean
sendGlySmsContent
(
String
phone
,
String
content
,
String
code
);
...
...
src/main/java/com/cnooc/expert/auth/service/impl/LoginServiceImpl.java
View file @
c1ddbc56
...
...
@@ -102,7 +102,7 @@ public class LoginServiceImpl implements LoginService {
if(!flag){
throw new BusinessException(GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getCode(),GlobalErrorCodeConstants.CAPTCHA_EXPIRED.getMsg());
}else{*/
boolean
smsfalg
=
smsService
.
sendSmsCode
(
vo
.
getPhoneNumber
());
boolean
smsfalg
=
smsService
.
sendSmsCode
(
vo
.
getPhoneNumber
()
,
vo
.
getSmsTemplateType
()
);
if
(!
smsfalg
)
{
throw
new
BusinessException
(
GlobalErrorCodeConstants
.
SEND_SMS_ERROR
.
getCode
(),
GlobalErrorCodeConstants
.
SEND_SMS_ERROR
.
getMsg
());
}
else
{
...
...
src/main/java/com/cnooc/expert/auth/service/impl/SmsServiceImpl.java
View file @
c1ddbc56
...
...
@@ -22,6 +22,8 @@ import java.util.concurrent.CompletableFuture;
@Slf4j
public
class
SmsServiceImpl
implements
SmsService
{
public
static
final
String
SMS_CODE_CONTENT
=
"您的验证码是:%s(有效期为2分钟),请勿泄露给他人,如非本人操作,请忽略此消息。"
;
public
static
final
String
SMS_LOGIN_CODE_CONTENT
=
"【专家小程序】您正在登录专家小程序,请确认是本人操作。验证码为:%s,10分钟内有效,请勿告知他人。"
;
public
static
final
String
SMS_CHANGEPWD_CODE_CONTENT
=
"【专家小程序】您正在修改登录密码,请确认是本人操作。验证码为:%s,10分钟内有效,请勿告知他人。"
;
@Autowired
private
StringRedisTemplate
redisTemplate
;
private
final
SmsConfig
smsConfig
;
...
...
@@ -51,20 +53,20 @@ public class SmsServiceImpl implements SmsService {
* @param phone 手机号
* @return 是否发送成功
*/
public
boolean
sendSmsCode
(
String
phone
)
{
public
boolean
sendSmsCode
(
String
phone
,
int
smsTemplateType
)
{
// 生成6位验证码
//String code = RandomUtil.randomNumbers(6);
String
code
=
"666666"
;
String
key
=
"sms:code:"
+
phone
;
redisTemplate
.
opsForValue
().
set
(
key
,
code
,
5
,
TimeUnit
.
MINUTES
);
// 存入 Redis,设置过期时间为5
分钟
redisTemplate
.
opsForValue
().
set
(
key
,
code
,
10
,
TimeUnit
.
MINUTES
);
// 存入 Redis,设置过期时间为10
分钟
//String storedCode = (String)redisTemplate.opsForValue().get(key);
System
.
out
.
println
(
"发送短信验证码:"
+
phone
+
" -> "
+
code
);
// 模拟发送短信,实际应调用第三方短信服务
return
true
;
//return sendGlySmsCode(phone);
//return sendGlySmsCode(phone
,smsTemplateType
);
}
@Override
public
boolean
sendGlySmsCode
(
String
phone
)
{
public
boolean
sendGlySmsCode
(
String
phone
,
int
smsTemplateType
)
{
// 生成验证码并构建缓存键
String
code
=
SmsUtil
.
generateVerificationCode
();
System
.
out
.
println
(
"发送短信验证码:"
+
phone
+
" -> "
+
code
);
...
...
@@ -72,14 +74,18 @@ public class SmsServiceImpl implements SmsService {
try
{
// 构建短信内容
String
content
=
String
.
format
(
SMS_CODE_CONTENT
,
code
);
String
content
=
String
.
format
(
SMS_LOGIN_CODE_CONTENT
,
code
);
if
(
smsTemplateType
==
2
){
//修改密码
content
=
String
.
format
(
SMS_CHANGEPWD_CODE_CONTENT
,
code
);
}
System
.
out
.
println
(
"发送短信验证码:"
+
phone
+
" -> "
+
code
);
log
.
info
(
"云MAS业务平台 发送手机号: {},短信验证码:{}"
,
phone
,
code
);
System
.
out
.
println
(
"云MAS业务平台 短信内容: "
+
content
);
boolean
result
=
sendGlySmsContent
(
phone
,
content
,
code
);
if
(
result
){
redisTemplate
.
opsForValue
().
set
(
key
,
code
,
2
*
60
);
// 存入 Redis,设置过期时间为2
分钟
redisTemplate
.
opsForValue
().
set
(
key
,
code
,
10
*
60
);
// 存入 Redis,设置过期时间为10
分钟
}
return
result
;
}
catch
(
Exception
e
)
{
...
...
@@ -134,10 +140,10 @@ public class SmsServiceImpl implements SmsService {
*/
private
Map
<
String
,
String
>
buildRequestBody
(
String
phone
,
String
content
,
String
code
)
{
Map
<
String
,
Object
>
sms
=
new
HashMap
<>();
Map
<
String
,
String
>
dataItems
=
new
HashMap
<>();
dataItems
.
put
(
"code"
,
code
);
sms
.
put
(
"template"
,
"短信验证码"
);
sms
.
put
(
"dataItems"
,
JsonUtils
.
toJsonString
((
dataItems
)));
//
Map<String, String> dataItems = new HashMap<>();
//
dataItems.put("code", code);
//
sms.put("template", "短信验证码");
//
sms.put("dataItems", JsonUtils.toJsonString((dataItems)));
sms
.
put
(
"type"
,
"1"
);
String
[]
recvNumArray
=
new
String
[
1
];
recvNumArray
[
0
]
=
phone
;
...
...
src/main/java/com/cnooc/expert/system/entity/vo/LoginVO.java
View file @
c1ddbc56
...
...
@@ -28,6 +28,10 @@ public class LoginVO {
@Min
(
value
=
1
)
private
Integer
loginType
;
@Max
(
value
=
2
,
message
=
"短信模版类型只能是1,登录时候发送验证码的短信模版 2.修改密码时候发送验证码的短信模版"
)
@Min
(
value
=
1
)
private
Integer
smsTemplateType
;
//图形验证码的key
private
String
key
;
...
...
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