This commit is contained in:
2025-06-27 10:23:57 +08:00
parent 15d7ef8771
commit b94549185c
774 changed files with 3543 additions and 3558 deletions

View File

@ -0,0 +1,33 @@
package com.fuyuanshen.common.sms.config;
import com.fuyuanshen.common.sms.core.dao.PlusSmsDao;
import com.fuyuanshen.common.sms.handler.SmsExceptionHandler;
import org.dromara.sms4j.api.dao.SmsDao;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
/**
* 短信配置类
*
* @author Feng
*/
@AutoConfiguration(after = {RedisAutoConfiguration.class})
public class SmsAutoConfiguration {
@Primary
@Bean
public SmsDao smsDao() {
return new PlusSmsDao();
}
/**
* 异常处理器
*/
@Bean
public SmsExceptionHandler smsExceptionHandler() {
return new SmsExceptionHandler();
}
}

View File

@ -0,0 +1,72 @@
package com.fuyuanshen.common.sms.core.dao;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import org.dromara.sms4j.api.dao.SmsDao;
import java.time.Duration;
/**
* SmsDao缓存配置 (使用框架自带RedisUtils实现 协议统一)
* <p>主要用于短信重试和拦截的缓存
*
* @author Feng
*/
public class PlusSmsDao implements SmsDao {
/**
* 存储
*
* @param key 键
* @param value 值
* @param cacheTime 缓存时间(单位:秒)
*/
@Override
public void set(String key, Object value, long cacheTime) {
RedisUtils.setCacheObject(GlobalConstants.GLOBAL_REDIS_KEY + key, value, Duration.ofSeconds(cacheTime));
}
/**
* 存储
*
* @param key 键
* @param value 值
*/
@Override
public void set(String key, Object value) {
RedisUtils.setCacheObject(GlobalConstants.GLOBAL_REDIS_KEY + key, value, true);
}
/**
* 读取
*
* @param key 键
* @return 值
*/
@Override
public Object get(String key) {
return RedisUtils.getCacheObject(GlobalConstants.GLOBAL_REDIS_KEY + key);
}
/**
* remove
* <p> 根据key移除缓存
*
* @param key 缓存键
* @return 被删除的value
* @author :Wind
*/
@Override
public Object remove(String key) {
return RedisUtils.deleteObject(GlobalConstants.GLOBAL_REDIS_KEY + key);
}
/**
* 清空
*/
@Override
public void clean() {
RedisUtils.deleteKeys(GlobalConstants.GLOBAL_REDIS_KEY + "sms:*");
}
}

View File

@ -0,0 +1,30 @@
package com.fuyuanshen.common.sms.handler;
import cn.hutool.http.HttpStatus;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import com.fuyuanshen.common.core.domain.R;
import org.dromara.sms4j.comm.exception.SmsBlendException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* SMS异常处理器
*
* @author AprilWind
*/
@Slf4j
@RestControllerAdvice
public class SmsExceptionHandler {
/**
* sms异常
*/
@ExceptionHandler(SmsBlendException.class)
public R<Void> handleSmsBlendException(SmsBlendException e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生sms短信异常.", requestURI, e);
return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, "短信发送失败,请稍后再试...");
}
}

View File

@ -0,0 +1 @@
com.fuyuanshen.common.sms.config.SmsAutoConfiguration