Commit f28a04c4 by 郑永强

【1002866】小程序订阅消息授权流程

parent aa42393d
......@@ -36,6 +36,8 @@ public class CultivateNotifySend extends BaseEntity {
@ApiModelProperty("阅读时间")
private Date readTime;
@ApiModelProperty("标题")
private String title;
@JSONField(
format = "yyyy-MM-dd HH:mm:ss"
......
......@@ -5,6 +5,7 @@ package com.pcloud.book.consumer.message;
import com.pcloud.common.core.biz.TemplateQueueBiz;
import com.pcloud.common.core.constant.WechatCode;
import com.pcloud.common.core.dto.AppletTemplateMessageDto;
import com.pcloud.common.core.dto.TemplateMessageDto;
import com.pcloud.common.exceptions.BizException;
......@@ -75,5 +76,12 @@ public class TemplateConsr {
LOGGER.error("【模板消息(消)】发送模板消息topic(运营号),<ERROR>.[sendMessageQueue]:" + e.getMessage(), e);
}
}
public void sendAppletMessageQueue(AppletTemplateMessageDto appletTemplateMessage) {
try {
templateQueueBiz.sendAppletMessageQueue(appletTemplateMessage);
} catch (Exception e) {
LOGGER.error("【小程序模板消息(消)】发送小程序模板消息topic,<ERROR>.[sendAppletMessageQueue]:" + e.getMessage(), e);
}
}
}
package com.pcloud.book.consumer.reader;
import com.pcloud.channelcenter.base.exceptions.ChannelBizException;
import com.pcloud.readercenter.wechat.dto.NickNameAndOpenIdDto;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -146,7 +148,53 @@ public class ReaderConsr {
return result;
}
/**
* 去用户中心拿openId和nickname
*/
public NickNameAndOpenIdDto getOpenIdAndNickName(Long wechatUserId, Long wechatId) throws BizException {
LOGGER.info("【客户-用户(消)】获取用户的openId和name,<PARAM>.[wechatUserId]=" + wechatUserId + ",[wechatId]=" + wechatId);
NickNameAndOpenIdDto nickNameAndOpenId = null;
if (wechatUserId == null || wechatId == null) {
LOGGER.info("【客户-用户(消)】获取用户的openId和name,<PARAM=NULL>");
return nickNameAndOpenId;
}
try {
nickNameAndOpenId = ResponseHandleUtil.parseResponse(wechatUserService.getOpenIdAndNickName(wechatUserId, wechatId), NickNameAndOpenIdDto.class);
LOGGER.info("【客户-用户(消)】获取用户的openId和name,<END>.[nickNameAndOpenId]=" + nickNameAndOpenId.toString());
} catch (BizException e) {
throw new BizException(e.getCode(), e.getMessage());
} catch (Exception e) {
LOGGER.error("【客户-用户(消)】获取用户的openId和name.<ERROR>[getOpenIdAndNickName]:" + e.getMessage(), e);
throw new ChannelBizException(ChannelBizException.INVOKE_USER_ERROR, "获取用户信息失败~!");
}
return nickNameAndOpenId == null ? new NickNameAndOpenIdDto() : nickNameAndOpenId;
}
/**
* 获取用户openId
*/
public String getOpenIdByWechatUserIdAndOfficialAccountsId(Long wechatUserId, Long accountSettingId) throws BizException {
LOGGER.info("获取用户openId,参数列表[wechatUserId:" + wechatUserId + "accountSettingId:" + accountSettingId + "]");
String openId = "";
if (wechatUserId == null || accountSettingId == null) {
LOGGER.error("获取用户openId,参数为空");
return openId;
}
try {
openId = ResponseHandleUtil.parseResponse(wechatUserService.getOpenIdByWechatUserIdAndOfficialAccountsId(wechatUserId, accountSettingId), String.class);
LOGGER.info("获取用户openId结束");
} catch (BizException e) {
throw new BizException(e.getCode(), e.getMessage());
} catch (Exception e) {
LOGGER.error("获取用户openId失败:【wechatUserService.getOpenIdByWechatUserIdAndOfficialAccountsId】" + e.getMessage(), e);
throw new ChannelBizException(ChannelBizException.INVOKE_ERROR, "获取用户信息失败~!");
}
return openId;
}
}
......
......@@ -6,6 +6,7 @@ import com.pcloud.book.cultivate.dto.CultivateNotifyPageDTO;
import com.pcloud.book.cultivate.dto.SearchNotifyDTO;
import com.pcloud.book.cultivate.dto.SearchSendUserDTO;
import com.pcloud.book.cultivate.dto.SendUserDetailDto;
import com.pcloud.book.cultivate.entity.CultivateNotifySend;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.book.cultivate.dto.CultivateNotifyTypeDTO;
......@@ -17,6 +18,7 @@ public interface CultivateNotifyBiz {
void createNotify(CultivateNotifyDTO cultivateNotifyDTO);
void sendAppletTemplateMessage(List<CultivateNotifySend> list);
PageBeanNew<CultivateNotifyPageDTO> listPage4CultivateNotify(SearchNotifyDTO searchNotifyDTO);
......
package com.pcloud.book.cultivate.biz.impl;
import com.google.common.collect.Maps;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.book.dao.BookDao;
import com.pcloud.book.book.dao.SearchRecordDao;
import com.pcloud.book.book.dto.AdviserBookInfoDTO;
import com.pcloud.book.consumer.content.ResourceConsr;
import com.pcloud.book.consumer.message.TemplateConsr;
import com.pcloud.book.consumer.reader.ReaderConsr;
import com.pcloud.book.consumer.user.AdviserConsr;
import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr;
......@@ -24,8 +26,10 @@ import com.pcloud.book.cultivate.entity.CultivateNotifyItem;
import com.pcloud.book.cultivate.entity.CultivateNotifySend;
import com.pcloud.book.cultivate.enums.NotifySendTypeEnum;
import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.common.core.dto.AppletTemplateMessageDto;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
import com.pcloud.common.utils.DateUtils;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.contentcenter.resource.dto.ResourceDTO;
import com.pcloud.readercenter.wechat.dto.MiniUserDto;
......@@ -34,6 +38,7 @@ import com.pcloud.usercenter.party.adviser.dto.AdviserBaseInfoDto;
import com.pcloud.wechatgroup.selfrobot.dto.SendMessageDTO;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
......@@ -69,6 +74,11 @@ public class CultivateNotifyBizImpl implements CultivateNotifyBiz {
private BookDao bookDao;
@Autowired
private AdviserConsr adviserConsr;
@Autowired
private TemplateConsr templateConsr;
@Value("${mini.official.account.id}")
private Long accountSettingId;
private final Integer SEND_BATCH_NUM=100;
......@@ -179,9 +189,11 @@ public class CultivateNotifyBizImpl implements CultivateNotifyBiz {
cultivateNotifySend.setSendType(cultivateNotifyDTO.getSendType());
cultivateNotifySend.setWxUserId(wechatUserDTO.getWxUserId());
cultivateNotifySend.setWechatUserId(wechatUserDTO.getWechatUserId());
cultivateNotifySend.setTitle(cultivateNotify.getTitle());
list.add(cultivateNotifySend);
}
cultivateNotifySendDao.insert(list);
sendAppletTemplateMessage(list);
}
//分类用户发送
if (NotifySendTypeEnum.CLASSIFY_USER.value.equals(cultivateNotifyDTO.getSendType())) {
......@@ -217,6 +229,7 @@ public class CultivateNotifyBizImpl implements CultivateNotifyBiz {
cultivateNotifySendList.add(cultivateNotifySend);
}
cultivateNotifySendDao.insert(cultivateNotifySendList);
sendAppletTemplateMessage(cultivateNotifySendList);
}
}
}
......@@ -230,6 +243,29 @@ public class CultivateNotifyBizImpl implements CultivateNotifyBiz {
}
}
/**
* 发送小程序模板消息
* @param list
*/
public void sendAppletTemplateMessage(List<CultivateNotifySend> list) {
AppletTemplateMessageDto appletTemplateMessage;
Map<String, String> tempMap;
for (CultivateNotifySend cultivateNotifySend : list) {
if(cultivateNotifySend.getMessageType() == 1){ continue;}
appletTemplateMessage = new AppletTemplateMessageDto();
appletTemplateMessage.setAccountSettingId(accountSettingId);
appletTemplateMessage.setWechatUserId(cultivateNotifySend.getWechatUserId());
appletTemplateMessage.setTempalteTypeCode("xiaorui_unread_message_remind");
appletTemplateMessage.setPage("pages/index/index");
tempMap = Maps.newHashMap();
tempMap.put("thing2", cultivateNotifySend.getTitle());
tempMap.put("time3", DateUtils.getLongDateStr());
tempMap.put("thing7", "小睿有1条新通知提醒一下小主");
appletTemplateMessage.setData(tempMap);
templateConsr.sendAppletMessageQueue(appletTemplateMessage);
}
}
@Override
public PageBeanNew<CultivateNotifyPageDTO> listPage4CultivateNotify(SearchNotifyDTO searchNotifyDTO) {
......
package com.pcloud.book.cultivate.service.impl;
import com.pcloud.book.cultivate.biz.CultivateNotifyBiz;
import com.pcloud.book.cultivate.dao.CultivateNotifySendDao;
import com.pcloud.book.cultivate.entity.CultivateNotifySend;
import com.pcloud.book.cultivate.service.CultivateNotifyService;
......@@ -34,6 +35,8 @@ import java.util.Map;
public class CultivateNotifyServiceImpl implements CultivateNotifyService {
@Autowired
private CultivateNotifyBiz cultivateNotifyBiz;
@Autowired
private CultivateNotifySendDao cultivateNotifySendDao;
@Override
......@@ -41,6 +44,7 @@ public class CultivateNotifyServiceImpl implements CultivateNotifyService {
public void batchSendMiniUser(@RequestBody List<CultivateNotifySend> list) throws BizException {
if(!ListUtils.isEmpty(list)){
cultivateNotifySendDao.insert(list);
cultivateNotifyBiz.sendAppletTemplateMessage(list);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment