longz
2026-07-11 04e4346f9e05f8df3a40a96a8187c93f9d3d524c
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package com.ruoyi.common.core.utils;
 
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.constant.MsgConstants;
import com.ruoyi.common.core.utils.req.SubmitTempletReq;
import org.apache.commons.codec.binary.Base64;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.concurrent.ThreadLocalRandom;
 
public class MsgUtil {
 
    public final static String ecName= "四川明星新能源科技有限公司";
    public final static String secretKey= "MX_xny2023?9";
    public final static String sign= "1PUAVuY2b";
 
 
 
    /**
     * 更换手机号:【签名】验证码:XXX,用于更换手机号。请勿转发。
     * @param phone 手机号
     * @param code 验证码
     * @return
     */
    public static String codeMsg(String phone,String code){
        SubmitTempletReq submitReq = new SubmitTempletReq();
        String[] paramss = {code};
        submitReq.setApId(MsgConstants.CODE_AP_ID);
        submitReq.setEcName(ecName);
        submitReq.setSecretKey(secretKey);
        submitReq.setParams(JSON.toJSONString(paramss));
        submitReq.setMobiles(phone);
        submitReq.setAddSerial("");
        submitReq.setSign(sign);
        submitReq.setTemplateId(MsgConstants.CODE_TEMPLATE_ID);
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(submitReq.getEcName());
        stringBuffer.append(submitReq.getApId());
        stringBuffer.append(submitReq.getSecretKey());
        stringBuffer.append(submitReq.getTemplateId());
        stringBuffer.append(submitReq.getMobiles());
        stringBuffer.append(submitReq.getParams());
        stringBuffer.append(submitReq.getSign());
        stringBuffer.append(submitReq.getAddSerial());
        submitReq.setMac(MD5Util.getMD5(stringBuffer.toString()));
        String reqText = JSON.toJSONString(submitReq);
        //加密
        String encode = Base64.encodeBase64String(reqText.getBytes());
        System.err.println(encode);
        return encode;
    }
 
    /**
     * 更换手机号:【签名】验证码:XXX,用于更换手机号。请勿转发。
     * @param phone 手机号
     * @param code 验证码
     * @return
     */
    public static String applyCodeMsg(String phone,String code){
        SubmitTempletReq submitReq = new SubmitTempletReq();
        String[] paramss = {code};
        submitReq.setApId(MsgConstants.APPLY_AP_ID);
        submitReq.setEcName(ecName);
        submitReq.setSecretKey(secretKey);
        submitReq.setParams(JSON.toJSONString(paramss));
        submitReq.setMobiles(phone);
        submitReq.setAddSerial("");
        submitReq.setSign(sign);
        submitReq.setTemplateId(MsgConstants.APPLY_TEMPLATE_ID);
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(submitReq.getEcName());
        stringBuffer.append(submitReq.getApId());
        stringBuffer.append(submitReq.getSecretKey());
        stringBuffer.append(submitReq.getTemplateId());
        stringBuffer.append(submitReq.getMobiles());
        stringBuffer.append(submitReq.getParams());
        stringBuffer.append(submitReq.getSign());
        stringBuffer.append(submitReq.getAddSerial());
        submitReq.setMac(MD5Util.getMD5(stringBuffer.toString()));
        String reqText = JSON.toJSONString(submitReq);
        //加密
        String encode = Base64.encodeBase64String(reqText.getBytes());
        System.err.println(encode);
        return encode;
    }
 
 
    /**
     * 停车占位提醒:车辆已在3小时前完成充电,请及时取车,避免长时间占用充电资源。
     * @param phone 手机号
     * @return
     */
    public static String stopMsg(String phone){
        SubmitTempletReq submitReq = new SubmitTempletReq();
        submitReq.setTemplateId(MsgConstants.STOP_TEMPLATE_ID);
        submitReq.setApId(MsgConstants.STOP_AP_ID);
        submitReq.setEcName(ecName);
        submitReq.setSecretKey(secretKey);
        submitReq.setMobiles(phone);
        submitReq.setAddSerial("");
        submitReq.setSign(sign);
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(submitReq.getEcName());
        stringBuffer.append(submitReq.getApId());
        stringBuffer.append(submitReq.getSecretKey());
        stringBuffer.append(submitReq.getTemplateId());
        stringBuffer.append(submitReq.getMobiles());
        stringBuffer.append(submitReq.getParams());
        stringBuffer.append(submitReq.getSign());
        stringBuffer.append(submitReq.getAddSerial());
        submitReq.setMac(MD5Util.getMD5(stringBuffer.toString()));
        String reqText = JSON.toJSONString(submitReq);
        //加密
        String encode = Base64.encodeBase64String(reqText.getBytes());
        System.err.println(encode);
        return encode;
    }
 
    /**
     * 充电结束:车辆充电结束,请及时取车。
     * @param phone 手机号
     * @return
     */
    public static String chargeStopMsg(String phone){
        SubmitTempletReq submitReq = new SubmitTempletReq();
        submitReq.setTemplateId(MsgConstants.CHARGE_TEMPLATE_ID);
        submitReq.setApId(MsgConstants.CHARGE_AP_ID);
        submitReq.setEcName(ecName);
        submitReq.setSecretKey(secretKey);
        submitReq.setMobiles(phone);
        submitReq.setAddSerial("");
        submitReq.setSign(sign);
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(submitReq.getEcName());
        stringBuffer.append(submitReq.getApId());
        stringBuffer.append(submitReq.getSecretKey());
        stringBuffer.append(submitReq.getTemplateId());
        stringBuffer.append(submitReq.getMobiles());
        stringBuffer.append(submitReq.getParams());
        stringBuffer.append(submitReq.getSign());
        stringBuffer.append(submitReq.getAddSerial());
        submitReq.setMac(MD5Util.getMD5(stringBuffer.toString()));
        String reqText = JSON.toJSONString(submitReq);
        //加密
        String encode = Base64.encodeBase64String(reqText.getBytes());
        System.err.println(encode);
        return encode;
    }
 
    /**
     * VIP充电完成:VIP 用户您好!您在{电站名称}的充电已完成,本次电量{充电度数}度,费用共计{充电费用}元。
     */
    public static String vipChargeFinishMsg(String phone, String site, String chargingCapacity, String chargingFee){
        SubmitTempletReq submitReq = new SubmitTempletReq();
        String[] paramss = {limitSiteName(site), limitNumber(chargingCapacity), limitNumber(chargingFee)};
        submitReq.setParams(JSON.toJSONString(paramss));
        submitReq.setTemplateId(MsgConstants.VIP_CHARGE_FINISH_TEMPLATE_ID);
        submitReq.setApId(MsgConstants.VIP_CHARGE_FINISH_AP_ID);
        submitReq.setEcName(ecName);
        submitReq.setSecretKey(secretKey);
        submitReq.setMobiles(phone);
        submitReq.setAddSerial("");
        submitReq.setSign(sign);
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(submitReq.getEcName());
        stringBuffer.append(submitReq.getApId());
        stringBuffer.append(submitReq.getSecretKey());
        stringBuffer.append(submitReq.getTemplateId());
        stringBuffer.append(submitReq.getMobiles());
        stringBuffer.append(submitReq.getParams());
        stringBuffer.append(submitReq.getSign());
        stringBuffer.append(submitReq.getAddSerial());
        submitReq.setMac(MD5Util.getMD5(stringBuffer.toString()));
        String reqText = JSON.toJSONString(submitReq);
        return Base64.encodeBase64String(reqText.getBytes());
    }
 
    /**  phone  单词可拼接5000个号码
     * 桩故障(自动/手动):检测到【电站1】【编号】号桩设备离线,请及时查看处理!
     * @param phone 手机号
     * @param site 站点名称
     * @param chargeGun 桩编号
     * @return
     */
 
    public static String faultMsg(String phone,String site,String chargeGun){
        // 去除特殊字符 比如.-/{(等等
        site = site.replaceAll("[\\p{P}+~$`^=|<>~`$^+=|<>¥×]", "");
 
        SubmitTempletReq submitReq = new SubmitTempletReq();
        if(site.length()<=10){
            String[] paramss = {site,chargeGun};
            submitReq.setParams(JSON.toJSONString(paramss));
        }else{
            String work1 = site.substring(0,10);
            String[] paramss = {work1,chargeGun};
            submitReq.setParams(JSON.toJSONString(paramss));
        }
        submitReq.setTemplateId(MsgConstants.FAULT_TEMPLATE_ID);
        submitReq.setApId(MsgConstants.FAULT_AP_ID);
        submitReq.setEcName(ecName);
        submitReq.setSecretKey(secretKey);
        submitReq.setMobiles(phone);
        submitReq.setAddSerial("");
        submitReq.setSign(sign);
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(submitReq.getEcName());
        stringBuffer.append(submitReq.getApId());
        stringBuffer.append(submitReq.getSecretKey());
        stringBuffer.append(submitReq.getTemplateId());
        stringBuffer.append(submitReq.getMobiles());
        stringBuffer.append(submitReq.getParams());
        stringBuffer.append(submitReq.getSign());
        stringBuffer.append(submitReq.getAddSerial());
        submitReq.setMac(MD5Util.getMD5(stringBuffer.toString()));
        String reqText = JSON.toJSONString(submitReq);
        //加密
        String encode = Base64.encodeBase64String(reqText.getBytes());
        return encode;
    }
    /**
     * 生成验证码
     * @return
     */
    public static String createCode(){
        return String.valueOf(ThreadLocalRandom.current().nextInt(100000, 999999));
    }
 
    private static String limitSiteName(String site) {
        String value = site == null ? "充电站" : site.replaceAll("[^\\u4e00-\\u9fa5\\d,。!?、:;()《》【】]", "");
        if (value.length() == 0) {
            value = "充电站";
        }
        return value.length() <= 10 ? value : value.substring(0, 10);
    }
 
    private static String limitNumber(String value) {
        if (value == null) {
            return "0";
        }
        String number = value.replaceAll("[^\\d.]", "");
        if (number.length() == 0) {
            return "0";
        }
        try {
            number = new BigDecimal(number).setScale(0, RoundingMode.HALF_UP).toPlainString();
        } catch (NumberFormatException e) {
            number = number.replaceAll("\\D", "");
        }
        if (number.length() == 0) {
            return "0";
        }
        return number.length() <= 5 ? number : number.substring(0, 5);
    }
 
}