| | |
| | | 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 { |
| | |
| | | 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 手机号 |
| | |
| | | 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); |
| | | } |
| | | |
| | | } |