|
|
|
@ -8,6 +8,7 @@ import com.java3y.austin.common.constant.SendAccountConstant;
|
|
|
|
|
import com.java3y.austin.common.domain.TaskInfo;
|
|
|
|
|
import com.java3y.austin.common.dto.model.EnterpriseWeChatContentModel;
|
|
|
|
|
import com.java3y.austin.common.enums.ChannelType;
|
|
|
|
|
import com.java3y.austin.common.enums.SendMessageType;
|
|
|
|
|
import com.java3y.austin.handler.handler.BaseHandler;
|
|
|
|
|
import com.java3y.austin.handler.handler.Handler;
|
|
|
|
|
import com.java3y.austin.support.domain.MessageTemplate;
|
|
|
|
@ -17,6 +18,8 @@ import me.chanjar.weixin.common.error.WxMpErrorMsgEnum;
|
|
|
|
|
import me.chanjar.weixin.cp.api.WxCpService;
|
|
|
|
|
import me.chanjar.weixin.cp.api.impl.WxCpMessageServiceImpl;
|
|
|
|
|
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
|
|
|
|
import me.chanjar.weixin.cp.bean.article.MpnewsArticle;
|
|
|
|
|
import me.chanjar.weixin.cp.bean.article.NewArticle;
|
|
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
|
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
|
|
|
|
|
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
|
|
|
@ -24,6 +27,9 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author 3y
|
|
|
|
|
* 企业微信推送处理
|
|
|
|
@ -63,7 +69,6 @@ public class EnterpriseWeChatHandler extends BaseHandler implements Handler {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化 WxCpServiceImpl 服务接口
|
|
|
|
|
*
|
|
|
|
@ -90,14 +95,42 @@ public class EnterpriseWeChatHandler extends BaseHandler implements Handler {
|
|
|
|
|
} else {
|
|
|
|
|
userId = StringUtils.join(taskInfo.getReceiver(), DELIMITER);
|
|
|
|
|
}
|
|
|
|
|
EnterpriseWeChatContentModel enterpriseWeChatContentModel = (EnterpriseWeChatContentModel) taskInfo.getContentModel();
|
|
|
|
|
return WxCpMessage
|
|
|
|
|
.TEXT()
|
|
|
|
|
.agentId(agentId)
|
|
|
|
|
.toUser(userId)
|
|
|
|
|
.content(enterpriseWeChatContentModel.getContent())
|
|
|
|
|
.build();
|
|
|
|
|
EnterpriseWeChatContentModel contentModel = (EnterpriseWeChatContentModel) taskInfo.getContentModel();
|
|
|
|
|
|
|
|
|
|
// 通用配置
|
|
|
|
|
WxCpMessage wxCpMessage = null;
|
|
|
|
|
|
|
|
|
|
if (SendMessageType.TEXT.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
wxCpMessage = WxCpMessage.TEXT().content(contentModel.getContent()).build();
|
|
|
|
|
} else if (SendMessageType.IMAGE.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
wxCpMessage = WxCpMessage.IMAGE().mediaId(contentModel.getMediaId()).build();
|
|
|
|
|
} else if (SendMessageType.VOICE.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
wxCpMessage = WxCpMessage.VOICE().mediaId(contentModel.getMediaId()).build();
|
|
|
|
|
} else if (SendMessageType.VIDEO.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
wxCpMessage = WxCpMessage.VIDEO().mediaId(contentModel.getMediaId()).description(contentModel.getDescription()).title(contentModel.getTitle()).build();
|
|
|
|
|
} else if (SendMessageType.FILE.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
wxCpMessage = WxCpMessage.FILE().mediaId(contentModel.getMediaId()).build();
|
|
|
|
|
} else if (SendMessageType.TEXT_CARD.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
wxCpMessage = WxCpMessage.TEXTCARD().url(contentModel.getUrl()).title(contentModel.getTitle()).description(contentModel.getDescription()).btnTxt(contentModel.getBtnTxt()).build();
|
|
|
|
|
} else if (SendMessageType.NEWS.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
List<NewArticle> newArticles = JSON.parseArray(contentModel.getArticles(), NewArticle.class);
|
|
|
|
|
wxCpMessage = WxCpMessage.NEWS().articles(newArticles).build();
|
|
|
|
|
} else if (SendMessageType.MP_NEWS.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
List<MpnewsArticle> mpNewsArticles = JSON.parseArray(contentModel.getMpNewsArticle(), MpnewsArticle.class);
|
|
|
|
|
wxCpMessage = WxCpMessage.MPNEWS().articles(mpNewsArticles).build();
|
|
|
|
|
} else if (SendMessageType.MARKDOWN.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
wxCpMessage = WxCpMessage.MARKDOWN().content(contentModel.getContent()).build();
|
|
|
|
|
} else if (SendMessageType.MINI_PROGRAM_NOTICE.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
Map contentItems = JSON.parseObject(contentModel.getContentItems(), Map.class);
|
|
|
|
|
wxCpMessage = WxCpMessage.newMiniProgramNoticeBuilder().appId(contentModel.getAppId()).page(contentModel.getPage()).emphasisFirstItem(contentModel.getEmphasisFirstItem()).contentItems(contentItems).title(contentModel.getTitle()).description(contentModel.getDescription()).build();
|
|
|
|
|
} else if (SendMessageType.TEMPLATE_CARD.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
// WxJava 未支持
|
|
|
|
|
}
|
|
|
|
|
wxCpMessage.setAgentId(agentId);
|
|
|
|
|
wxCpMessage.setToUser(userId);
|
|
|
|
|
return wxCpMessage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void recall(MessageTemplate messageTemplate) {
|
|
|
|
|
|
|
|
|
|