Authored by unknown

update

1 package com.test; 1 package com.test;
2 2
  3 +import com.alibaba.fastjson.JSONArray;
3 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
4 import com.yoho.message.dal.MessageFilterInfoMapper; 5 import com.yoho.message.dal.MessageFilterInfoMapper;
5 import com.yoho.service.model.msgcenter.wechat.WechatCustomMsgBO; 6 import com.yoho.service.model.msgcenter.wechat.WechatCustomMsgBO;
@@ -28,16 +29,26 @@ public class WechatSendTest { @@ -28,16 +29,26 @@ public class WechatSendTest {
28 29
29 @Test 30 @Test
30 public void sendCustomTest(){ 31 public void sendCustomTest(){
  32 +
31 List<String> openIdList = new ArrayList<>(); 33 List<String> openIdList = new ArrayList<>();
32 openIdList.add("oemqmjl0M38zwP-7wnmhNcQqVMEA"); 34 openIdList.add("oemqmjl0M38zwP-7wnmhNcQqVMEA");
  35 +
  36 + JSONArray contentArray = new JSONArray();
  37 + JSONObject part = new JSONObject();
  38 + part.put("title","Happy Day");
  39 + part.put("description","Is Really A Happy Day");
  40 + part.put("url","https://m.yohobuy.com/");
  41 + part.put("picurl","http://img11.static.yhbimg.com/yhb-img01/2018/10/09/11/01212cad454186ddd6e9bab47d76dde7f3.png");
  42 + contentArray.add(part);
33 JSONObject content = new JSONObject(); 43 JSONObject content = new JSONObject();
34 - content.put("content","hi LingMin"); 44 + content.put("articles",contentArray);
  45 +
35 WechatCustomMsgBO customMsgBO = new WechatCustomMsgBO(); 46 WechatCustomMsgBO customMsgBO = new WechatCustomMsgBO();
36 customMsgBO.setPublicNumCode(2); 47 customMsgBO.setPublicNumCode(2);
37 customMsgBO.setOpenIdList(openIdList); 48 customMsgBO.setOpenIdList(openIdList);
38 customMsgBO.setSendKey("123"); 49 customMsgBO.setSendKey("123");
39 customMsgBO.setFilterDays(0); 50 customMsgBO.setFilterDays(0);
40 - customMsgBO.setMsgType("text"); 51 + customMsgBO.setMsgType("news");
41 customMsgBO.setSendContent(content.toJSONString()); 52 customMsgBO.setSendContent(content.toJSONString());
42 wechatService.sendWechatCustomMsg(customMsgBO); 53 wechatService.sendWechatCustomMsg(customMsgBO);
43 } 54 }
@@ -147,7 +147,7 @@ public class WechatServiceImpl implements IWechatService { @@ -147,7 +147,7 @@ public class WechatServiceImpl implements IWechatService {
147 logger.info("enter sendWechatCustomMsg with sceneKey is {},msgBO is {}",customMsgBO.getSendKey(),customMsgBO.getSendContent()); 147 logger.info("enter sendWechatCustomMsg with sceneKey is {},msgBO is {}",customMsgBO.getSendKey(),customMsgBO.getSendContent());
148 148
149 if(CollectionUtils.isEmpty(customMsgBO.getOpenIdList())){ 149 if(CollectionUtils.isEmpty(customMsgBO.getOpenIdList())){
150 - logger.warn("sendWechatCustomMsg with sendOpenIds null, sceneKey is {}",customMsgBO.getSendKey()); 150 + logger.warn("sendWechatCustomMsg with sendOpenIds null, sceneKey is {}", customMsgBO.getSendKey());
151 return; 151 return;
152 } 152 }
153 String sceneKey = customMsgBO.getSendKey(); 153 String sceneKey = customMsgBO.getSendKey();
@@ -155,10 +155,14 @@ public class WechatServiceImpl implements IWechatService { @@ -155,10 +155,14 @@ public class WechatServiceImpl implements IWechatService {
155 logger.info("sendWechatCustomMsg with sceneKey is {},send origin size is {}",sceneKey,openIdSet.size()); 155 logger.info("sendWechatCustomMsg with sceneKey is {},send origin size is {}",sceneKey,openIdSet.size());
156 //根据过滤条件进行过滤 156 //根据过滤条件进行过滤
157 if(customMsgBO.getFilterDays() != 0){ 157 if(customMsgBO.getFilterDays() != 0){
158 - getDaysFilter(customMsgBO,openIdSet); 158 + getDaysFilter(customMsgBO, openIdSet);
159 } 159 }
160 //组装发送 160 //组装发送
161 - List<String> sendSuccessList = customMsgSend(customMsgBO,openIdSet); 161 + List<String> sendSuccessList = customMsgSend(customMsgBO, openIdSet);
  162 + if(CollectionUtils.isEmpty(sendSuccessList)){
  163 + logger.warn("sendWechatCustomMsg with sendSuccess size is 0,sceneKey is {}",customMsgBO.getSendKey());
  164 + return;
  165 + }
162 logger.info("end sendWechatCustomMsg with sceneKey is {},successSize is {}",customMsgBO.getSendKey(),sendSuccessList.size()); 166 logger.info("end sendWechatCustomMsg with sceneKey is {},successSize is {}",customMsgBO.getSendKey(),sendSuccessList.size());
163 //成功记录存redis 167 //成功记录存redis
164 String nowDate = DateUtil.getToday(DATE_ID_FORMAT); 168 String nowDate = DateUtil.getToday(DATE_ID_FORMAT);
@@ -183,7 +187,7 @@ public class WechatServiceImpl implements IWechatService { @@ -183,7 +187,7 @@ public class WechatServiceImpl implements IWechatService {
183 Calendar calendar = Calendar.getInstance(); 187 Calendar calendar = Calendar.getInstance();
184 calendar.add(Calendar.DATE, -filterDayReal); 188 calendar.add(Calendar.DATE, -filterDayReal);
185 String startDate = DateUtil.dateToString(calendar.getTime(), DATE_ID_FORMAT); 189 String startDate = DateUtil.dateToString(calendar.getTime(), DATE_ID_FORMAT);
186 - Date date = DateUtil.stringToDate(startDate,"DATE_ID_FORMAT"); 190 + Date date = DateUtil.stringToDate(startDate,DATE_ID_FORMAT);
187 Calendar c = Calendar.getInstance(); 191 Calendar c = Calendar.getInstance();
188 c.setTime(date); 192 c.setTime(date);
189 int day = c.get(Calendar.DATE); 193 int day = c.get(Calendar.DATE);
@@ -195,12 +199,19 @@ public class WechatServiceImpl implements IWechatService { @@ -195,12 +199,19 @@ public class WechatServiceImpl implements IWechatService {
195 String redisKeyStr = RedisCacheKeyConstant.WECAHT_CUSTOM_SEND_KEY + customMsgBO.getPublicNumCode() + '_' + nowDate; 199 String redisKeyStr = RedisCacheKeyConstant.WECAHT_CUSTOM_SEND_KEY + customMsgBO.getPublicNumCode() + '_' + nowDate;
196 pushRedisService.getSetFilter(openIdSet,redisKeyStr); 200 pushRedisService.getSetFilter(openIdSet,redisKeyStr);
197 logger.info("sendWechatCustomMsg with day filter,sceneKey is {},redisKeyStr is {},nowSize is {}",customMsgBO.getSendKey(),redisKeyStr,openIdSet.size()); 201 logger.info("sendWechatCustomMsg with day filter,sceneKey is {},redisKeyStr is {},nowSize is {}",customMsgBO.getSendKey(),redisKeyStr,openIdSet.size());
  202 + if(openIdSet.size() == 0){
  203 + break;
  204 + }
198 } 205 }
199 } 206 }
200 207
201 208
202 private List<String> customMsgSend(WechatCustomMsgBO customMsgBO,Set<String> openIdSet){ 209 private List<String> customMsgSend(WechatCustomMsgBO customMsgBO,Set<String> openIdSet){
203 logger.info("begin customMsgSend with sceneKey is {},send openId size is {}",customMsgBO.getSendKey(),openIdSet.size()); 210 logger.info("begin customMsgSend with sceneKey is {},send openId size is {}",customMsgBO.getSendKey(),openIdSet.size());
  211 + if(CollectionUtils.isEmpty(openIdSet)){
  212 + logger.warn("customMsgSend with openIdSet is null,sceneKey is {}",customMsgBO.getSendKey());
  213 + return new ArrayList<>();
  214 + }
204 // 获取token 和接口url 215 // 获取token 和接口url
205 AccessToken accessToken = weixinAccessTokenService.queryWeixinAccessToken(customMsgBO.getPublicNumCode()); 216 AccessToken accessToken = weixinAccessTokenService.queryWeixinAccessToken(customMsgBO.getPublicNumCode());
206 //若仍未获取到 token 则返回 217 //若仍未获取到 token 则返回