|
@@ -6,7 +6,9 @@ import com.yoho.core.common.utils.DateUtil; |
|
@@ -6,7 +6,9 @@ import com.yoho.core.common.utils.DateUtil; |
6
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
6
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
7
|
import com.yoho.error.ServiceError;
|
7
|
import com.yoho.error.ServiceError;
|
8
|
import com.yoho.error.exception.ServiceException;
|
8
|
import com.yoho.error.exception.ServiceException;
|
|
|
9
|
+import com.yoho.message.dal.IMiniSubscribeDAO;
|
9
|
import com.yoho.message.dal.IMiniappMsgFormDAO;
|
10
|
import com.yoho.message.dal.IMiniappMsgFormDAO;
|
|
|
11
|
+import com.yoho.message.dal.model.MiniSubscribe;
|
10
|
import com.yoho.message.dal.model.MiniappMsgForm;
|
12
|
import com.yoho.message.dal.model.MiniappMsgForm;
|
11
|
import com.yoho.service.model.msgcenter.wechat.MiniappMsgReqBO;
|
13
|
import com.yoho.service.model.msgcenter.wechat.MiniappMsgReqBO;
|
12
|
import com.yoho.yhmessage.constants.RedisCacheKeyConstant;
|
14
|
import com.yoho.yhmessage.constants.RedisCacheKeyConstant;
|
|
@@ -42,6 +44,8 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
@@ -42,6 +44,8 @@ public class MiniServiceAppImpl implements IMiniAppService { |
42
|
@Value("${miniapp.send.tempalte:/cgi-bin/message/wxopen/template/send?}")
|
44
|
@Value("${miniapp.send.tempalte:/cgi-bin/message/wxopen/template/send?}")
|
43
|
private String sendMsgTemplate;
|
45
|
private String sendMsgTemplate;
|
44
|
|
46
|
|
|
|
47
|
+ private static final String sendSubscribeMsg = "/cgi-bin/message/subscribe/send?";
|
|
|
48
|
+
|
45
|
@Autowired
|
49
|
@Autowired
|
46
|
private IMiniappMsgFormDAO miniappMsgFormDAO;
|
50
|
private IMiniappMsgFormDAO miniappMsgFormDAO;
|
47
|
|
51
|
|
|
@@ -49,7 +53,7 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
@@ -49,7 +53,7 @@ public class MiniServiceAppImpl implements IMiniAppService { |
49
|
private IMiniAppAccessTokenService miniAppAccessTokenService;
|
53
|
private IMiniAppAccessTokenService miniAppAccessTokenService;
|
50
|
|
54
|
|
51
|
public String getMsgSendUrl(){
|
55
|
public String getMsgSendUrl(){
|
52
|
- return wechatHost + sendMsgTemplate;
|
56
|
+ return wechatHost + sendSubscribeMsg;
|
53
|
}
|
57
|
}
|
54
|
|
58
|
|
55
|
@Autowired
|
59
|
@Autowired
|
|
@@ -64,6 +68,9 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
@@ -64,6 +68,9 @@ public class MiniServiceAppImpl implements IMiniAppService { |
64
|
@Autowired
|
68
|
@Autowired
|
65
|
private IFilterSensitiveWordService filterSensitiveWordService;
|
69
|
private IFilterSensitiveWordService filterSensitiveWordService;
|
66
|
|
70
|
|
|
|
71
|
+ @Autowired
|
|
|
72
|
+ private IMiniSubscribeDAO miniSubscribeDAO;
|
|
|
73
|
+
|
67
|
/**
|
74
|
/**
|
68
|
* 发送小程序模板消息
|
75
|
* 发送小程序模板消息
|
69
|
* @param reqBO
|
76
|
* @param reqBO
|
|
@@ -78,10 +85,7 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
@@ -78,10 +85,7 @@ public class MiniServiceAppImpl implements IMiniAppService { |
78
|
}
|
85
|
}
|
79
|
|
86
|
|
80
|
//过滤敏感词目前只过滤了‘测试’相关字眼,以后若要加敏感词,则改为该方法过滤 将敏感词维护在 q_msg_system.message_sensitive_words 表中
|
87
|
//过滤敏感词目前只过滤了‘测试’相关字眼,以后若要加敏感词,则改为该方法过滤 将敏感词维护在 q_msg_system.message_sensitive_words 表中
|
81
|
- /*if(filterSensitiveWordService.isContainSensitiveWord(reqBO.getData().toJSONString())){
|
|
|
82
|
- logger.warn("sendMiniappMsg with sensitiveWord exist,reqBO is {}",reqBO);
|
|
|
83
|
- return new JSONObject();
|
|
|
84
|
- }*/
|
88
|
+
|
85
|
if(filterSensitiveWordService.checkTestWord(reqBO.getData().toJSONString())){
|
89
|
if(filterSensitiveWordService.checkTestWord(reqBO.getData().toJSONString())){
|
86
|
logger.warn("sendMiniappMsg with sensitiveWord exist,uid is {},reqBO is {}",reqBO.getUid(),reqBO);
|
90
|
logger.warn("sendMiniappMsg with sensitiveWord exist,uid is {},reqBO is {}",reqBO.getUid(),reqBO);
|
87
|
return new JSONObject();
|
91
|
return new JSONObject();
|
|
@@ -92,33 +96,40 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
@@ -92,33 +96,40 @@ public class MiniServiceAppImpl implements IMiniAppService { |
92
|
throw new ServiceException(ServiceError.WECHAT_PARAM_ISNULL);
|
96
|
throw new ServiceException(ServiceError.WECHAT_PARAM_ISNULL);
|
93
|
}
|
97
|
}
|
94
|
|
98
|
|
95
|
- // 获取有效的formid
|
99
|
+ //判断该模板用户是否已经订阅
|
|
|
100
|
+ MiniSubscribe miniSubscribe = miniSubscribeDAO.selectAvailableTemplateId("mini_subscribe_"+reqBO.getMiniappType(), Integer.valueOf(reqBO.getUid()), reqBO.getTemplateId());
|
|
|
101
|
+ if(miniSubscribe == null){
|
|
|
102
|
+ return new JSONObject();
|
|
|
103
|
+ }
|
|
|
104
|
+ /*// 获取有效的formid
|
96
|
MiniappMsgForm miniappMsgForm = miniappMsgFormDAO.selectLastedAvailabByUid(reqBO.getUid(), reqBO.getMiniappType());
|
105
|
MiniappMsgForm miniappMsgForm = miniappMsgFormDAO.selectLastedAvailabByUid(reqBO.getUid(), reqBO.getMiniappType());
|
97
|
if (miniappMsgForm == null) {
|
106
|
if (miniappMsgForm == null) {
|
98
|
logger.warn("validate form not exist, uid is {},reqBO is {}",reqBO.getUid(),reqBO);
|
107
|
logger.warn("validate form not exist, uid is {},reqBO is {}",reqBO.getUid(),reqBO);
|
99
|
return new JSONObject();
|
108
|
return new JSONObject();
|
100
|
- }
|
109
|
+ }*/
|
101
|
|
110
|
|
102
|
- // 新获取的formid
|
111
|
+ /* // 新获取的formid
|
103
|
if (!reqBO.getFormId().equals(miniappMsgForm.getFormId())){
|
112
|
if (!reqBO.getFormId().equals(miniappMsgForm.getFormId())){
|
104
|
logger.info("reset form id, uid is {},old formid is {}, new formid is {}", reqBO.getUid(),reqBO.getFormId(), miniappMsgForm.getFormId());
|
113
|
logger.info("reset form id, uid is {},old formid is {}, new formid is {}", reqBO.getUid(),reqBO.getFormId(), miniappMsgForm.getFormId());
|
105
|
reqBO.setFormId(miniappMsgForm.getFormId());
|
114
|
reqBO.setFormId(miniappMsgForm.getFormId());
|
106
|
- }
|
115
|
+ }*/
|
107
|
|
116
|
|
108
|
// 发送消息
|
117
|
// 发送消息
|
109
|
- JSONObject result = sendMsgUpdateDB(reqBO, miniappMsgForm);
|
118
|
+ JSONObject result = sendMsgUpdateDB(reqBO, miniSubscribe);
|
110
|
|
119
|
|
111
|
// token过期重新获取
|
120
|
// token过期重新获取
|
112
|
- if (result == null || result.getInteger("errcode") == 40001){
|
|
|
113
|
- logger.warn("retry send msg because error is {}, uid is {},reqBO is {}", result != null ? result.toJSONString() : null, reqBO.getUid(), reqBO);
|
121
|
+ if (result == null || (Integer)result.get("errcode") == 40001){
|
|
|
122
|
+ logger.warn("retry send msg because error is {}, uid is {},reqBO is {}", result != null ? result.toString() : null, reqBO.getUid(), reqBO);
|
114
|
miniAppAccessTokenService.deletAccessToken(reqBO.getMiniappType());
|
123
|
miniAppAccessTokenService.deletAccessToken(reqBO.getMiniappType());
|
115
|
- return sendMsgUpdateDB(reqBO, miniappMsgForm);
|
124
|
+ return sendMsgUpdateDB(reqBO, miniSubscribe);
|
116
|
}
|
125
|
}
|
117
|
- // 过期的formId 和 不合法的formid
|
|
|
118
|
- else if(result.getInteger("errcode") == 41028 || result.getInteger("errcode")== 41029){
|
|
|
119
|
- logger.info("retry send msg because error is {}, uid is {},reqBO is {}", result.toJSONString(),reqBO.getUid(),reqBO);
|
|
|
120
|
- miniappMsgForm.setAvailableTimes(0);
|
|
|
121
|
- miniappMsgFormDAO.updateByPrimaryKey(miniappMsgForm);
|
126
|
+
|
|
|
127
|
+ // TODO用户拒绝订阅需清空订阅次数
|
|
|
128
|
+ /*// 过期的formId 和 不合法的formid
|
|
|
129
|
+ else if((Integer)result.get("errcode") == 41028 || (Integer)result.get("errcode")== 41029){
|
|
|
130
|
+ logger.info("retry send msg because error is {}, uid is {},reqBO is {}", result.toString(),reqBO.getUid(),reqBO);
|
|
|
131
|
+ miniSubscribe.setAvailableTimes(0);
|
|
|
132
|
+ miniappMsgFormDAO.updateByPrimaryKey(miniSubscribe);
|
122
|
|
133
|
|
123
|
MiniappMsgForm miniappMsgFormNew = miniappMsgFormDAO.selectLastedAvailabByUid(reqBO.getUid(), reqBO.getMiniappType());
|
134
|
MiniappMsgForm miniappMsgFormNew = miniappMsgFormDAO.selectLastedAvailabByUid(reqBO.getUid(), reqBO.getMiniappType());
|
124
|
|
135
|
|
|
@@ -130,19 +141,20 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
@@ -130,19 +141,20 @@ public class MiniServiceAppImpl implements IMiniAppService { |
130
|
}
|
141
|
}
|
131
|
|
142
|
|
132
|
return sendMsgUpdateDB(reqBO, miniappMsgFormNew);
|
143
|
return sendMsgUpdateDB(reqBO, miniappMsgFormNew);
|
133
|
- }
|
144
|
+ }*/
|
134
|
|
145
|
|
135
|
return result;
|
146
|
return result;
|
136
|
|
147
|
|
137
|
}
|
148
|
}
|
138
|
|
149
|
|
139
|
|
150
|
|
140
|
- private JSONObject sendMsgUpdateDB(MiniappMsgReqBO reqBO, MiniappMsgForm miniappMsgForm) {
|
151
|
+ private JSONObject sendMsgUpdateDB(MiniappMsgReqBO reqBO, MiniSubscribe miniSubscribe) {
|
|
|
152
|
+ reqBO.setTouser(miniSubscribe.getOpenId());
|
141
|
JSONObject result = sendTemplateMsg(reqBO);
|
153
|
JSONObject result = sendTemplateMsg(reqBO);
|
142
|
-
|
|
|
143
|
- if (result != null && result.getInteger("errcode") == 0){
|
|
|
144
|
- miniappMsgForm.setAvailableTimes(miniappMsgForm.getAvailableTimes()-1);
|
|
|
145
|
- miniappMsgFormDAO.updateByPrimaryKey(miniappMsgForm);
|
154
|
+ if (result != null && (Integer)result.get("errcode") == 0){
|
|
|
155
|
+ miniSubscribe.setAvailableTimes(miniSubscribe.getAvailableTimes()-1);
|
|
|
156
|
+ miniSubscribeDAO.updateMiniSubscribe("mini_subscribe_" + reqBO.getMiniappType(), miniSubscribe);
|
|
|
157
|
+ //miniappMsgFormDAO.updateByPrimaryKey(miniappMsgForm);
|
146
|
//发送成功,记入发送数至 redis
|
158
|
//发送成功,记入发送数至 redis
|
147
|
saveSendRedis(reqBO.getPage());
|
159
|
saveSendRedis(reqBO.getPage());
|
148
|
}
|
160
|
}
|
|
@@ -163,6 +175,7 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
@@ -163,6 +175,7 @@ public class MiniServiceAppImpl implements IMiniAppService { |
163
|
String msgId = page.substring(index + MSG_ID_INDEX);
|
175
|
String msgId = page.substring(index + MSG_ID_INDEX);
|
164
|
//组装key:日期,value部分为 以场景id为key的hash结构 设置超时时间2天
|
176
|
//组装key:日期,value部分为 以场景id为key的hash结构 设置超时时间2天
|
165
|
RedisKeyBuilder redisKey = RedisKeyBuilder.newInstance().appendFixed(RedisCacheKeyConstant.MINI_SEND_NUM_KEY).appendVar(DateUtil.getToday("yyyyMMdd"));
|
177
|
RedisKeyBuilder redisKey = RedisKeyBuilder.newInstance().appendFixed(RedisCacheKeyConstant.MINI_SEND_NUM_KEY).appendVar(DateUtil.getToday("yyyyMMdd"));
|
|
|
178
|
+ //todo 若是
|
166
|
long result = pushRedisService.hashIncrement(redisKey,msgId,1,TWO_DAYS_HOURS);
|
179
|
long result = pushRedisService.hashIncrement(redisKey,msgId,1,TWO_DAYS_HOURS);
|
167
|
logger.info("saveSendRedis end with msgId is {},result is {}",msgId,result);
|
180
|
logger.info("saveSendRedis end with msgId is {},result is {}",msgId,result);
|
168
|
}catch (Exception e){
|
181
|
}catch (Exception e){
|
|
@@ -196,7 +209,6 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
@@ -196,7 +209,6 @@ public class MiniServiceAppImpl implements IMiniAppService { |
196
|
bodyParam.put("touser", reqBO.getTouser());
|
209
|
bodyParam.put("touser", reqBO.getTouser());
|
197
|
bodyParam.put("template_id", reqBO.getTemplateId());
|
210
|
bodyParam.put("template_id", reqBO.getTemplateId());
|
198
|
bodyParam.put("page", reqBO.getPage());
|
211
|
bodyParam.put("page", reqBO.getPage());
|
199
|
- bodyParam.put("form_id", reqBO.getFormId());
|
|
|
200
|
bodyParam.put("data", reqBO.getData());
|
212
|
bodyParam.put("data", reqBO.getData());
|
201
|
|
213
|
|
202
|
if (StringUtils.isNotBlank(reqBO.getEmphasisKeyword())){
|
214
|
if (StringUtils.isNotBlank(reqBO.getEmphasisKeyword())){
|