mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-07 01:18:33 +08:00
Merge branch 'dev-3.0.x' into oa-plugin
This commit is contained in:
commit
91807cfe61
@ -78,7 +78,7 @@
|
||||
url: https://XXXXX.cn-north-4.XXXXXXXX.com:443
|
||||
zhutong:
|
||||
#助通短信
|
||||
#助通终端用户管理的用户名 username 必填;非登录账号密码,请登录后台管理地址进行查看:http://mix2.zthysms.com/login
|
||||
#助通终端用户管理的用户名 username 必填;非登录账号密码,请登录后台管理地址进行查看:https://mix2.zthysms.com/login
|
||||
accessKeyId: tushu1122XXX
|
||||
#助通终端用户管理的用户名 passwrod 必填;
|
||||
accessKeySecret: UbXXX4SL
|
||||
|
||||
2
pom.xml
2
pom.xml
@ -28,7 +28,7 @@
|
||||
<licenses>
|
||||
<license>
|
||||
<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>
|
||||
<comments>A business-friendly OSS license</comments>
|
||||
</license>
|
||||
|
||||
@ -15,9 +15,9 @@ public interface CoreMethodProcessor extends SmsProcessor {
|
||||
default Object[] preProcessor(Method method, Object source, Object[] param) {
|
||||
String name = method.getName();
|
||||
int parameterCount = method.getParameterCount();
|
||||
if ("sendMessage".equals(method.getName())) {
|
||||
if ("sendMessage".equals(name)) {
|
||||
if (NumberOfParasmeters.TWO == NumberOfParasmeters.getNumberOfParasmetersEnum(parameterCount)) {
|
||||
sendMessagePreProcess((String) param[0],(String) param[1]);
|
||||
sendMessagePreProcess((String) param[0], param[1]);
|
||||
return param;
|
||||
}
|
||||
if (NumberOfParasmeters.THREE == NumberOfParasmeters.getNumberOfParasmetersEnum(parameterCount)) {
|
||||
@ -25,7 +25,7 @@ public interface CoreMethodProcessor extends SmsProcessor {
|
||||
return param;
|
||||
}
|
||||
}
|
||||
if ("massTexting".equals(method.getName())) {
|
||||
if ("massTexting".equals(name)) {
|
||||
if (NumberOfParasmeters.TWO == NumberOfParasmeters.getNumberOfParasmetersEnum(parameterCount)) {
|
||||
massTextingPreProcess((List<String>)param[0],(String)param[1]);
|
||||
return param;
|
||||
@ -37,7 +37,7 @@ public interface CoreMethodProcessor extends SmsProcessor {
|
||||
}
|
||||
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 massTextingPreProcess(List<String> phones, String message);
|
||||
void massTextingByTemplatePreProcess(List<String> phones, String templateId, LinkedHashMap<String, String> messages);
|
||||
|
||||
@ -28,7 +28,7 @@ public class BlackListProcessor implements CoreMethodProcessor, SmsDaoAware {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessagePreProcess(String phone, String message) {
|
||||
public void sendMessagePreProcess(String phone, Object message) {
|
||||
doRestricted(Collections.singletonList(phone));
|
||||
}
|
||||
|
||||
@ -49,6 +49,9 @@ public class BlackListProcessor implements CoreMethodProcessor, SmsDaoAware {
|
||||
|
||||
public void doRestricted(List<String> phones) {
|
||||
ArrayList<String> blackList = (ArrayList<String>) smsDao.get("sms:blacklist:global");
|
||||
if(null==blackList){
|
||||
return;
|
||||
}
|
||||
for (String phone : phones) {
|
||||
if (blackList.stream().filter(black -> black.replace("-","").equals(phone)).findAny().isPresent()) {
|
||||
throw new SmsBlendException("The phone:", phone + " hit global blacklist!");
|
||||
|
||||
@ -25,6 +25,9 @@ public class BlackListRecordingProcessor implements SmsProcessor, SmsDaoAware, S
|
||||
@Setter
|
||||
Object smsConfig;
|
||||
|
||||
public int getOrder(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] preProcessor(Method method, Object source, Object[] param) {
|
||||
|
||||
@ -21,7 +21,7 @@ public class CoreMethodParamValidateProcessor implements CoreMethodProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessagePreProcess(String phone, String message) {
|
||||
public void sendMessagePreProcess(String phone, Object message) {
|
||||
validatePhone(phone);
|
||||
validateMessage(message);
|
||||
}
|
||||
@ -44,11 +44,20 @@ public class CoreMethodParamValidateProcessor implements CoreMethodProcessor {
|
||||
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)) {
|
||||
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) {
|
||||
if (null == phone || "".equals(phone)) {
|
||||
|
||||
@ -40,7 +40,7 @@ public class RestrictedProcessor implements CoreMethodProcessor, SmsDaoAware {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessagePreProcess(String phone, String message) {
|
||||
public void sendMessagePreProcess(String phone, Object message) {
|
||||
doRestricted(Collections.singletonList(phone));
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,17 @@ public class SingleBlendRestrictedProcessor implements SmsProcessor, SmsDaoAware
|
||||
SmsBlend smsBlend = (SmsBlend) source;
|
||||
String configId = smsBlend.getConfigId();
|
||||
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");
|
||||
if (SmsUtils.isEmpty(i)) {
|
||||
smsDao.set(REDIS_KEY + configId + "maximum", 1);
|
||||
|
||||
@ -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
|
||||
public void testParamValidate() {
|
||||
public void test3() {
|
||||
System.out.println("------------");
|
||||
|
||||
SmsBlendException knowEx = null;
|
||||
try {
|
||||
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).sendMessage("", SmsUtils.getRandomInt(6));
|
||||
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, new LinkedHashMap<>());
|
||||
} catch (SmsBlendException e) {
|
||||
knowEx = e;
|
||||
System.out.println(knowEx.getMessage());
|
||||
}
|
||||
Assert.notNull(knowEx);
|
||||
knowEx = null;
|
||||
try {
|
||||
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).sendMessage(PHONE, "");
|
||||
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage("", SmsUtils.getRandomInt(6));
|
||||
} catch (SmsBlendException e) {
|
||||
knowEx = e;
|
||||
System.out.println(knowEx.getMessage());
|
||||
}
|
||||
Assert.notNull(knowEx);
|
||||
knowEx = null;
|
||||
try {
|
||||
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).sendMessage(PHONE, "111", new LinkedHashMap<>());
|
||||
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, "");
|
||||
} catch (SmsBlendException e) {
|
||||
knowEx = e;
|
||||
System.out.println(knowEx.getMessage());
|
||||
}
|
||||
Assert.notNull(knowEx);
|
||||
knowEx = null;
|
||||
try {
|
||||
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).massTexting(Collections.singletonList(PHONE), "");
|
||||
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, "111", new LinkedHashMap<>());
|
||||
} catch (SmsBlendException e) {
|
||||
knowEx = e;
|
||||
System.out.println(knowEx.getMessage());
|
||||
}
|
||||
Assert.notNull(knowEx);
|
||||
knowEx = null;
|
||||
try {
|
||||
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).massTexting(Collections.singletonList(PHONE), "2222", new LinkedHashMap<>());
|
||||
SmsFactory.getBySupplier(SupplierConstant.UNISMS).massTexting(Collections.singletonList(PHONE), "");
|
||||
} catch (SmsBlendException e) {
|
||||
knowEx = e;
|
||||
System.out.println(knowEx.getMessage());
|
||||
}
|
||||
Assert.notNull(knowEx);
|
||||
knowEx = null;
|
||||
try {
|
||||
SmsFactory.getBySupplier(SupplierConstant.ALIBABA).massTexting(new ArrayList<String>(), "321321");
|
||||
SmsFactory.getBySupplier(SupplierConstant.UNISMS).massTexting(Collections.singletonList(PHONE), "2222", new LinkedHashMap<>());
|
||||
} catch (SmsBlendException 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);
|
||||
}
|
||||
|
||||
//黑名单测试 黑名单手机号13899998888
|
||||
//黑名单测试
|
||||
@Test
|
||||
public void testBlackList() {
|
||||
public void test4() {
|
||||
System.out.println("------------");
|
||||
|
||||
SmsBlend smsBlend = SmsFactory.getBySupplier(SupplierConstant.UNISMS);
|
||||
//单黑名单添加
|
||||
smsBlend.joinInBlacklist(PHONE);
|
||||
@ -84,6 +127,7 @@ public class SmsProcessorTest {
|
||||
smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6));
|
||||
} catch (SmsBlendException e) {
|
||||
knowEx = e;
|
||||
System.out.println(knowEx.getMessage());
|
||||
}
|
||||
Assert.notNull(knowEx);
|
||||
//单黑名单移除
|
||||
@ -97,18 +141,21 @@ public class SmsProcessorTest {
|
||||
smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6));
|
||||
} catch (SmsBlendException e) {
|
||||
knowEx = e;
|
||||
System.out.println(knowEx.getMessage());
|
||||
}
|
||||
Assert.notNull(knowEx);
|
||||
//批量黑名单添加
|
||||
smsBlend.removeFromBlacklist(PHONE);
|
||||
smsBlend.batchRemovalFromBlacklist(Collections.singletonList(PHONE));
|
||||
smsResponse = smsBlend.sendMessage(PHONE, SmsUtils.getRandomInt(6));
|
||||
Assert.isTrue(smsResponse.isSuccess());
|
||||
|
||||
}
|
||||
|
||||
//账号级上限测试、需成功发送一笔,特殊配置
|
||||
//账号级上限测试、需成功发送4笔,再发就会报错 参数配置 4
|
||||
@Test
|
||||
public void testAcctLimt() {
|
||||
public void test5() {
|
||||
System.out.println("------------");
|
||||
|
||||
SmsResponse smsResponse = SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6));
|
||||
Assert.isTrue(smsResponse.isSuccess());
|
||||
SmsBlendException knowEx = null;
|
||||
@ -116,21 +163,25 @@ public class SmsProcessorTest {
|
||||
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6));
|
||||
} catch (SmsBlendException e) {
|
||||
knowEx = e;
|
||||
System.out.println(knowEx.getMessage());
|
||||
}
|
||||
Assert.notNull(knowEx);
|
||||
}
|
||||
|
||||
//账号级上限测试、需成功发送一笔,特殊配置
|
||||
//渠道级上限测试、需成功发送6笔,再发就会报错 参数配置 6
|
||||
@Test
|
||||
public void testChannelLimt() {
|
||||
SmsResponse smsResponse = SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6));
|
||||
public void test6() {
|
||||
System.out.println("------------");
|
||||
|
||||
SmsResponse smsResponse = SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE1, SmsUtils.getRandomInt(6));
|
||||
Assert.isTrue(smsResponse.isSuccess());
|
||||
|
||||
SmsBlendException knowEx = null;
|
||||
try {
|
||||
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE, SmsUtils.getRandomInt(6));
|
||||
SmsFactory.getBySupplier(SupplierConstant.UNISMS).sendMessage(PHONE1, SmsUtils.getRandomInt(6));
|
||||
} catch (SmsBlendException e) {
|
||||
knowEx = e;
|
||||
System.out.println(knowEx.getMessage());
|
||||
}
|
||||
Assert.notNull(knowEx);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user