|
@@ -6,14 +6,8 @@ import com.alibaba.fastjson.JSONObject;
|
6
|
6
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
7
|
7
|
import com.huiju.estateagents.base.ResponseBean;
|
8
|
8
|
import com.huiju.estateagents.common.*;
|
9
|
|
-import com.huiju.estateagents.entity.TaMiniapp;
|
10
|
|
-import com.huiju.estateagents.entity.TaMiniappQrcode;
|
11
|
|
-import com.huiju.estateagents.entity.TaMiniappTemplate;
|
12
|
|
-import com.huiju.estateagents.entity.TaPerson;
|
13
|
|
-import com.huiju.estateagents.mapper.TaMiniFormidsMapper;
|
14
|
|
-import com.huiju.estateagents.mapper.TaMiniappMapper;
|
15
|
|
-import com.huiju.estateagents.mapper.TaMiniappQrcodeMapper;
|
16
|
|
-import com.huiju.estateagents.mapper.TaMiniappTemplateMapper;
|
|
9
|
+import com.huiju.estateagents.entity.*;
|
|
10
|
+import com.huiju.estateagents.mapper.*;
|
17
|
11
|
import com.huiju.estateagents.service.IMiniAppService;
|
18
|
12
|
import com.huiju.estateagents.service.ITaMiniFormidsService;
|
19
|
13
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -45,9 +39,15 @@ public class MiniAppServiceImpl implements IMiniAppService {
|
45
|
39
|
@Autowired
|
46
|
40
|
TaMiniappTemplateMapper taMiniappTemplateMapper;
|
47
|
41
|
|
|
42
|
+ @Autowired
|
|
43
|
+ SysSmsSettingMapper sysSmsSettingMapper;
|
|
44
|
+
|
48
|
45
|
@Autowired
|
49
|
46
|
WxUtils wxUtils;
|
50
|
47
|
|
|
48
|
+ @Autowired
|
|
49
|
+ SMSUtils smsUtils;
|
|
50
|
+
|
51
|
51
|
@Override
|
52
|
52
|
public WxMaJscode2SessionResult getSessionInfo(String code, String appid) throws WxErrorException {
|
53
|
53
|
WxMaService wxService = wxUtils.getMiniApp(appid);
|
|
@@ -76,20 +76,27 @@ public class MiniAppServiceImpl implements IMiniAppService {
|
76
|
76
|
|
77
|
77
|
@Override
|
78
|
78
|
public void sendNoticeMessage(TaPerson toUser, String link, String name, String phone, String content, LocalDateTime dt) {
|
|
79
|
+ TaMiniapp miniapp = taMiniappMapper.selectById(toUser.getMiniappId());
|
|
80
|
+ if (null == miniapp) {
|
|
81
|
+ log.error("小程序 {} 不存在", toUser.getMiniappId());
|
|
82
|
+ return ;
|
|
83
|
+ }
|
|
84
|
+ String[] smsParams = { name, miniapp.getName() + "小程序" };
|
|
85
|
+
|
79
|
86
|
TaMiniappTemplate tpl = getTplByType(CommConstant.MINIAPP_TPL_NOTICE, toUser.getMiniappId());
|
80
|
87
|
if (null == tpl) {
|
81
|
88
|
log.error("小程序 {} 无通知消息模板 {}", toUser.getMiniappId(), CommConstant.MINIAPP_TPL_NOTICE);
|
82
|
89
|
|
83
|
|
- // TODO
|
84
|
90
|
// 短信发送
|
|
91
|
+ sendSmsMessage(StringUtils.ifNull(toUser.getTel(), toUser.getPhone()), CommConstant.MINIAPP_TPL_NOTICE, smsParams);
|
85
|
92
|
};
|
86
|
93
|
|
87
|
94
|
if (((Boolean) true).equals(tpl.getIsSubscribe())) {
|
88
|
95
|
String[] data = new String[] { name, content, DateUtils.cutSecond(dt) };
|
89
|
96
|
ResponseBean res = sendSubscribeMessage(tpl, toUser, link, data);
|
90
|
97
|
if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
91
|
|
- // TODO
|
92
|
98
|
// 使用短信发送
|
|
99
|
+ sendSmsMessage(StringUtils.ifNull(toUser.getTel(), toUser.getPhone()), CommConstant.MINIAPP_TPL_NOTICE, smsParams);
|
93
|
100
|
}
|
94
|
101
|
} else {
|
95
|
102
|
List<WxMaTemplateData> data = new ArrayList<>();
|
|
@@ -105,20 +112,27 @@ public class MiniAppServiceImpl implements IMiniAppService {
|
105
|
112
|
|
106
|
113
|
@Override
|
107
|
114
|
public void sendHelpMessage(TaPerson toUser, String link, String result, String activityName, LocalDateTime dt) {
|
|
115
|
+ TaMiniapp miniapp = taMiniappMapper.selectById(toUser.getMiniappId());
|
|
116
|
+ if (null == miniapp) {
|
|
117
|
+ log.error("小程序 {} 不存在", toUser.getMiniappId());
|
|
118
|
+ return ;
|
|
119
|
+ }
|
|
120
|
+ String[] smsParams = { miniapp.getName() + "小程序-" + activityName };
|
|
121
|
+
|
108
|
122
|
TaMiniappTemplate tpl = getTplByType(CommConstant.MINIAPP_TPL_HELP, toUser.getMiniappId());
|
109
|
123
|
if (null == tpl) {
|
110
|
124
|
log.error("小程序 {} 无通知消息模板 {}", toUser.getMiniappId(), CommConstant.MINIAPP_TPL_HELP);
|
111
|
125
|
|
112
|
|
- // TODO
|
113
|
126
|
// 短信发送
|
|
127
|
+ sendSmsMessage(StringUtils.ifNull(toUser.getTel(), toUser.getPhone()), CommConstant.MINIAPP_TPL_HELP, smsParams);
|
114
|
128
|
};
|
115
|
129
|
|
116
|
130
|
if (((Boolean) true).equals(tpl.getIsSubscribe())) {
|
117
|
131
|
String[] data = new String[] { activityName, result };
|
118
|
132
|
ResponseBean res = sendSubscribeMessage(tpl, toUser, link, data);
|
119
|
133
|
if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
120
|
|
- // TODO
|
121
|
134
|
// 使用短信发送
|
|
135
|
+ sendSmsMessage(StringUtils.ifNull(toUser.getTel(), toUser.getPhone()), CommConstant.MINIAPP_TPL_HELP, smsParams);
|
122
|
136
|
}
|
123
|
137
|
} else {
|
124
|
138
|
List<WxMaTemplateData> data = new ArrayList<>();
|
|
@@ -132,20 +146,27 @@ public class MiniAppServiceImpl implements IMiniAppService {
|
132
|
146
|
|
133
|
147
|
@Override
|
134
|
148
|
public void sendGroupMessage(TaPerson toUser, String link, String result, String activityName, LocalDateTime dt) {
|
|
149
|
+ TaMiniapp miniapp = taMiniappMapper.selectById(toUser.getMiniappId());
|
|
150
|
+ if (null == miniapp) {
|
|
151
|
+ log.error("小程序 {} 不存在", toUser.getMiniappId());
|
|
152
|
+ return ;
|
|
153
|
+ }
|
|
154
|
+ String[] smsParams = { miniapp.getName() + "小程序-" + activityName };
|
|
155
|
+
|
135
|
156
|
TaMiniappTemplate tpl = getTplByType(CommConstant.MINIAPP_TPL_GROUP, toUser.getMiniappId());
|
136
|
157
|
if (null == tpl) {
|
137
|
158
|
log.error("小程序 {} 无通知消息模板 {}", toUser.getMiniappId(), CommConstant.MINIAPP_TPL_GROUP);
|
138
|
159
|
|
139
|
|
- // TODO
|
140
|
160
|
// 短信发送
|
|
161
|
+ sendSmsMessage(StringUtils.ifNull(toUser.getTel(), toUser.getPhone()), CommConstant.MINIAPP_TPL_GROUP, smsParams);
|
141
|
162
|
};
|
142
|
163
|
|
143
|
164
|
if (((Boolean) true).equals(tpl.getIsSubscribe())) {
|
144
|
165
|
String[] data = new String[] { activityName, result };
|
145
|
166
|
ResponseBean res = sendSubscribeMessage(tpl, toUser, link, data);
|
146
|
167
|
if (res.getCode() != ResponseBean.CODE_SUCCESS) {
|
147
|
|
- // TODO
|
148
|
168
|
// 使用短信发送
|
|
169
|
+ sendSmsMessage(StringUtils.ifNull(toUser.getTel(), toUser.getPhone()), CommConstant.MINIAPP_TPL_GROUP, smsParams);
|
149
|
170
|
}
|
150
|
171
|
} else {
|
151
|
172
|
List<WxMaTemplateData> data = new ArrayList<>();
|
|
@@ -374,6 +395,25 @@ public class MiniAppServiceImpl implements IMiniAppService {
|
374
|
395
|
}
|
375
|
396
|
}
|
376
|
397
|
|
|
398
|
+ private String sendSmsMessage(String tel, String type, String[] params) {
|
|
399
|
+ if (StringUtils.isEmpty(tel) || StringUtils.isEmpty(type)) {
|
|
400
|
+ return "短信发送失败: 没有手机号或者短信模板";
|
|
401
|
+ }
|
|
402
|
+
|
|
403
|
+ QueryWrapper<SysSmsSetting> query = new QueryWrapper<>();
|
|
404
|
+ query.eq("sms_type", type);
|
|
405
|
+ query.eq("status", CommConstant.STATUS_NORMAL);
|
|
406
|
+ query.last("limit 1");
|
|
407
|
+
|
|
408
|
+ SysSmsSetting smsSetting = sysSmsSettingMapper.selectOne(query);
|
|
409
|
+ if (null == smsSetting) {
|
|
410
|
+ return "没有设置有效的【" + type + "】短信模板";
|
|
411
|
+ }
|
|
412
|
+
|
|
413
|
+ boolean success = smsUtils.sendMessage(smsSetting.getTplCode(), tel, params);
|
|
414
|
+ return success ? null : "短信发送失败";
|
|
415
|
+ }
|
|
416
|
+
|
377
|
417
|
private List<WxMaSubscribeData> createMessageData(String[] list, String fieldsStr) {
|
378
|
418
|
List<WxMaSubscribeData> data = new ArrayList<>();
|
379
|
419
|
if (list == null || list.length == 0 || StringUtils.isEmpty(fieldsStr)) return data;
|