SmsClient.java
2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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;
}
}