SmsMessage.java
1.82 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
package com.diligrp.cashier.assistant.domain;
import org.apache.commons.text.StringSubstitutor;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class SmsMessage {
// 短信服务通道模版标识 - 支持短信模版的服务通道使用
private final String templateId;
// 手机号
private final List<String> telephones;
// 解析模版变量前的原始内容
private final String rawContent;
// 解析模版变量后的短信内容
private String content;
// 模版变量
private final Map<String, String> params;
// 消息签名
private final String signature;
public SmsMessage(String templateId, List<String> telephones, String rawContent, Map<String, String> params, String signature) {
this.templateId = templateId;
this.telephones = telephones;
this.rawContent = rawContent;
this.params = Objects.nonNull(params) ? new HashMap<>(params) : null;
this.signature = signature;
}
public String getTemplateId() {
return templateId;
}
public List<String> getTelephones() {
return telephones;
}
public synchronized String getContent() { // 延迟解析模版变量
if (content == null) {
content = parseContent();
}
return content;
}
public String getRawContent() {
return rawContent;
}
public Map<String, String> getParams() {
return params;
}
public String getSignature() {
return signature;
}
private String parseContent() {
if (Objects.nonNull(this.params)) { // 解析模版变量
StringSubstitutor engine = new StringSubstitutor(this.params);
return engine.replace(this.rawContent);
}
return rawContent;
}
}