Authored by unknown

update

package com.test;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.message.dal.MessageFilterInfoMapper;
import com.yoho.service.model.msgcenter.wechat.WechatCustomMsgBO;
... ... @@ -28,16 +29,26 @@ public class WechatSendTest {
@Test
public void sendCustomTest(){
List<String> openIdList = new ArrayList<>();
openIdList.add("oemqmjl0M38zwP-7wnmhNcQqVMEA");
JSONArray contentArray = new JSONArray();
JSONObject part = new JSONObject();
part.put("title","Happy Day");
part.put("description","Is Really A Happy Day");
part.put("url","https://m.yohobuy.com/");
part.put("picurl","http://img11.static.yhbimg.com/yhb-img01/2018/10/09/11/01212cad454186ddd6e9bab47d76dde7f3.png");
contentArray.add(part);
JSONObject content = new JSONObject();
content.put("content","hi LingMin");
content.put("articles",contentArray);
WechatCustomMsgBO customMsgBO = new WechatCustomMsgBO();
customMsgBO.setPublicNumCode(2);
customMsgBO.setOpenIdList(openIdList);
customMsgBO.setSendKey("123");
customMsgBO.setFilterDays(0);
customMsgBO.setMsgType("text");
customMsgBO.setMsgType("news");
customMsgBO.setSendContent(content.toJSONString());
wechatService.sendWechatCustomMsg(customMsgBO);
}
... ...
... ... @@ -147,7 +147,7 @@ public class WechatServiceImpl implements IWechatService {
logger.info("enter sendWechatCustomMsg with sceneKey is {},msgBO is {}",customMsgBO.getSendKey(),customMsgBO.getSendContent());
if(CollectionUtils.isEmpty(customMsgBO.getOpenIdList())){
logger.warn("sendWechatCustomMsg with sendOpenIds null, sceneKey is {}",customMsgBO.getSendKey());
logger.warn("sendWechatCustomMsg with sendOpenIds null, sceneKey is {}", customMsgBO.getSendKey());
return;
}
String sceneKey = customMsgBO.getSendKey();
... ... @@ -155,10 +155,14 @@ public class WechatServiceImpl implements IWechatService {
logger.info("sendWechatCustomMsg with sceneKey is {},send origin size is {}",sceneKey,openIdSet.size());
//根据过滤条件进行过滤
if(customMsgBO.getFilterDays() != 0){
getDaysFilter(customMsgBO,openIdSet);
getDaysFilter(customMsgBO, openIdSet);
}
//组装发送
List<String> sendSuccessList = customMsgSend(customMsgBO,openIdSet);
List<String> sendSuccessList = customMsgSend(customMsgBO, openIdSet);
if(CollectionUtils.isEmpty(sendSuccessList)){
logger.warn("sendWechatCustomMsg with sendSuccess size is 0,sceneKey is {}",customMsgBO.getSendKey());
return;
}
logger.info("end sendWechatCustomMsg with sceneKey is {},successSize is {}",customMsgBO.getSendKey(),sendSuccessList.size());
//成功记录存redis
String nowDate = DateUtil.getToday(DATE_ID_FORMAT);
... ... @@ -183,7 +187,7 @@ public class WechatServiceImpl implements IWechatService {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -filterDayReal);
String startDate = DateUtil.dateToString(calendar.getTime(), DATE_ID_FORMAT);
Date date = DateUtil.stringToDate(startDate,"DATE_ID_FORMAT");
Date date = DateUtil.stringToDate(startDate,DATE_ID_FORMAT);
Calendar c = Calendar.getInstance();
c.setTime(date);
int day = c.get(Calendar.DATE);
... ... @@ -195,12 +199,19 @@ public class WechatServiceImpl implements IWechatService {
String redisKeyStr = RedisCacheKeyConstant.WECAHT_CUSTOM_SEND_KEY + customMsgBO.getPublicNumCode() + '_' + nowDate;
pushRedisService.getSetFilter(openIdSet,redisKeyStr);
logger.info("sendWechatCustomMsg with day filter,sceneKey is {},redisKeyStr is {},nowSize is {}",customMsgBO.getSendKey(),redisKeyStr,openIdSet.size());
if(openIdSet.size() == 0){
break;
}
}
}
private List<String> customMsgSend(WechatCustomMsgBO customMsgBO,Set<String> openIdSet){
logger.info("begin customMsgSend with sceneKey is {},send openId size is {}",customMsgBO.getSendKey(),openIdSet.size());
if(CollectionUtils.isEmpty(openIdSet)){
logger.warn("customMsgSend with openIdSet is null,sceneKey is {}",customMsgBO.getSendKey());
return new ArrayList<>();
}
// 获取token 和接口url
AccessToken accessToken = weixinAccessTokenService.queryWeixinAccessToken(customMsgBO.getPublicNumCode());
//若仍未获取到 token 则返回
... ...