Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
YAS\29473
2025-08-22 11:57:51 +08:00
5 changed files with 109 additions and 2 deletions

View File

@@ -8,6 +8,9 @@ import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.redis.RedisCache;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -38,7 +41,7 @@ public class SMSUtil {
private static final int APP_ID = 1400536771;
// 签名使用的是签名内容而不是签名ID
private static final String SMS_SIGN = "举视新能源";
private static final String SMS_SIGN = "举视上海新能源";
// 国家码 如 86 为中国
private static final String NATION_CODE = "86";
@@ -67,6 +70,36 @@ public class SMSUtil {
return reStr;
}
/**
* 发送短信V2
* @param request
* @param phoneNumber
* @return
* @throws HTTPException
* @throws IOException
*/
public static String sendSMSV2(HttpServletRequest request, String phoneNumber) throws HTTPException, IOException {
String reStr = "success"; //定义返回值
//随机生成六位验证码
String code = RandomUtil.getSMSVerificationCode();
SmsBlend smsBlend = SmsFactory.getSmsBlend("tx1");
SmsResponse smsResponse = smsBlend.sendMessage(phoneNumber, code);
boolean success = smsResponse.isSuccess();
if (!success) {
reStr = "error";
log.error("发送验证码失败:{}", JSON.toJSONString(smsResponse));
} else {
// 改为保存redis
String redisKey = CacheConstants.SMS_VERIFICATION_CODE_KEY + phoneNumber;
redisCache.setCacheObject(redisKey, code, CacheConstants.cache_expire_time_30m);
}
// 新增一个通用验证码 2025年4月14日14点23分个别手机号无法收到验证码, 新增通用验证码
String redisKey2 = CacheConstants.SMS_COMMON_VERIFICATION_CODE_KEY + phoneNumber;
redisCache.setCacheObject(redisKey2, Constants.COMMON_VERIFICATION_CODE, CacheConstants.cache_expire_time_30m);
return reStr;
}
public static void main(String[] args) {
System.out.println();