mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-06 08:58:38 +08:00
删除无用模块,添加错误日志记录
This commit is contained in:
parent
7aef711fbf
commit
2bc24264b4
@ -24,6 +24,12 @@
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>dysmsapi20170525</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
@ -37,5 +43,10 @@
|
||||
<groupId>kim.wind</groupId>
|
||||
<artifactId>sms-aggregation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.14.9</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@ -5,6 +5,7 @@ import com.aliyun.teaopenapi.models.Config;
|
||||
import kim.wind.sms.aliyun.service.AlibabaSmsImpl;
|
||||
import kim.wind.sms.comm.exception.SmsBlendException;
|
||||
import kim.wind.sms.comm.factory.BeanFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
/**
|
||||
@ -13,6 +14,7 @@ import kim.wind.sms.comm.factory.BeanFactory;
|
||||
* @author :Wind
|
||||
* 2023/4/8 14:54
|
||||
**/
|
||||
@Slf4j
|
||||
public class AlibabaSmsConfig {
|
||||
|
||||
private static AlibabaSmsImpl alibabaSms;
|
||||
@ -30,6 +32,7 @@ public class AlibabaSmsConfig {
|
||||
config.endpoint = alibabaConfig.getRequestUrl();
|
||||
return new Client(config);
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage());
|
||||
throw new SmsBlendException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,11 +85,11 @@ public class AlibabaSmsImpl implements SmsBlend {
|
||||
smsResponse.setMessage(sendSmsResponse.body.message);
|
||||
}
|
||||
} catch (TeaException error) {
|
||||
log.error(error.getMessage());
|
||||
throw new SmsBlendException(error.message);
|
||||
// 如有需要,请打印 error
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 如有需要,请打印 error
|
||||
log.error(_error.getMessage());
|
||||
throw new SmsBlendException(error.message);
|
||||
}
|
||||
return smsResponse;
|
||||
@ -125,11 +125,11 @@ public class AlibabaSmsImpl implements SmsBlend {
|
||||
smsResponse.setMessage(sendBatchSmsResponse.body.message);
|
||||
}
|
||||
} catch (TeaException error) {
|
||||
log.error(error.getMessage());
|
||||
throw new SmsBlendException(error.message);
|
||||
// 如有需要,请打印 error
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 如有需要,请打印 error
|
||||
log.error(error.getMessage());
|
||||
throw new SmsBlendException(error.message);
|
||||
}
|
||||
return smsResponse;
|
||||
|
||||
@ -7,6 +7,7 @@ import kim.wind.sms.autoimmit.utils.RedisUtils;
|
||||
import kim.wind.sms.comm.utils.SmsUtil;
|
||||
import kim.wind.sms.comm.utils.TimeExpiredPoolCache;
|
||||
import kim.wind.sms.autoimmit.utils.SpringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
@ -16,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Aspect
|
||||
@Slf4j
|
||||
public class AopAdvice {
|
||||
|
||||
private static final Long minTimer = 60 * 1000L;
|
||||
@ -55,6 +57,7 @@ public class AopAdvice {
|
||||
try {
|
||||
proce = redisProcess(f);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (proce != null) {
|
||||
@ -73,7 +76,8 @@ public class AopAdvice {
|
||||
if (SmsUtil.isEmpty(i)) {
|
||||
instance.put(args + "max", 1, accTimer);
|
||||
} else if (i > accountMax) {
|
||||
return new SmsBlendException("accountMax", args + "今日短信已达最大次数");
|
||||
log.info("The phone:"+args +",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:"+args +",number of short messages reached the maximum today");
|
||||
} else {
|
||||
instance.put(args + "max", i + 1, accTimer);
|
||||
}
|
||||
@ -84,7 +88,8 @@ public class AopAdvice {
|
||||
if (o < minuteMax) {
|
||||
instance.put(args, o + 1, minTimer);
|
||||
} else {
|
||||
return new SmsBlendException("minuteMax", args + "短信发送过于频繁!");
|
||||
log.info("The phone:"+args +",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:", args + " Text messages are sent too often!");
|
||||
}
|
||||
} else {
|
||||
instance.put(args, 1, minTimer);
|
||||
@ -106,7 +111,8 @@ public class AopAdvice {
|
||||
if (SmsUtil.isEmpty(i)) {
|
||||
redis.setOrTime(REDIS_KEY+args + "max", 1,accTimer/1000);
|
||||
} else if (i > accountMax) {
|
||||
return new SmsBlendException("accountMax", args + "今日短信已达最大次数");
|
||||
log.info("The phone:"+args +",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:"+args +",number of short messages reached the maximum today");
|
||||
} else {
|
||||
redis.setOrTime(REDIS_KEY+args + "max", i + 1,accTimer/1000);
|
||||
}
|
||||
@ -117,7 +123,8 @@ public class AopAdvice {
|
||||
if (o < minuteMax) {
|
||||
redis.setOrTime(REDIS_KEY+args, o + 1,minTimer/1000);
|
||||
} else {
|
||||
return new SmsBlendException("minuteMax", args + "短信发送过于频繁!");
|
||||
log.info("The phone:"+args +",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:", args + " Text messages are sent too often!");
|
||||
}
|
||||
} else {
|
||||
redis.setOrTime(REDIS_KEY+args, 1,minTimer/1000);
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package kim.wind.sms.autoimmit.config;
|
||||
|
||||
import kim.wind.sms.aliyun.config.AlibabaConfig;
|
||||
import kim.wind.sms.autoimmit.aop.AopAdvice;
|
||||
import kim.wind.sms.autoimmit.utils.ConfigUtil;
|
||||
import kim.wind.sms.autoimmit.utils.RedisUtils;
|
||||
@ -9,8 +8,7 @@ import kim.wind.sms.comm.config.SmsBanner;
|
||||
import kim.wind.sms.comm.config.SmsConfig;
|
||||
import kim.wind.sms.comm.delayedTime.DelayedTime;
|
||||
import kim.wind.sms.comm.factory.BeanFactory;
|
||||
import kim.wind.sms.core.config.SupplierFactory;
|
||||
import kim.wind.sms.huawei.config.HuaweiConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.env.Environment;
|
||||
@ -18,6 +16,7 @@ import org.springframework.core.env.Environment;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class SmsAutowiredConfig {
|
||||
|
||||
private final SpringUtil springUtil;
|
||||
@ -61,10 +60,12 @@ public class SmsAutowiredConfig {
|
||||
/* 如果配置中启用了redis,则注入redis工具*/
|
||||
if (BeanFactory.getSmsConfig().getRedisCache()){
|
||||
springUtil.createBean(RedisUtils.class);
|
||||
log.debug("The redis cache is enabled for sms-aggregation");
|
||||
}
|
||||
/* 如果启用了短信限制,则注入AOP组件*/
|
||||
if (BeanFactory.getSmsConfig().getRestricted()){
|
||||
springUtil.createBean(AopAdvice.class);
|
||||
log.debug("SMS restriction is enabled");
|
||||
}
|
||||
if (BeanFactory.getSmsConfig().getIsPrint()){
|
||||
SmsBanner.PrintBanner("V 1.0.4");
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
package kim.wind.sms.autoimmit.factory;
|
||||
|
||||
/**
|
||||
* AutoBeanFac
|
||||
* <p> 自动注入中获取bean工厂,用于优先实例化bean确保spring中的对象和此处一致
|
||||
* @author :Wind
|
||||
* 2023/4/8 13:44
|
||||
**/
|
||||
public class AutoBeanFac {
|
||||
|
||||
}
|
||||
@ -19,6 +19,9 @@ public class RedisUtils {
|
||||
|
||||
@Autowired
|
||||
public void init(RedisConnectionFactory connectionFactory) {
|
||||
if (connectionFactory == null){
|
||||
log.error("RedisConnectionFactory not found");
|
||||
}
|
||||
// 指定相应的序列化方案
|
||||
StringRedisSerializer keySerializer = new StringRedisSerializer();
|
||||
JdkSerializationRedisSerializer valueSerializer = new JdkSerializationRedisSerializer();
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package kim.wind.sms.autoimmit.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
@ -13,6 +14,7 @@ import org.springframework.context.ApplicationContextAware;
|
||||
* @author :Wind
|
||||
* 2023/3/25 0:13
|
||||
**/
|
||||
@Slf4j
|
||||
public class SpringUtil implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext applicationContext;
|
||||
@ -38,6 +40,7 @@ public class SpringUtil implements ApplicationContextAware {
|
||||
try {
|
||||
return getApplicationContext().getBean(name);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
|
||||
@ -47,6 +50,7 @@ public class SpringUtil implements ApplicationContextAware {
|
||||
try {
|
||||
return getApplicationContext().getBean(clazz);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -61,7 +65,6 @@ public class SpringUtil implements ApplicationContextAware {
|
||||
|
||||
/**
|
||||
* <p>说明:创建一个bean
|
||||
*
|
||||
* @param
|
||||
* @name: createBean
|
||||
* @author :Wind
|
||||
|
||||
@ -8,15 +8,15 @@ package kim.wind.sms.comm.enumerate;
|
||||
**/
|
||||
public enum SupplierType {
|
||||
/** 阿里云*/
|
||||
ALIBABA("alibaba"),
|
||||
ALIBABA("阿里云短信"),
|
||||
/** 华为云*/
|
||||
HUAWEI("huawei"),
|
||||
HUAWEI("华为云短信"),
|
||||
/** 云片*/
|
||||
YUNPIAN("yunpian"),
|
||||
YUNPIAN("云片短信"),
|
||||
/** 腾讯云*/
|
||||
TENCENT("tencent"),
|
||||
TENCENT("腾讯云短信"),
|
||||
/** 合一短信*/
|
||||
UNI_SMS("unisms")
|
||||
UNI_SMS("合一短信")
|
||||
;
|
||||
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* @author :Wind
|
||||
* 2023/4/7 15:26
|
||||
**/
|
||||
|
||||
public class BeanFactory {
|
||||
|
||||
/** 定时器*/
|
||||
|
||||
@ -3,6 +3,7 @@ package kim.wind.sms.comm.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import kim.wind.sms.comm.exception.SmsBlendException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -20,6 +21,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* @author :Wind
|
||||
* 2023/3/25 18:26
|
||||
**/
|
||||
@Slf4j
|
||||
public class TimeExpiredPoolCache {
|
||||
/**
|
||||
* 持久化文件格式
|
||||
@ -70,6 +72,7 @@ public class TimeExpiredPoolCache {
|
||||
return true;
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
log.error(ignored.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -81,6 +84,7 @@ public class TimeExpiredPoolCache {
|
||||
try {
|
||||
clearExpiredCaches();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
throw new SmsBlendException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,6 +72,7 @@ public class HuaweiSmsImpl implements SmsBlend {
|
||||
HuaweiResponse huaweiResponse = res.get(HuaweiResponse.class);
|
||||
smsResponse.setErrMessage(huaweiResponse.getDescription());
|
||||
smsResponse.setErrorCode(huaweiResponse.getCode());
|
||||
log.debug(huaweiResponse.getDescription());
|
||||
})
|
||||
.execute();
|
||||
return smsResponse;
|
||||
|
||||
@ -13,10 +13,11 @@ import kim.wind.sms.comm.annotation.Restricted;
|
||||
import kim.wind.sms.comm.delayedTime.DelayedTime;
|
||||
import kim.wind.sms.comm.exception.SmsBlendException;
|
||||
import kim.wind.sms.tencent.config.TencentConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Slf4j
|
||||
public class TencentSmsImpl implements SmsBlend {
|
||||
|
||||
private TencentConfig tencentSmsConfig;
|
||||
@ -66,6 +67,7 @@ public class TencentSmsImpl implements SmsBlend {
|
||||
JSONObject jsonObject = JSON.parseObject(s1);
|
||||
if (!"Ok".equals(jsonObject.getString("Code"))) {
|
||||
smsResponse.setErrMessage(jsonObject.getString("Message"));
|
||||
log.debug(smsResponse.getErrMessage());
|
||||
}
|
||||
smsResponse.setMessage(jsonObject.getString("Message"));
|
||||
smsResponse.setBizId(res.getRequestId());
|
||||
@ -108,6 +110,7 @@ public class TencentSmsImpl implements SmsBlend {
|
||||
JSONObject jsonObject = JSON.parseObject(s1);
|
||||
if (!"Ok".equals(jsonObject.getString("Code"))) {
|
||||
smsResponse.setErrMessage(jsonObject.getString("Message"));
|
||||
log.debug(jsonObject.getString("Message"));
|
||||
}
|
||||
smsResponse.setMessage(jsonObject.getString("Message"));
|
||||
smsResponse.setBizId(res.getRequestId());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user