package com.doumee.core.wx.wxPlat; 
 | 
  
 | 
import com.doumee.dao.business.model.Visits; 
 | 
import lombok.extern.slf4j.Slf4j; 
 | 
import me.chanjar.weixin.common.error.WxErrorException; 
 | 
import me.chanjar.weixin.mp.api.WxMpService; 
 | 
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; 
 | 
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; 
 | 
import org.apache.commons.lang3.StringUtils; 
 | 
import org.springframework.stereotype.Component; 
 | 
  
 | 
/** 
 | 
 * 微信公众号通知 
 | 
 * 
 | 
 * @Author : Rk 
 | 
 * @create 2023/12/27 9:19 
 | 
 */ 
 | 
@Slf4j 
 | 
@Component 
 | 
public class WxPlatNotice { 
 | 
  
 | 
    /** 
 | 
     * 微信公众号API的Service 
 | 
     */ 
 | 
    private final WxMpService wxMpService; 
 | 
  
 | 
    public WxPlatNotice(WxMpService wxMpService) { 
 | 
        this.wxMpService = wxMpService; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 访客记录审批业务通知 
 | 
     */ 
 | 
    public Boolean  sendVisitAuditTemplateNotice(Visits visits,String prefix,String tempId){ 
 | 
        if(StringUtils.isBlank(visits.getOpenid())){ 
 | 
            return false; 
 | 
        } 
 | 
        WxMpTemplateMessage templateMessage =  WxMpTemplateMessage.builder() 
 | 
                .toUser(visits.getOpenid()) 
 | 
                .templateId(tempId) 
 | 
                .url(prefix + visits.getId()) 
 | 
                .build(); 
 | 
        String thing1 = "待审批"; 
 | 
        if(visits.getStatus()==2){ 
 | 
            thing1 = "审核通过"; 
 | 
        }else if(visits.getStatus()==3){ 
 | 
            thing1 = "审核不通过"; 
 | 
        }else if(visits.getStatus()==5){ 
 | 
            thing1 = "设备授权成功"; 
 | 
        }else if(visits.getStatus()==6){ 
 | 
            thing1 = "设备授权未成功"; 
 | 
        } 
 | 
        // 添加模板数据 
 | 
        templateMessage.addData(new WxMpTemplateData("thing1", thing1)) 
 | 
                .addData(new WxMpTemplateData("thing2", visits.getName())) 
 | 
                .addData(new WxMpTemplateData("phone_number6", visits.getPhone())); 
 | 
        String msgId = null; 
 | 
        try { 
 | 
            // 发送模板消息 
 | 
            msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage); 
 | 
        } catch (WxErrorException e) { 
 | 
            e.printStackTrace(); 
 | 
        } 
 | 
        log.warn("·==++--·推送微信模板信息:{}·--++==·", msgId != null ? "成功" : "失败"); 
 | 
        return msgId != null; 
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |