All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nb6868.onex.sys.mail.WxMaSubscribeMailService Maven / Gradle / Ivy

There is a newer version: 4.2.16
Show newest version
package com.nb6868.onex.sys.mail;

import com.nb6868.onex.common.msg.MsgSendForm;
import com.nb6868.onex.sys.entity.MsgTplEntity;

/**
 * 微信小程序订阅消息 消息服务
 *
 * @author Charles [email protected]
 */
public class WxMaSubscribeMailService extends AbstractMailService {

    @Override
    public boolean sendMail(MsgTplEntity mailTpl, MsgSendForm request) {
        /*WxProp wxProp = JacksonUtils.jsonToPojo(mailTpl.getParam(), WxProp.class);
        AssertUtils.isNull(wxProp, "消息模板配置错误");

        // 初始化service
        WxMpService wxService = new WxMpServiceImpl();
        WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
        config.setAppId(wxProp.getAppid());
        config.setSecret(wxProp.getSecret());
        config.setToken(wxProp.getToken());
        config.setAesKey(wxProp.getAesKey());
        wxService.setWxMpConfigStorage(config);

        // 可能是发送多个
        List openIds = StrSplitter.splitTrim(request.getMailTo(), ',', true);
        for (String openId : openIds) {
            // 构建消息
            WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
                    .toUser(openId)
                    .templateId(wxProp.getTemplateId())
                    .url("")
                    .build();

            // 封装消息实际内容
            Map contentParam = JacksonUtils.jsonToMap(request.getContentParam());
            String content = TemplateUtils.getTemplateContent("wxTemplateContent", mailTpl.getContent(), contentParam);

            for (String key : contentParam.keySet()) {
                templateMessage.addData(new WxMpTemplateData(key, contentParam.get(key).toString()));
            }

            Const.ResultEnum state = Const.ResultEnum.FAIL;
            String result;
            try {
                result = wxService.getTemplateMsgService().sendTemplateMsg(templateMessage);
                state = Const.ResultEnum.SUCCESS;
            } catch (WxErrorException e) {
                e.printStackTrace();
                result = e.getError().getJson();
            }
            // 保存记录
            MailLogEntity mailLog = new MailLogEntity();
            mailLog.setTenantCode(mailTpl.getTenantCode());
            mailLog.setMailTo(openId);
            mailLog.setState(state.value());
            mailLog.setResult(result);
            mailLog.setContent(content);
            mailLog.setTplCode(mailTpl.getCode());
            mailLog.setTplType(mailTpl.getType());
            mailLog.setContentParams(request.getContentParam());
            mailLog.setConsumeState(Const.BooleanEnum.FALSE.value());
            save(mailLog);
        }*/
        return true;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy