Commit 3be80b47 by 刘红梅

发送短信代码44

parent c1ddbc56
......@@ -71,7 +71,7 @@ public class SlideCaptchaService {
/**
* 在背景图上绘制滑块挖空效果
*/
private void drawSliderHole(BufferedImage background, int x, int y) {
private void drawSliderHoleOld(BufferedImage background, int x, int y) {
Graphics2D g2d = background.createGraphics();
// 设置挖空区域
......@@ -87,9 +87,22 @@ public class SlideCaptchaService {
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 createSliderWithShadowOld(BufferedImage background, int x, int y) {
int width = 50;
int height = 50;
int shadowSize = 3;
......@@ -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) {
......
......@@ -21,8 +21,8 @@ public interface SmsService {
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);
}
......@@ -21,7 +21,7 @@ import java.util.concurrent.CompletableFuture;
@AllArgsConstructor
@Slf4j
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_CHANGEPWD_CODE_CONTENT = "【专家小程序】您正在修改登录密码,请确认是本人操作。验证码为:%s,10分钟内有效,请勿告知他人。";
@Autowired
......@@ -83,7 +83,7 @@ public class SmsServiceImpl implements SmsService {
log.info("云MAS业务平台 发送手机号: {},短信验证码:{}", phone, code);
System.out.println("云MAS业务平台 短信内容: " + content);
boolean result = sendGlySmsContent(phone, content, code);
boolean result = sendGlySmsContent(phone, content, code, smsTemplateType);
if(result){
redisTemplate.opsForValue().set(key, code, 10 * 60); // 存入 Redis,设置过期时间为10分钟
}
......@@ -96,14 +96,14 @@ public class SmsServiceImpl implements SmsService {
}
@Override
public boolean sendGlySmsContent(String phone, String content, String code) {
public boolean sendGlySmsContent(String phone, String content, String code, int smsTemplateType) {
try {
log.info("管理云业务平台 短信内容: {}", content);
log.info("管理云业务平台 发送手机号: {},短信内容:{}", phone, content);
// 构建请求体并转换为 Base64 编码的 JSON 字符串
String encodedJson = SmsUtil.encodeRequestBodyToBase64(buildRequestBody(phone, content, code));
String encodedJson = SmsUtil.encodeRequestBodyToBase64(buildRequestBody(phone, content, code,smsTemplateType));
System.out.println("管理云业务平台 请求体Base64编码: " + encodedJson);
log.info("管理云业务平台 请求体Base64编码: {}", encodedJson);
......@@ -122,11 +122,11 @@ public class SmsServiceImpl implements SmsService {
}
@Override
public void asyncSendGlySmsContent(String phone, String content, String code){
public void asyncSendGlySmsContent(String phone, String content, String code, int smsTemplateType){
CompletableFuture.runAsync(() -> {
try {
System.out.println("======开始发送短信======");
sendGlySmsContent(phone, content,code);
sendGlySmsContent(phone, content,code,smsTemplateType);
System.out.println("======发送短信结束======");
} catch (Exception e) {
log.error("asyncSendMasSmsContent异步执行失败", e);
......@@ -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, 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);
dataItems.put("time", "10");
sms.put("template", smsConfig.getLoginTemplate());
if(smsTemplateType == 2){
sms.put("template", smsConfig.getChangePwdTemplate());
}
sms.put("dataItems", JsonUtils.toJsonString((dataItems)));
sms.put("type", "1");
String[] recvNumArray = new String[1];
recvNumArray[0] = phone;
sms.put("recvNum", recvNumArray);
sms.put("content", content);
//sms.put("content", content);
sms.put("sendNum", "");
Map<String, String> requestBody = new HashMap<>();
requestBody.put("priority", "high");
......
......@@ -12,5 +12,7 @@ public class SmsConfig {
private String apiUrl;
private String appCode;
private String loginTemplate;
private String changePwdTemplate;
}
......@@ -42,6 +42,8 @@ sms:
# 短信发送配置
api_url: https://gly.api.mcmptest.cnooc/msg/mcmp-msg-api/message
app_code: 3F2504E04F8911D39A0C0305E82C3301
loginTemplate: 登录验证码模版名称
changePwdTemplate: 修改密码验证码模版名称
app:
info:
appId: 10000
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment