123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package cn.iocoder.dashboard.framework.sms;
- import org.apache.commons.lang3.StringUtils;
- import java.util.Arrays;
- import java.util.Collection;
- import java.util.Collections;
- /**
- * 短信父接口
- *
- * @author zzf
- * @date 2021/1/25 14:14
- */
- public interface SmsClient<R> {
- /**
- * 发送消息
- *
- * @param msgBody 消息内容
- * @param targets 发送对象列表
- * @return 是否发送成功
- */
- SmsResult<R> send(SmsBody msgBody, Collection<String> targets);
- /**
- * 发送消息
- *
- * @param msgBody 消息内容
- * @param target 发送对象
- * @return 是否发送成功
- */
- default SmsResult<R> send(SmsBody msgBody, String target) {
- if (StringUtils.isBlank(target)) {
- return failResult();
- }
- return send(msgBody, Collections.singletonList(target));
- }
- /**
- * 发送消息
- *
- * @param msgBody 消息内容
- * @param targets 发送对象列表
- * @return 是否发送成功
- */
- default SmsResult<R> send(SmsBody msgBody, String... targets) {
- if (targets == null) {
- return failResult();
- }
- return send(msgBody, Arrays.asList(targets));
- }
- /**
- * 异步发送消息
- *
- * @param msgBody 消息内容
- * @param targets 发送对象列表
- * @return 是否发送成功
- */
- SmsResult<R> sendAsync(SmsBody msgBody, Collection<String> targets);
- /**
- * 异步发送消息
- *
- * @param msgBody 消息内容
- * @param target 发送对象
- * @return 是否发送成功
- */
- default SmsResult<R> sendAsync(SmsBody msgBody, String target) {
- if (StringUtils.isBlank(target)) {
- return failResult("target must not null.");
- }
- return sendAsync(msgBody, Collections.singletonList(target));
- }
- /**
- * 异步发送消息
- *
- * @param msgBody 消息内容
- * @param targets 发送对象列表
- * @return 是否发送成功
- */
- default SmsResult<R> sendAsync(SmsBody msgBody, String... targets) {
- if (targets == null) {
- return failResult("targets must not null.");
- }
- return sendAsync(msgBody, Arrays.asList(targets));
- }
- default SmsResult<R> failResult() {
- SmsResult<R> resultBody = new SmsResult<>();
- resultBody.setSuccess(false);
- return resultBody;
- }
- default SmsResult<R> failResult(String message) {
- SmsResult<R> resultBody = failResult();
- resultBody.setMessage(message);
- return resultBody;
- }
- }
|