nidapeng
2024-04-25 f89719902615823be2a1ddc1b5082f52eed31984
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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;
    }
 
 
}