k94314517
2024-12-12 d826a023e72face0707cf4d6832957e8397f1d37
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.doumee.core.wx;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.HttpsUtil;
import com.doumee.dao.business.model.Bookings;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
 
import java.util.*;
 
/**
 * 微信公众号通知
 *
 * @Author : Rk
 * @create 2023/12/27 9:19
 */
@Slf4j
@Component
public class WxPlatNotice {
 
    public void  testSendNotice(List<String> openIds,String token){
        if(CollectionUtils.isNotEmpty(openIds)){
            String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
            //整体参数map
            Map<String, Object> paramMap = new HashMap<String, Object>();
            //消息主题显示相关map
            Map<String, Object> dataMap = new HashMap<String, Object>();
            Map<String, Object> const9 = new HashMap<String,Object>();
            const9.put("value","申请待您审批");
            Map<String, Object> thing1 = new HashMap<String,Object>();
            thing1.put("value", "测试名称");
            Map<String, Object> car_number7 = new HashMap<String,Object>();
            car_number7.put("value","皖AP12345");
            Map<String, Object> character_string6 = new HashMap<String,Object>();
            character_string6.put("value","1");
            Map<String, Object> thing4 = new HashMap<String,Object>();
            thing4.put("value","理由");
            dataMap.put("const9",const9);
            dataMap.put("thing1",thing1);
            dataMap.put("car_number7",car_number7);
            dataMap.put("character_string6",character_string6);
            dataMap.put("thing4",thing4);
            paramMap.put("data", dataMap);
            for (String openId:openIds) {
                paramMap.clear();
                paramMap.put("template_id", "SPwvgtASkm1aMDBsYhX2wHKdL2JBEGPknDkgniSza2Y");
                paramMap.put("touser", openId);
                paramMap.put("data", dataMap);
                String response = HttpsUtil.postJson(postUrL, JSONObject.toJSONString(paramMap));
                if(StringUtils.isBlank(response)){
                    log.warn("·==++--·推送微信模板信息:{}·--++==·", "失败");
                }else{
                    JSONObject json = JSONObject.parseObject(response);
                    log.warn("·==++--·推送微信模板信息:{}·--++==·", Constants.equalsInteger(json.getInteger("errcode"),Constants.ZERO)?"成功":"失败"+json.getString("errmsg"));
                }
            }
//            log.warn("·==++--·推送微信模板信息:{}·--++==·", msgId != null ? "成功" : "失败");
        }
    }
 
    /**
     * 会议室预约通知
     * @param bookings
     * @param tempId CuoDoxOl6SFwi4NhNgOQgKSJVjDD4VCIaPYlnbv_zdY
     * @param token
     * @param openIds
     */
    public void  sendMeetingBookTemplateNotice(SystemDictDataBiz systemDictDataBiz,Bookings bookings,String tempId, String token, Set<String> openIds){
        if(CollectionUtils.isNotEmpty(openIds)){
            String jumpUrl = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                    Constants.WxUrlParams.MEETING,bookings.getId().toString());
 
            String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
            //整体参数map
            Map<String, Object> paramMap = new HashMap<String, Object>();
            //消息主题显示相关map
            Map<String, Object> dataMap = new HashMap<String, Object>();
            //会议名称
            Map<String, Object> thing1 = new HashMap<String,Object>();
            thing1.put("value",bookings.getName());
            //会议时间
            Map<String, Object> time2 = new HashMap<String,Object>();
            time2.put("value", DateUtil.getFomartDate(bookings.getStartTime(),"yyyy-MM-dd HH:mm:ss") );
            //会议地点
            Map<String, Object> thing3 = new HashMap<String,Object>();
            thing3.put("value",bookings.getRoomName());
            //发起人
            Map<String, Object> thing6 = new HashMap<String,Object>();
            thing6.put("value",bookings.getManagerInfo());
 
            dataMap.put("thing1",thing1);
            dataMap.put("time2",time2);
            dataMap.put("thing3",thing3);
            dataMap.put("thing6",thing6);
            paramMap.put("data", dataMap);
            for (String openId:openIds) {
                paramMap.clear();
                paramMap.put("url", jumpUrl);
                paramMap.put("template_id", tempId);
                paramMap.put("touser", openId);
                paramMap.put("data", dataMap);
                String response = HttpsUtil.postJson(postUrL, JSONObject.toJSONString(paramMap));
                if(StringUtils.isBlank(response)){
                    log.warn("·==++--·推送微信模板信息:{}·--++==·", "失败");
                }else{
                    JSONObject json = JSONObject.parseObject(response);
                    log.warn("·==++--·推送微信模板信息:{}·--++==·", Constants.equalsInteger(json.getInteger("errcode"),Constants.ZERO)?"成功":"失败"+json.getString("errmsg"));
                }
            }
        }
    }
 
 
    /**
     * 会议室取消通知
     * @param bookings
     * @param tempId  CiB6vCT2InovAoQfudY-lvzLSV0-3lfz3a5GsSFCzd8
     * @param token
     * @param openIds
     */
    public void  sendMeetingBookCancelTemplateNotice(SystemDictDataBiz systemDictDataBiz,Bookings bookings, String tempId, String token, Set<String> openIds){
        if(CollectionUtils.isNotEmpty(openIds)){
            String jumpUrl = Constants.getWxUrl(systemDictDataBiz.queryByCode(Constants.PLATFORM,Constants.WX_REDIRECT_URL).getCode(),
                    Constants.WxUrlParams.MEETING,bookings.getId().toString());
 
 
            String postUrL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+token;
            //整体参数map
            Map<String, Object> paramMap = new HashMap<String, Object>();
            //消息主题显示相关map
            Map<String, Object> dataMap = new HashMap<String, Object>();
            //会议名称
            Map<String, Object> thing1 = new HashMap<String,Object>();
            thing1.put("value",bookings.getName());
            //会议时间
            Map<String, Object> time6 = new HashMap<String,Object>();
            time6.put("value", DateUtil.getFomartDate(bookings.getStartTime(),"yyyy-MM-dd HH:mm:ss") );
            //会议地点
            Map<String, Object> thing2 = new HashMap<String,Object>();
            thing2.put("value",bookings.getRoomName());
            //预约人员
            Map<String, Object> thing4 = new HashMap<String,Object>();
            thing4.put("value",bookings.getManagerInfo());
 
            dataMap.put("thing1",thing1);
            dataMap.put("time6",time6);
            dataMap.put("thing2",thing2);
            dataMap.put("thing4",thing4);
            for (String openId:openIds) {
                paramMap.clear();
                paramMap.put("url", jumpUrl);
                paramMap.put("data", dataMap);
                paramMap.put("template_id", tempId);
                paramMap.put("touser", openId);
                paramMap.put("data", dataMap);
                String response = HttpsUtil.postJson(postUrL, JSONObject.toJSONString(paramMap));
                if(StringUtils.isBlank(response)){
                    log.warn("·==++--·推送微信模板信息:{}·--++==·", "失败");
                }else{
                    JSONObject json = JSONObject.parseObject(response);
                    log.warn("·==++--·推送微信模板信息:{}·--++==·", Constants.equalsInteger(json.getInteger("errcode"),Constants.ZERO)?"成功":"失败"+json.getString("errmsg"));
                }
            }
        }
    }
 
 
 
 
}