TemplateMessageService.java
6.06 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package cn.fw.hestia.rpc.passport;
import cn.fw.data.base.domain.common.Message;
import cn.fw.hestia.rpc.passport.dto.TemplateMessageParam;
import cn.fw.passport.sdk.api.WxMpTemplateMessageApi;
import cn.fw.passport.sdk.api.param.WxMpTempMessageData;
import cn.fw.passport.sdk.api.param.WxMpTempMessageParam;
import cn.fw.hestia.rpc.passport.dto.RenewInsurNoticeMessageParam;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* passport系统-模板消息服务
* <p>
* create at 2019-05-15
*
* @author kurisu
*/
@Slf4j
@Service
public class TemplateMessageService {
private final WxMpTemplateMessageApi wxMpTemplateMessageApi;
public TemplateMessageService(final WxMpTemplateMessageApi wxMpTemplateMessageApi) {
this.wxMpTemplateMessageApi = wxMpTemplateMessageApi;
}
/**
* 消息模板Code
*/
@Value("${templateCode}")
@Getter
private String templateCode = "";
/**
* 小程序页面--续保提醒/保险估算
*/
private static final String PAGE_PATH_INSU = "/pgCas/Insurance/Append/index?bizType={0}";
/**
* 保养预约页面
*/
private static final String RESE_URL = "/pgCas/Appoint/Index/index";
/**
* 发送续保提醒通知
*
* @param messageParam
*/
public String sendTemplateMessage(TemplateMessageParam messageParam) {
log.info("开始发送续保提醒通知,senderId:{}", messageParam);
try {
WxMpTempMessageParam param = new WxMpTempMessageParam();
param.setCusId(messageParam.getMemberId());
param.setTempCode(getTemplateCode());
WxMpTempMessageData remark = new WxMpTempMessageData();
remark.setValue("点击“详情”进行保险估价⬇");
remark.setColor("#a61b29");
param.setRemark(remark);
WxMpTempMessageData title = new WxMpTempMessageData();
title.setValue("您好!您购买的车险即将到期,现在预约续保可享养车大礼包!");
param.setTitle(title);
List<WxMpTempMessageData> keywords = new ArrayList<>();
//车牌号
WxMpTempMessageData keyword1 = new WxMpTempMessageData();
keyword1.setValue("");
keywords.add(keyword1);
param.setKeyWordList(keywords);
param.setPagePath(MessageFormat.format(PAGE_PATH_INSU, 2));
Message msg = wxMpTemplateMessageApi.send(param);
if (!msg.isSuccess()) {
log.error("【passport系统】发送续保提醒模板消息失败:{}", msg.getResult());
return msg.getResult();
}
return "";
} catch (Exception e) {
log.error("发送续保提醒模板消息失败", e);
return "系统异常";
}
}
/**
* 发送首保消息提醒
*
* @param messageParam
* @return
*/
public String sendFMNotice(RenewInsurNoticeMessageParam messageParam) {
log.info("开始发送首保消息提醒,senderId:{}", messageParam);
try {
WxMpTempMessageParam param = new WxMpTempMessageParam();
param.setCusId(messageParam.getMemberId());
param.setTempCode(getTemplateCode());
param.setRemark(new WxMpTempMessageData("点击“详情”可在线预约保养", "a61b29"));
param.setTitle(new WxMpTempMessageData("您好!您的爱车的首次保养即将到期,请尽快进店进行保养!"));
List<WxMpTempMessageData> keywords = Arrays.asList(
new WxMpTempMessageData("首保提醒"),
//门店
new WxMpTempMessageData(messageParam.getShopName()),
//到期时间
new WxMpTempMessageData(messageParam.getExpireDate())
);
param.setKeyWordList(keywords);
param.setPagePath(RESE_URL);
Message<?> msg = wxMpTemplateMessageApi.send(param);
if (!msg.isSuccess()) {
log.error("【passport系统】发送首保提醒模板消息失败:{}", msg.getResult());
return msg.getResult();
}
return "";
} catch (Exception e) {
log.error("发送首保提醒模板消息失败", e);
return "系统异常";
}
}
/**
* 发送例保消息提醒
*
* @param messageParam
* @return
*/
public String sendRMNotice(RenewInsurNoticeMessageParam messageParam) {
log.info("开始发送例保消息提醒,senderId:{}", messageParam);
try {
WxMpTempMessageParam param = new WxMpTempMessageParam();
param.setCusId(messageParam.getMemberId());
param.setTempCode(getTemplateCode());
param.setRemark(new WxMpTempMessageData("点击“详情”可在线预约保养", "a61b29"));
param.setTitle(new WxMpTempMessageData("您好!您的爱车的下次保养即将到期,请尽快进店进行保养!"));
List<WxMpTempMessageData> keywords = Arrays.asList(
new WxMpTempMessageData("保养提醒"),
//门店
new WxMpTempMessageData(messageParam.getShopName()),
//到期时间
new WxMpTempMessageData(messageParam.getExpireDate())
);
param.setKeyWordList(keywords);
param.setPagePath(RESE_URL);
Message<?> msg = wxMpTemplateMessageApi.send(param);
if (!msg.isSuccess()) {
log.error("【passport系统】发送例保提醒模板消息失败:{}", msg.getResult());
return msg.getResult();
}
return "";
} catch (Exception e) {
log.error("发送例保提醒模板消息失败", e);
return "系统异常";
}
}
}