Merge branch 'dev-3.0.x' into oa-plugin

This commit is contained in:
东风 2023-12-15 10:34:40 +08:00
commit 91807cfe61
9 changed files with 106 additions and 30 deletions

View File

@ -78,7 +78,7 @@
url: https://XXXXX.cn-north-4.XXXXXXXX.com:443 url: https://XXXXX.cn-north-4.XXXXXXXX.com:443
zhutong: zhutong:
#助通短信 #助通短信
#助通终端用户管理的用户名 username 必填非登录账号密码请登录后台管理地址进行查看http://mix2.zthysms.com/login #助通终端用户管理的用户名 username 必填非登录账号密码请登录后台管理地址进行查看https://mix2.zthysms.com/login
accessKeyId: tushu1122XXX accessKeyId: tushu1122XXX
#助通终端用户管理的用户名 passwrod 必填; #助通终端用户管理的用户名 passwrod 必填;
accessKeySecret: UbXXX4SL accessKeySecret: UbXXX4SL

View File

@ -28,7 +28,7 @@
<licenses> <licenses>
<license> <license>
<name>Apache 2</name> <name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution> <distribution>repo</distribution>
<comments>A business-friendly OSS license</comments> <comments>A business-friendly OSS license</comments>
</license> </license>

View File

@ -15,9 +15,9 @@ public interface CoreMethodProcessor extends SmsProcessor {
default Object[] preProcessor(Method method, Object source, Object[] param) { default Object[] preProcessor(Method method, Object source, Object[] param) {
String name = method.getName(); String name = method.getName();
int parameterCount = method.getParameterCount(); int parameterCount = method.getParameterCount();
if ("sendMessage".equals(method.getName())) { if ("sendMessage".equals(name)) {
if (NumberOfParasmeters.TWO == NumberOfParasmeters.getNumberOfParasmetersEnum(parameterCount)) { if (NumberOfParasmeters.TWO == NumberOfParasmeters.getNumberOfParasmetersEnum(parameterCount)) {
sendMessagePreProcess((String) param[0],(String) param[1]); sendMessagePreProcess((String) param[0], param[1]);
return param; return param;
} }
if (NumberOfParasmeters.THREE == NumberOfParasmeters.getNumberOfParasmetersEnum(parameterCount)) { if (NumberOfParasmeters.THREE == NumberOfParasmeters.getNumberOfParasmetersEnum(parameterCount)) {
@ -25,7 +25,7 @@ public interface CoreMethodProcessor extends SmsProcessor {
return param; return param;
} }
} }
if ("massTexting".equals(method.getName())) { if ("massTexting".equals(name)) {
if (NumberOfParasmeters.TWO == NumberOfParasmeters.getNumberOfParasmetersEnum(parameterCount)) { if (NumberOfParasmeters.TWO == NumberOfParasmeters.getNumberOfParasmetersEnum(parameterCount)) {
massTextingPreProcess((List<String>)param[0],(String)param[1]); massTextingPreProcess((List<String>)param[0],(String)param[1]);
return param; return param;
@ -37,7 +37,7 @@ public interface CoreMethodProcessor extends SmsProcessor {
} }
return param; return param;
} }
void sendMessagePreProcess(String phone, String message); void sendMessagePreProcess(String phone, Object message);
void sendMessageByTemplatePreProcess(String phone, String templateId, LinkedHashMap<String, String> messages); void sendMessageByTemplatePreProcess(String phone, String templateId, LinkedHashMap<String, String> messages);
void massTextingPreProcess(List<String> phones, String message); void massTextingPreProcess(List<String> phones, String message);
void massTextingByTemplatePreProcess(List<String> phones, String templateId, LinkedHashMap<String, String> messages); void massTextingByTemplatePreProcess(List<String> phones, String templateId, LinkedHashMap<String, String> messages);

View File

@ -28,7 +28,7 @@ public class BlackListProcessor implements CoreMethodProcessor, SmsDaoAware {
} }
@Override @Override
public void sendMessagePreProcess(String phone, String message) { public void sendMessagePreProcess(String phone, Object message) {
doRestricted(Collections.singletonList(phone)); doRestricted(Collections.singletonList(phone));
} }
@ -49,6 +49,9 @@ public class BlackListProcessor implements CoreMethodProcessor, SmsDaoAware {
public void doRestricted(List<String> phones) { public void doRestricted(List<String> phones) {
ArrayList<String> blackList = (ArrayList<String>) smsDao.get("sms:blacklist:global"); ArrayList<String> blackList = (ArrayList<String>) smsDao.get("sms:blacklist:global");
if(null==blackList){
return;
}
for (String phone : phones) { for (String phone : phones) {
if (blackList.stream().filter(black -> black.replace("-","").equals(phone)).findAny().isPresent()) { if (blackList.stream().filter(black -> black.replace("-","").equals(phone)).findAny().isPresent()) {
throw new SmsBlendException("The phone:", phone + " hit global blacklist"); throw new SmsBlendException("The phone:", phone + " hit global blacklist");

View File

@ -25,6 +25,9 @@ public class BlackListRecordingProcessor implements SmsProcessor, SmsDaoAware, S
@Setter @Setter
Object smsConfig; Object smsConfig;
public int getOrder(){
return 1;
}
@Override @Override
public Object[] preProcessor(Method method, Object source, Object[] param) { public Object[] preProcessor(Method method, Object source, Object[] param) {

View File

@ -21,7 +21,7 @@ public class CoreMethodParamValidateProcessor implements CoreMethodProcessor {
} }
@Override @Override
public void sendMessagePreProcess(String phone, String message) { public void sendMessagePreProcess(String phone, Object message) {
validatePhone(phone); validatePhone(phone);
validateMessage(message); validateMessage(message);
} }
@ -44,11 +44,20 @@ public class CoreMethodParamValidateProcessor implements CoreMethodProcessor {
validateMessages(templateId, messages); validateMessages(templateId, messages);
} }
public void validateMessage(String message) { public void validateMessage(Object messageObj) {
if (messageObj instanceof String){
String message = (String) messageObj;
if (null == message || "".equals(message)) { if (null == message || "".equals(message)) {
throw new SmsBlendException("cant send a null message!"); throw new SmsBlendException("cant send a null message!");
} }
} }
if (messageObj instanceof Map){
Map message = (Map) messageObj;
if (message.size()<1) {
throw new SmsBlendException("cant send a null message!");
}
}
}
public void validatePhone(String phone) { public void validatePhone(String phone) {
if (null == phone || "".equals(phone)) { if (null == phone || "".equals(phone)) {

View File

@ -40,7 +40,7 @@ public class RestrictedProcessor implements CoreMethodProcessor, SmsDaoAware {
} }
@Override @Override
public void sendMessagePreProcess(String phone, String message) { public void sendMessagePreProcess(String phone, Object message) {
doRestricted(Collections.singletonList(phone)); doRestricted(Collections.singletonList(phone));
} }

View File

@ -51,7 +51,17 @@ public class SingleBlendRestrictedProcessor implements SmsProcessor, SmsDaoAware
SmsBlend smsBlend = (SmsBlend) source; SmsBlend smsBlend = (SmsBlend) source;
String configId = smsBlend.getConfigId(); String configId = smsBlend.getConfigId();
Map targetConfig = (Map) smsBlendsConfig.get(configId); Map targetConfig = (Map) smsBlendsConfig.get(configId);
int maximum = (int) targetConfig.get("maximum"); Object maximumObj = targetConfig.get("maximum");
if (SmsUtils.isEmpty(maximumObj)) {
return param;
}
int maximum = 0;
try{
maximum = (int) maximumObj ;
}catch (Exception e){
log.error("获取厂商级发送上限参数错误!请检查!");
throw new IllegalArgumentException("获取厂商级发送上限参数错误");
}
Integer i = (Integer) smsDao.get(REDIS_KEY + configId + "maximum"); Integer i = (Integer) smsDao.get(REDIS_KEY + configId + "maximum");
if (SmsUtils.isEmpty(i)) { if (SmsUtils.isEmpty(i)) {
smsDao.set(REDIS_KEY + configId + "maximum", 1); smsDao.set(REDIS_KEY + configId + "maximum", 1);

View File

@ -24,58 +24,101 @@ public class SmsProcessorTest {
/** /**
* 填测试手机号 * 填测试手机号
*/ */
private static final String PHONE = "13899998888"; private static final String PHONE = "11111111111";
private static final String PHONE1 = "22222222222";
//基础发送测试即黑名单账户限制渠道限制都不预设直接发送新增参数全为空
@Test
public void test1() {
System.out.println("------------");
SmsBlend smsBlend = SmsFactory.getBySupplier(SupplierConstant.UNISMS);
SmsResponse smsResponse = smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6));
Assert.isTrue(smsResponse.isSuccess());
System.out.println(smsResponse.getData());
}
//第二个账号的测试
@Test
public void test2() {
System.out.println("------------");
SmsBlend smsBlend = SmsFactory.getBySupplier(SupplierConstant.HUAWEI);
SmsResponse smsResponse = smsBlend.sendMessage(PHONE1, SmsUtils.getRandomInt(6));
Assert.isTrue(smsResponse.isSuccess());
System.out.println(smsResponse.getData());
}
//参数校验测试 //参数校验测试
@Test @Test
public void testParamValidate() { public void test3() {
System.out.println("------------");
SmsBlendException knowEx = null; SmsBlendException knowEx = null;
try { try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).sendMessage("", SmsUtils.getRandomInt(6)); SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, new LinkedHashMap<>());
} catch (SmsBlendException e) { } catch (SmsBlendException e) {
knowEx = e; knowEx = e;
System.out.println(knowEx.getMessage());
} }
Assert.notNull(knowEx); Assert.notNull(knowEx);
knowEx = null; knowEx = null;
try { try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).sendMessage(PHONE, ""); SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage("", SmsUtils.getRandomInt(6));
} catch (SmsBlendException e) { } catch (SmsBlendException e) {
knowEx = e; knowEx = e;
System.out.println(knowEx.getMessage());
} }
Assert.notNull(knowEx); Assert.notNull(knowEx);
knowEx = null; knowEx = null;
try { try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).sendMessage(PHONE, "111", new LinkedHashMap<>()); SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, "");
} catch (SmsBlendException e) { } catch (SmsBlendException e) {
knowEx = e; knowEx = e;
System.out.println(knowEx.getMessage());
} }
Assert.notNull(knowEx); Assert.notNull(knowEx);
knowEx = null; knowEx = null;
try { try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).massTexting(Collections.singletonList(PHONE), ""); SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, "111", new LinkedHashMap<>());
} catch (SmsBlendException e) { } catch (SmsBlendException e) {
knowEx = e; knowEx = e;
System.out.println(knowEx.getMessage());
} }
Assert.notNull(knowEx); Assert.notNull(knowEx);
knowEx = null; knowEx = null;
try { try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).massTexting(Collections.singletonList(PHONE), "2222", new LinkedHashMap<>()); SmsFactory.getBySupplier(SupplierConstant.UNISMS).massTexting(Collections.singletonList(PHONE), "");
} catch (SmsBlendException e) { } catch (SmsBlendException e) {
knowEx = e; knowEx = e;
System.out.println(knowEx.getMessage());
} }
Assert.notNull(knowEx); Assert.notNull(knowEx);
knowEx = null; knowEx = null;
try { try {
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).massTexting(new ArrayList<String>(), "321321"); SmsFactory.getBySupplier(SupplierConstant.UNISMS).massTexting(Collections.singletonList(PHONE), "2222", new LinkedHashMap<>());
} catch (SmsBlendException e) { } catch (SmsBlendException e) {
knowEx = e; knowEx = e;
System.out.println(knowEx.getMessage());
}
Assert.notNull(knowEx);
knowEx = null;
try {
SmsFactory.getBySupplier(SupplierConstant.UNISMS).massTexting(new ArrayList<String>(), "321321");
} catch (SmsBlendException e) {
knowEx = e;
System.out.println(knowEx.getMessage());
} }
Assert.notNull(knowEx); Assert.notNull(knowEx);
} }
//黑名单测试 黑名单手机号13899998888 //黑名单测试
@Test @Test
public void testBlackList() { public void test4() {
System.out.println("------------");
SmsBlend smsBlend = SmsFactory.getBySupplier(SupplierConstant.UNISMS); SmsBlend smsBlend = SmsFactory.getBySupplier(SupplierConstant.UNISMS);
//单黑名单添加 //单黑名单添加
smsBlend.joinInBlacklist(PHONE); smsBlend.joinInBlacklist(PHONE);
@ -84,6 +127,7 @@ public class SmsProcessorTest {
smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6)); smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6));
} catch (SmsBlendException e) { } catch (SmsBlendException e) {
knowEx = e; knowEx = e;
System.out.println(knowEx.getMessage());
} }
Assert.notNull(knowEx); Assert.notNull(knowEx);
//单黑名单移除 //单黑名单移除
@ -97,18 +141,21 @@ public class SmsProcessorTest {
smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6)); smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6));
} catch (SmsBlendException e) { } catch (SmsBlendException e) {
knowEx = e; knowEx = e;
System.out.println(knowEx.getMessage());
} }
Assert.notNull(knowEx); Assert.notNull(knowEx);
//批量黑名单添加 //批量黑名单添加
smsBlend.removeFromBlacklist(PHONE); smsBlend.batchRemovalFromBlacklist(Collections.singletonList(PHONE));
smsResponse = smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6)); smsResponse = smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6));
Assert.isTrue(smsResponse.isSuccess()); Assert.isTrue(smsResponse.isSuccess());
} }
//账号级上限测试需成功发送一笔特殊配置 //账号级上限测试需成功发送4笔再发就会报错 参数配置 4
@Test @Test
public void testAcctLimt() { public void test5() {
System.out.println("------------");
SmsResponse smsResponse = SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6)); SmsResponse smsResponse = SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6));
Assert.isTrue(smsResponse.isSuccess()); Assert.isTrue(smsResponse.isSuccess());
SmsBlendException knowEx = null; SmsBlendException knowEx = null;
@ -116,21 +163,25 @@ public class SmsProcessorTest {
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6)); SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6));
} catch (SmsBlendException e) { } catch (SmsBlendException e) {
knowEx = e; knowEx = e;
System.out.println(knowEx.getMessage());
} }
Assert.notNull(knowEx); Assert.notNull(knowEx);
} }
//账号级上限测试需成功发送一笔特殊配置 //渠道级上限测试需成功发送6笔再发就会报错 参数配置 6
@Test @Test
public void testChannelLimt() { public void test6() {
SmsResponse smsResponse = SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6)); System.out.println("------------");
SmsResponse smsResponse = SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE1, SmsUtils.getRandomInt(6));
Assert.isTrue(smsResponse.isSuccess()); Assert.isTrue(smsResponse.isSuccess());
SmsBlendException knowEx = null; SmsBlendException knowEx = null;
try { try {
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6)); SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE1, SmsUtils.getRandomInt(6));
} catch (SmsBlendException e) { } catch (SmsBlendException e) {
knowEx = e; knowEx = e;
System.out.println(knowEx.getMessage());
} }
Assert.notNull(knowEx); Assert.notNull(knowEx);
} }