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
3be80b47
Commit
3be80b47
authored
Nov 17, 2025
by
刘红梅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
发送短信代码44
parent
c1ddbc56
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
16 deletions
+54
-16
src/main/java/com/cnooc/expert/auth/service/SlideCaptchaService.java
+32
-2
src/main/java/com/cnooc/expert/auth/service/SmsService.java
+2
-2
src/main/java/com/cnooc/expert/auth/service/impl/SmsServiceImpl.java
+16
-12
src/main/java/com/cnooc/expert/system/entity/vo/SmsConfig.java
+2
-0
src/main/resources/application.yml
+2
-0
No files found.
src/main/java/com/cnooc/expert/auth/service/SlideCaptchaService.java
View file @
3be80b47
...
@@ -71,7 +71,7 @@ public class SlideCaptchaService {
...
@@ -71,7 +71,7 @@ public class SlideCaptchaService {
/**
/**
* 在背景图上绘制滑块挖空效果
* 在背景图上绘制滑块挖空效果
*/
*/
private
void
drawSliderHole
(
BufferedImage
background
,
int
x
,
int
y
)
{
private
void
drawSliderHole
Old
(
BufferedImage
background
,
int
x
,
int
y
)
{
Graphics2D
g2d
=
background
.
createGraphics
();
Graphics2D
g2d
=
background
.
createGraphics
();
// 设置挖空区域
// 设置挖空区域
...
@@ -87,9 +87,22 @@ public class SlideCaptchaService {
...
@@ -87,9 +87,22 @@ public class SlideCaptchaService {
g2d
.
dispose
();
g2d
.
dispose
();
}
}
/**
/**
* 在背景图上绘制滑块挖空效果
*/
private
void
drawSliderHole
(
BufferedImage
background
,
int
x
,
int
y
)
{
Graphics2D
g2d
=
background
.
createGraphics
();
// 设置挖空区域
// 创建半透明效果,能看到下层背景
g2d
.
setComposite
(
AlphaComposite
.
getInstance
(
AlphaComposite
.
SRC_OVER
,
0.8f
));
// 50%透明度
// 使用灰色填充
g2d
.
setColor
(
new
Color
(
100
,
100
,
100
));
// 深灰色
g2d
.
fillRect
(
x
,
y
,
SLIDER_WIDTH
,
SLIDER_HEIGHT
);
g2d
.
dispose
();
}
/**
* 创建带阴影效果的滑块
* 创建带阴影效果的滑块
*/
*/
private
BufferedImage
createSliderWithShadow
(
BufferedImage
background
,
int
x
,
int
y
)
{
private
BufferedImage
createSliderWithShadow
Old
(
BufferedImage
background
,
int
x
,
int
y
)
{
int
width
=
50
;
int
width
=
50
;
int
height
=
50
;
int
height
=
50
;
int
shadowSize
=
3
;
int
shadowSize
=
3
;
...
@@ -123,6 +136,23 @@ public class SlideCaptchaService {
...
@@ -123,6 +136,23 @@ public class SlideCaptchaService {
}
}
/**
/**
* 创建带阴影效果的滑块
*/
private
BufferedImage
createSliderWithShadow
(
BufferedImage
background
,
int
x
,
int
y
)
{
int
width
=
50
;
int
height
=
50
;
BufferedImage
slider
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_ARGB
);
Graphics2D
g2d
=
slider
.
createGraphics
();
// 直接截取背景图部分,不需要复杂的效果
BufferedImage
subImage
=
background
.
getSubimage
(
x
,
y
,
width
,
height
);
g2d
.
drawImage
(
subImage
,
0
,
0
,
null
);
g2d
.
dispose
();
return
slider
;
}
/**
* 调整图片尺寸
* 调整图片尺寸
*/
*/
private
BufferedImage
resizeImage
(
BufferedImage
originalImage
,
int
targetWidth
,
int
targetHeight
)
{
private
BufferedImage
resizeImage
(
BufferedImage
originalImage
,
int
targetWidth
,
int
targetHeight
)
{
...
...
src/main/java/com/cnooc/expert/auth/service/SmsService.java
View file @
3be80b47
...
@@ -21,8 +21,8 @@ public interface SmsService {
...
@@ -21,8 +21,8 @@ public interface SmsService {
boolean
sendGlySmsCode
(
String
phone
,
int
smsTemplateType
);
boolean
sendGlySmsCode
(
String
phone
,
int
smsTemplateType
);
boolean
sendGlySmsContent
(
String
phone
,
String
content
,
String
code
);
boolean
sendGlySmsContent
(
String
phone
,
String
content
,
String
code
,
int
smsTemplateType
);
void
asyncSendGlySmsContent
(
String
phone
,
String
content
,
String
code
);
void
asyncSendGlySmsContent
(
String
phone
,
String
content
,
String
code
,
int
smsTemplateType
);
}
}
src/main/java/com/cnooc/expert/auth/service/impl/SmsServiceImpl.java
View file @
3be80b47
...
@@ -21,7 +21,7 @@ import java.util.concurrent.CompletableFuture;
...
@@ -21,7 +21,7 @@ import java.util.concurrent.CompletableFuture;
@AllArgsConstructor
@AllArgsConstructor
@Slf4j
@Slf4j
public
class
SmsServiceImpl
implements
SmsService
{
public
class
SmsServiceImpl
implements
SmsService
{
public
static
final
String
SMS_CODE_CONTENT
=
"您的验证码是:%s(有效期为2分钟),请勿泄露给他人,如非本人操作,请忽略此消息。"
;
//
public static final String SMS_CODE_CONTENT = "您的验证码是:%s(有效期为2分钟),请勿泄露给他人,如非本人操作,请忽略此消息。";
public
static
final
String
SMS_LOGIN_CODE_CONTENT
=
"【专家小程序】您正在登录专家小程序,请确认是本人操作。验证码为:%s,10分钟内有效,请勿告知他人。"
;
public
static
final
String
SMS_LOGIN_CODE_CONTENT
=
"【专家小程序】您正在登录专家小程序,请确认是本人操作。验证码为:%s,10分钟内有效,请勿告知他人。"
;
public
static
final
String
SMS_CHANGEPWD_CODE_CONTENT
=
"【专家小程序】您正在修改登录密码,请确认是本人操作。验证码为:%s,10分钟内有效,请勿告知他人。"
;
public
static
final
String
SMS_CHANGEPWD_CODE_CONTENT
=
"【专家小程序】您正在修改登录密码,请确认是本人操作。验证码为:%s,10分钟内有效,请勿告知他人。"
;
@Autowired
@Autowired
...
@@ -83,7 +83,7 @@ public class SmsServiceImpl implements SmsService {
...
@@ -83,7 +83,7 @@ public class SmsServiceImpl implements SmsService {
log
.
info
(
"云MAS业务平台 发送手机号: {},短信验证码:{}"
,
phone
,
code
);
log
.
info
(
"云MAS业务平台 发送手机号: {},短信验证码:{}"
,
phone
,
code
);
System
.
out
.
println
(
"云MAS业务平台 短信内容: "
+
content
);
System
.
out
.
println
(
"云MAS业务平台 短信内容: "
+
content
);
boolean
result
=
sendGlySmsContent
(
phone
,
content
,
code
);
boolean
result
=
sendGlySmsContent
(
phone
,
content
,
code
,
smsTemplateType
);
if
(
result
){
if
(
result
){
redisTemplate
.
opsForValue
().
set
(
key
,
code
,
10
*
60
);
// 存入 Redis,设置过期时间为10分钟
redisTemplate
.
opsForValue
().
set
(
key
,
code
,
10
*
60
);
// 存入 Redis,设置过期时间为10分钟
}
}
...
@@ -96,14 +96,14 @@ public class SmsServiceImpl implements SmsService {
...
@@ -96,14 +96,14 @@ public class SmsServiceImpl implements SmsService {
}
}
@Override
@Override
public
boolean
sendGlySmsContent
(
String
phone
,
String
content
,
String
code
)
{
public
boolean
sendGlySmsContent
(
String
phone
,
String
content
,
String
code
,
int
smsTemplateType
)
{
try
{
try
{
log
.
info
(
"管理云业务平台 短信内容: {}"
,
content
);
log
.
info
(
"管理云业务平台 短信内容: {}"
,
content
);
log
.
info
(
"管理云业务平台 发送手机号: {},短信内容:{}"
,
phone
,
content
);
log
.
info
(
"管理云业务平台 发送手机号: {},短信内容:{}"
,
phone
,
content
);
// 构建请求体并转换为 Base64 编码的 JSON 字符串
// 构建请求体并转换为 Base64 编码的 JSON 字符串
String
encodedJson
=
SmsUtil
.
encodeRequestBodyToBase64
(
buildRequestBody
(
phone
,
content
,
code
));
String
encodedJson
=
SmsUtil
.
encodeRequestBodyToBase64
(
buildRequestBody
(
phone
,
content
,
code
,
smsTemplateType
));
System
.
out
.
println
(
"管理云业务平台 请求体Base64编码: "
+
encodedJson
);
System
.
out
.
println
(
"管理云业务平台 请求体Base64编码: "
+
encodedJson
);
log
.
info
(
"管理云业务平台 请求体Base64编码: {}"
,
encodedJson
);
log
.
info
(
"管理云业务平台 请求体Base64编码: {}"
,
encodedJson
);
...
@@ -122,11 +122,11 @@ public class SmsServiceImpl implements SmsService {
...
@@ -122,11 +122,11 @@ public class SmsServiceImpl implements SmsService {
}
}
@Override
@Override
public
void
asyncSendGlySmsContent
(
String
phone
,
String
content
,
String
code
){
public
void
asyncSendGlySmsContent
(
String
phone
,
String
content
,
String
code
,
int
smsTemplateType
){
CompletableFuture
.
runAsync
(()
->
{
CompletableFuture
.
runAsync
(()
->
{
try
{
try
{
System
.
out
.
println
(
"======开始发送短信======"
);
System
.
out
.
println
(
"======开始发送短信======"
);
sendGlySmsContent
(
phone
,
content
,
code
);
sendGlySmsContent
(
phone
,
content
,
code
,
smsTemplateType
);
System
.
out
.
println
(
"======发送短信结束======"
);
System
.
out
.
println
(
"======发送短信结束======"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"asyncSendMasSmsContent异步执行失败"
,
e
);
log
.
error
(
"asyncSendMasSmsContent异步执行失败"
,
e
);
...
@@ -138,17 +138,21 @@ public class SmsServiceImpl implements SmsService {
...
@@ -138,17 +138,21 @@ public class SmsServiceImpl implements SmsService {
/**
/**
* 构建请求体
* 构建请求体
*/
*/
private
Map
<
String
,
String
>
buildRequestBody
(
String
phone
,
String
content
,
String
code
)
{
private
Map
<
String
,
String
>
buildRequestBody
(
String
phone
,
String
content
,
String
code
,
int
smsTemplateType
)
{
Map
<
String
,
Object
>
sms
=
new
HashMap
<>();
Map
<
String
,
Object
>
sms
=
new
HashMap
<>();
//Map<String, String> dataItems = new HashMap<>();
Map
<
String
,
String
>
dataItems
=
new
HashMap
<>();
//dataItems.put("code", code);
dataItems
.
put
(
"code"
,
code
);
// sms.put("template", "短信验证码");
dataItems
.
put
(
"time"
,
"10"
);
//sms.put("dataItems", JsonUtils.toJsonString((dataItems)));
sms
.
put
(
"template"
,
smsConfig
.
getLoginTemplate
());
if
(
smsTemplateType
==
2
){
sms
.
put
(
"template"
,
smsConfig
.
getChangePwdTemplate
());
}
sms
.
put
(
"dataItems"
,
JsonUtils
.
toJsonString
((
dataItems
)));
sms
.
put
(
"type"
,
"1"
);
sms
.
put
(
"type"
,
"1"
);
String
[]
recvNumArray
=
new
String
[
1
];
String
[]
recvNumArray
=
new
String
[
1
];
recvNumArray
[
0
]
=
phone
;
recvNumArray
[
0
]
=
phone
;
sms
.
put
(
"recvNum"
,
recvNumArray
);
sms
.
put
(
"recvNum"
,
recvNumArray
);
sms
.
put
(
"content"
,
content
);
//
sms.put("content", content);
sms
.
put
(
"sendNum"
,
""
);
sms
.
put
(
"sendNum"
,
""
);
Map
<
String
,
String
>
requestBody
=
new
HashMap
<>();
Map
<
String
,
String
>
requestBody
=
new
HashMap
<>();
requestBody
.
put
(
"priority"
,
"high"
);
requestBody
.
put
(
"priority"
,
"high"
);
...
...
src/main/java/com/cnooc/expert/system/entity/vo/SmsConfig.java
View file @
3be80b47
...
@@ -12,5 +12,7 @@ public class SmsConfig {
...
@@ -12,5 +12,7 @@ public class SmsConfig {
private
String
apiUrl
;
private
String
apiUrl
;
private
String
appCode
;
private
String
appCode
;
private
String
loginTemplate
;
private
String
changePwdTemplate
;
}
}
src/main/resources/application.yml
View file @
3be80b47
...
@@ -42,6 +42,8 @@ sms:
...
@@ -42,6 +42,8 @@ sms:
# 短信发送配置
# 短信发送配置
api_url
:
https://gly.api.mcmptest.cnooc/msg/mcmp-msg-api/message
api_url
:
https://gly.api.mcmptest.cnooc/msg/mcmp-msg-api/message
app_code
:
3F2504E04F8911D39A0C0305E82C3301
app_code
:
3F2504E04F8911D39A0C0305E82C3301
loginTemplate
:
登录验证码模版名称
changePwdTemplate
:
修改密码验证码模版名称
app
:
app
:
info
:
info
:
appId
:
10000
appId
:
10000
...
...
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