parent
40576bf75b
commit
1b918cbbe7
|
|
@ -19,7 +19,6 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
|
|
@ -108,8 +107,7 @@ public class SysPasswordService {
|
|||
String code = VerificationCodeUtils.generateVerificationCode(VerificationCodeUtils.CodeType.NUMERIC);
|
||||
String str = "您的验证码为" + code + ",尊敬的客户,以上验证码3分钟有效,微服务平台提醒您:转发可能导致账号被盗,请勿将验证码泄露于他人";
|
||||
String verifyKey = CacheConstants.VERIFICATION_CODE + phone;
|
||||
//String s = SmsUtils.smsToken(phone, str, "");
|
||||
String s = SmsUtils.sendMsgToSms(Arrays.asList(phone), str);
|
||||
String s = SmsUtils.smsToken(phone, str, "");
|
||||
if (StringUtils.isNotEmpty(s)) {
|
||||
if (s.contains("ok")) {
|
||||
redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -164,16 +164,6 @@
|
|||
<version>1.10.19</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 省公司短信平台sms-util -->
|
||||
<dependency>
|
||||
<groupId>com.ahsbd</groupId>
|
||||
<artifactId>sms-util</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/sms-util-1.0.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -1,23 +1,13 @@
|
|||
package com.bonus.common.core.utils.sms;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.ah.sbd.SmsTool;
|
||||
import com.ah.sbd.utils.param.BatchSmsByContentParam;
|
||||
import com.ah.sbd.utils.param.SmsParam;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.utils.encryption.Sm4Utils;
|
||||
import com.bonus.common.core.utils.http.HttpRequestHelper;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SmsUtils {
|
||||
// 安徽省公司短信平台key
|
||||
public static final String ANHUI_COMPANY_SMS_KEY = "Wq1FZobZC5iJIAGKWh6gpKUmdGKBOQq7koHmx+Vg49g/dSjSFlw+2qRQmMmyXvJT";
|
||||
/**
|
||||
* 发送短信验证码
|
||||
*
|
||||
|
|
@ -26,71 +16,33 @@ public class SmsUtils {
|
|||
* @param sendTime 为空表示立即发送,定时发送格式:20101024090810
|
||||
* @return 是否发送成功
|
||||
*/
|
||||
// public static String smsToken(String mobile, String content, String sendTime) {
|
||||
// Map<String, String> headers = new HashMap<>();
|
||||
// Map<String, Object> mapJson = new HashMap<>(6);
|
||||
// mapJson.put("ddtkey", SmsConfig.DDT_KEY);
|
||||
// mapJson.put("secretkey", SmsConfig.SECRET_KEY);
|
||||
// mapJson.put("mobile", mobile);
|
||||
// mapJson.put("content", SmsConfig.SMS_SIGNATURE + content);
|
||||
// mapJson.put("sendTime", sendTime);
|
||||
// mapJson.put("extno", "");
|
||||
//
|
||||
// // 将mapJson转换为URL查询参数格式
|
||||
// StringBuilder urlBuilder = new StringBuilder(SmsConfig.SMS_TOKEN + "?");
|
||||
// for (Map.Entry<String, Object> entry : mapJson.entrySet()) {
|
||||
// try {
|
||||
// String encodedKey = URLEncoder.encode(entry.getKey(), "UTF-8");
|
||||
// String encodedValue = URLEncoder.encode(entry.getValue().toString(), "UTF-8");
|
||||
// urlBuilder.append(encodedKey).append("=").append(encodedValue).append("&");
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// // 移除最后一个&符号
|
||||
// urlBuilder.setLength(urlBuilder.length() - 1);
|
||||
// String urlWithParams = urlBuilder.toString();
|
||||
//
|
||||
// String json = JSON.toJSONString(mapJson);
|
||||
// return HttpRequestHelper.postJson(SmsConfig.DOMAIN, urlWithParams, json, headers);
|
||||
// }
|
||||
public static String smsToken(String mobile, String content, String sendTime) {
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
Map<String, Object> mapJson = new HashMap<>(6);
|
||||
mapJson.put("ddtkey", SmsConfig.DDT_KEY);
|
||||
mapJson.put("secretkey", SmsConfig.SECRET_KEY);
|
||||
mapJson.put("mobile", mobile);
|
||||
mapJson.put("content", SmsConfig.SMS_SIGNATURE + content);
|
||||
mapJson.put("sendTime", sendTime);
|
||||
mapJson.put("extno", "");
|
||||
|
||||
/**
|
||||
* 发送消息到短信
|
||||
*
|
||||
* @param phoneNumbers 电话号码列表,可能包含无效或重复的号码
|
||||
* @param msg 要发送的短信消息内容
|
||||
* @return 发送短信的结果,具体形式依赖于SmsUtils.smsToken的实现
|
||||
* 此方法首先检查电话号码列表是否为空,如果为空,则直接返回空字符串。
|
||||
* 接下来,它会移除列表中所有为空的电话号码,
|
||||
* 然后对列表中超过11位的电话号码进行解密处理,
|
||||
* 确保只有有效的电话号码被用来发送短信。
|
||||
*/
|
||||
public static String sendMsgToSms(List<String> phoneNumbers, String msg) {
|
||||
// 检查电话号码列表和消息内容是否有效
|
||||
if (CollectionUtils.isEmpty(phoneNumbers) || StringUtils.isBlank(msg)) {
|
||||
return "";
|
||||
// 将mapJson转换为URL查询参数格式
|
||||
StringBuilder urlBuilder = new StringBuilder(SmsConfig.SMS_TOKEN + "?");
|
||||
for (Map.Entry<String, Object> entry : mapJson.entrySet()) {
|
||||
try {
|
||||
String encodedKey = URLEncoder.encode(entry.getKey(), "UTF-8");
|
||||
String encodedValue = URLEncoder.encode(entry.getValue().toString(), "UTF-8");
|
||||
urlBuilder.append(encodedKey).append("=").append(encodedValue).append("&");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// 移除最后一个&符号
|
||||
urlBuilder.setLength(urlBuilder.length() - 1);
|
||||
String urlWithParams = urlBuilder.toString();
|
||||
|
||||
// 过滤掉无效的电话号码
|
||||
phoneNumbers.removeIf(StringUtils::isEmpty);
|
||||
|
||||
// 对超过11位的电话号码进行解密处理
|
||||
phoneNumbers.replaceAll(phoneNumber ->
|
||||
phoneNumber.length() > 11 ? Sm4Utils.decrypt(phoneNumber) : phoneNumber
|
||||
);
|
||||
|
||||
// 根据电话号码数量发送短信
|
||||
if (phoneNumbers.isEmpty()) {
|
||||
return "";
|
||||
} else if (phoneNumbers.size() == 1) {
|
||||
JSONObject sendResult = SmsTool.sendSms(new SmsParam(phoneNumbers.get(0), msg), ANHUI_COMPANY_SMS_KEY);
|
||||
return sendResult.toString();
|
||||
} else {
|
||||
JSONObject sendResult = SmsTool.sendSms(new BatchSmsByContentParam(phoneNumbers, msg), ANHUI_COMPANY_SMS_KEY);
|
||||
return sendResult.toString();
|
||||
}
|
||||
String json = JSON.toJSONString(mapJson);
|
||||
return HttpRequestHelper.postJson(SmsConfig.DOMAIN, urlWithParams, json, headers);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,9 @@ import com.bonus.common.core.utils.VerificationCodeUtils;
|
|||
import com.bonus.common.core.utils.sms.SmsUtils;
|
||||
import com.bonus.common.redis.service.RedisService;
|
||||
import com.bonus.common.security.config.VerificationCodeConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.bonus.common.core.utils.VerificationCodeUtils.CodeType.NUMERIC;
|
||||
|
|
@ -20,7 +18,6 @@ import static com.bonus.common.core.utils.VerificationCodeUtils.CodeType.NUMERIC
|
|||
* @author bonus
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SmsService {
|
||||
@Resource
|
||||
private VerificationCodeConfig verificationCodeConfig;
|
||||
|
|
@ -40,9 +37,7 @@ public class SmsService {
|
|||
String code = VerificationCodeUtils.generateVerificationCode(NUMERIC);
|
||||
String str = verificationCodeConfig.getContent().replace("<code>", code);
|
||||
str = str.replace("<time>", verificationCodeConfig.getTime().toString());
|
||||
//String s = SmsUtils.smsToken(to, str, "");
|
||||
String s = SmsUtils.sendMsgToSms(Arrays.asList(to), str);
|
||||
log.error("省公司短信平台发送短信返回结果=" + s);
|
||||
String s = SmsUtils.smsToken(to, str, "");
|
||||
if (StringUtils.isNotEmpty(s)) {
|
||||
if (s.contains("ok")) {
|
||||
String verifyKey = CacheConstants.VERIFICATION_CODE + StringUtils.nvl(to, "");
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import org.springframework.util.CollectionUtils;
|
|||
import javax.annotation.Resource;
|
||||
import javax.validation.Validator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
@ -601,8 +600,7 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
Integer i = userMapper.approvalStatus(userId);
|
||||
if (i > 0) {
|
||||
if (StringUtils.isNotEmpty(sysUser.getPhonenumber())) {
|
||||
//SmsUtils.smsToken(sysUser.getPhonenumber(), "您的账号:" + sysUser.getUserName() + "已通过审批,请登录系统", "");
|
||||
SmsUtils.sendMsgToSms(Arrays.asList(sysUser.getPhonenumber()), "您的账号:" + sysUser.getUserName() + "已通过审批,请登录系统");
|
||||
SmsUtils.smsToken(sysUser.getPhonenumber(), "您的账号:" + sysUser.getUserName() + "已通过审批,请登录系统", "");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(sysUser.getEmail())) {
|
||||
sendSimpleEmail(sysUser.getEmail(), "您的账号:" + sysUser.getUserName() + "已通过审批,请登录系统");
|
||||
|
|
|
|||
Loading…
Reference in New Issue