mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-06 17:08:40 +08:00
update 优化
This commit is contained in:
parent
bea0c20e67
commit
4a5e342d15
@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -191,10 +192,10 @@ public class SmsUtils {
|
|||||||
* @param <T> 集合泛型
|
* @param <T> 集合泛型
|
||||||
* @param <E> 想要的数组类型
|
* @param <E> 想要的数组类型
|
||||||
*/
|
*/
|
||||||
public static <E, T> E[] toArray(Collection<T> list, Predicate<T> predicate, E[] array) {
|
public static <E, T> E[] toArray(Collection<T> list, Predicate<T> predicate, Function<? super T, ? extends E> mapper, E[] array) {
|
||||||
if (isEmpty(list)) {
|
if (isEmpty(list)) {
|
||||||
return array.clone();
|
return array.clone();
|
||||||
}
|
}
|
||||||
return list.stream().filter(predicate).toArray(size -> array.clone());
|
return list.stream().filter(predicate).map(mapper).toArray(size -> array.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ public class TencentSmsImpl extends AbstractSmsBlend<TencentConfig> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SmsResponse sendMessage(String phone, String templateId, LinkedHashMap<String, String> messages) {
|
public SmsResponse sendMessage(String phone, String templateId, LinkedHashMap<String, String> messages) {
|
||||||
return getSmsResponse(new String[]{StrUtil.addPrefixIfNot(phone, "+86")}, SmsUtils.toArray(messages.values(), SmsUtils::isNotEmpty, new String[0]), templateId);
|
return getSmsResponse(new String[]{StrUtil.addPrefixIfNot(phone, "+86")}, toArray(messages), templateId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -62,7 +62,11 @@ public class TencentSmsImpl extends AbstractSmsBlend<TencentConfig> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SmsResponse massTexting(List<String> phones, String templateId, LinkedHashMap<String, String> messages) {
|
public SmsResponse massTexting(List<String> phones, String templateId, LinkedHashMap<String, String> messages) {
|
||||||
return getSmsResponse(SmsUtils.listToArray(phones), SmsUtils.toArray(messages.values(), SmsUtils::isNotEmpty, new String[0]), templateId);
|
return getSmsResponse(SmsUtils.listToArray(phones), toArray(messages), templateId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] toArray(LinkedHashMap<String, String> messages){
|
||||||
|
return SmsUtils.toArray(messages.values(), SmsUtils::isNotEmpty, s -> s, new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SmsResponse getSmsResponse(String[] phones, String[] messages, String templateId) {
|
private SmsResponse getSmsResponse(String[] phones, String[] messages, String templateId) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user