From 762fe744eab6db8394b189a057efb4a28b76e996 Mon Sep 17 00:00:00 2001 From: wen <1455474577@qq.com> Date: Thu, 30 Dec 2021 16:06:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9F=AD=E4=BF=A1=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E4=B8=AD=E5=AD=98=E5=9C=A8=E7=9A=84=E9=9A=90=E8=97=8F?= =?UTF-8?q?Bug=EF=BC=8C=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E9=AD=94=E6=B3=95=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../general/constant/AliyunSendResult.java | 17 +++++++ .../xhpc/general/constant/AliyunTemplate.java | 42 ++++++++++++++++++ .../constant/AliyunTemplateKeyWord.java | 38 ++++++++++++++++ .../general/controller/XhpcSmsController.java | 32 +++++++------- .../general/service/XhpcSmsServiceImpl.java | 44 ++++++++----------- 5 files changed, 132 insertions(+), 41 deletions(-) create mode 100644 xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunSendResult.java create mode 100644 xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplate.java create mode 100644 xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplateKeyWord.java diff --git a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunSendResult.java b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunSendResult.java new file mode 100644 index 00000000..369e3d9a --- /dev/null +++ b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunSendResult.java @@ -0,0 +1,17 @@ +package com.xhpc.general.constant; + +/** + * 阿里云短信服务发送结果常量类 + * + * @author WH + * @date 2021/12/30 14:56 + * @since version-1.0 + */ +public class AliyunSendResult { + + /** + * 短信发送成功 + */ + public static final String SUCCESS = "OK"; + +} diff --git a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplate.java b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplate.java new file mode 100644 index 00000000..e04df85b --- /dev/null +++ b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplate.java @@ -0,0 +1,42 @@ +package com.xhpc.general.constant; + +/** + * 阿里云短信模板常量类 + * + * @author WH + * @date 2021/12/30 14:40 + * @since version-1.0 + */ +public class AliyunTemplate { + + /** + * 阿里云短信签名 + */ + public static final String SIGNATURE_NAME = "小华充电"; + /** + * 电量充满 + */ + public static final String CHARGE_FULL = "SMS_227005968"; + /** + * 充电金额不足 + */ + public static final String CHARGE_MONEY_INSUFFICIENT = "SMS_226935795"; + /** + * 直流桩停止充电 + */ + public static final String DIRECT_STREAM_PILE_STOP_CHARGE = "SMS_226945037"; + /** + * 直流桩停止充电 + */ + public static final String INTERFLOW_STREAM_PILE_STOP_CHARGE = "SMS_226786374"; + /** + * 验证码 + */ + public static final String VALIDATE_CODE = "SMS_226786362"; + /** + * 退款失败 + */ + public static final String REFUND_FAIL = "SMS_231445428"; + + +} diff --git a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplateKeyWord.java b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplateKeyWord.java new file mode 100644 index 00000000..0e46ec9d --- /dev/null +++ b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/constant/AliyunTemplateKeyWord.java @@ -0,0 +1,38 @@ +package com.xhpc.general.constant; + +/** + * 阿里云模板内容关键字常量类 + * 根据模板话语判断该调用哪个模板id + * + * @author WH + * @date 2021/12/30 15:59 + * @since version-1.0 + */ +public class AliyunTemplateKeyWord { + + /** + * 电量充满 + */ + public static final String CHARGE_FULL = "设定的SOC"; + /** + * 充电金额不足 + */ + public static final String CHARGE_MONEY_INSUFFICIENT = "余额小于"; + /** + * 直流桩停止充电 + */ + public static final String DIRECT_STREAM_PILE_STOP_CHARGE = "电量为"; + /** + * 直流桩停止充电 + */ + public static final String INTERFLOW_STREAM_PILE_STOP_CHARGE = "总费用为"; + /** + * 验证码 + */ + public static final String VALIDATE_CODE = "SMS_226786362"; + /** + * 退款失败 + */ + public static final String REFUND_FAIL = "退款-尊敬的用户"; + +} diff --git a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/controller/XhpcSmsController.java b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/controller/XhpcSmsController.java index 44400c04..72327ae2 100644 --- a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/controller/XhpcSmsController.java +++ b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/controller/XhpcSmsController.java @@ -3,6 +3,8 @@ package com.xhpc.general.controller; import com.xhpc.common.core.web.controller.BaseController; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.core.web.page.TableDataInfo; +import com.xhpc.general.constant.AliyunTemplate; +import com.xhpc.general.constant.AliyunTemplateKeyWord; import com.xhpc.general.service.IXhpcSmsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -58,21 +60,21 @@ public class XhpcSmsController extends BaseController { paramMap.remove("phone"); paramMap.remove("content"); //判断内容是什么,调用相应的模板 - if (content.contains("电量为")) { - signatureName = "小华充电"; - templateId = "SMS_226945037"; - } else if (content.contains("总费用为")) { - signatureName = "小华充电"; - templateId = "SMS_226786374"; - } else if (content.contains("余额小于")) { - signatureName = "小华充电"; - templateId = "SMS_226935795"; - } else if (content.contains("设定的SOC")) { - signatureName = "小华充电"; - templateId = "SMS_227005968"; - }else if (content.contains("退款-尊敬的用户")) { - signatureName = "小华充电"; - templateId = "SMS_231445428"; + if (content.contains(AliyunTemplateKeyWord.DIRECT_STREAM_PILE_STOP_CHARGE)) { + signatureName = AliyunTemplate.SIGNATURE_NAME; + templateId = AliyunTemplate.DIRECT_STREAM_PILE_STOP_CHARGE; + } else if (content.contains(AliyunTemplateKeyWord.INTERFLOW_STREAM_PILE_STOP_CHARGE)) { + signatureName = AliyunTemplate.SIGNATURE_NAME; + templateId = AliyunTemplate.INTERFLOW_STREAM_PILE_STOP_CHARGE; + } else if (content.contains(AliyunTemplateKeyWord.CHARGE_MONEY_INSUFFICIENT)) { + signatureName = AliyunTemplate.SIGNATURE_NAME; + templateId = AliyunTemplate.CHARGE_MONEY_INSUFFICIENT; + } else if (content.contains(AliyunTemplateKeyWord.CHARGE_FULL)) { + signatureName = AliyunTemplate.SIGNATURE_NAME; + templateId = AliyunTemplate.CHARGE_FULL; + } else if (content.contains(AliyunTemplateKeyWord.REFUND_FAIL)) { + signatureName = AliyunTemplate.SIGNATURE_NAME; + templateId = AliyunTemplate.REFUND_FAIL; } xhpcSmsService.sendNotice(phone, signatureName, templateId, paramMap); diff --git a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/service/XhpcSmsServiceImpl.java b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/service/XhpcSmsServiceImpl.java index 4aebb25d..83b54977 100644 --- a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/service/XhpcSmsServiceImpl.java +++ b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/service/XhpcSmsServiceImpl.java @@ -7,6 +7,8 @@ import com.aliyun.dysmsapi20170525.models.SendSmsResponse; import com.aliyun.dysmsapi20170525.models.SendSmsResponseBody; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.common.redis.service.RedisService; +import com.xhpc.general.constant.AliyunSendResult; +import com.xhpc.general.constant.AliyunTemplate; import com.xhpc.general.domain.XhpcSms; import com.xhpc.general.mapper.XhpcSmsMapper; import com.xhpc.general.util.sms.SmsUtil; @@ -103,7 +105,7 @@ public class XhpcSmsServiceImpl implements IXhpcSmsService { //判断发送结果 String statusCode = neededParam.get("statusCode"); - if (statusCode.equals("OK")) { + if (statusCode.equals(AliyunSendResult.SUCCESS)) { REDIS.setCacheObject(pvToken, random, 300L, TimeUnit.SECONDS); //1分钟有效时间设置,防止用户频繁调用 REDIS.setCacheObject(token, random, 60L, TimeUnit.SECONDS); @@ -152,7 +154,7 @@ public class XhpcSmsServiceImpl implements IXhpcSmsService { //判断发送结果 String statusCode = neededParam.get("statusCode"); - if ("OK".equals(statusCode)) { + if (AliyunSendResult.SUCCESS.equals(statusCode)) { xhpcSms.setStatus(0); } else { xhpcSms.setStatus(1); @@ -217,40 +219,30 @@ public class XhpcSmsServiceImpl implements IXhpcSmsService { private String getTemplateContent(String templateId, Map paramMap) throws Exception { - if (templateId == "SMS_227005968") { + if (AliyunTemplate.CHARGE_FULL.equals(templateId)) { String battery = paramMap.get("battery"); - String templateContent = "尊敬的用户,你的车辆已充电达至设定的SOC:" + battery + "%并停止充电,请您尽快将车辆挪走以方便他人使用充电桩,谢谢合作。"; - return templateContent; + return "尊敬的用户,你的车辆已充电达至设定的SOC:" + battery + "%并停止充电,请您尽快将车辆挪走以方便他人使用充电桩,谢谢合作。"; } - if (templateId == "SMS_226935795") { + if (AliyunTemplate.CHARGE_MONEY_INSUFFICIENT.equals(templateId)) { String money = paramMap.get("money"); - String templateContent = "尊敬的用户,你的账户余额小于" + money + "元,为不影响您的正常充电,请您尽快充值交费,谢谢。"; - return templateContent; + return "尊敬的用户,你的账户余额小于" + money + "元,为不影响您的正常充电,请您尽快充值交费,谢谢。"; } - if (templateId == "SMS_226786374") { - String sumMoney = paramMap.get("sumMoney"); - String templateContent = "尊敬的用户,你的爱车已停止充电,请尽快挪车。总费用为:" + sumMoney + "元,充电费用明细,请查询小华充电小程序,谢谢。"; - return templateContent; - } - if (templateId == "SMS_227005968") { + if (AliyunTemplate.DIRECT_STREAM_PILE_STOP_CHARGE.equals(templateId)) { String elec = paramMap.get("elec"); String sumMoney = paramMap.get("sumMoney"); - String templateContent = "尊敬的用户,你的爱车已停止充电,请尽快挪车。电量为:" + elec + ",总费用为:" + sumMoney + "元,充电费用明细,请查询小华充电小程序,谢谢。"; - return templateContent; + return "尊敬的用户,你的爱车已停止充电,请尽快挪车。电量为:" + elec + ",总费用为:" + sumMoney + "元,充电费用明细,请查询小华充电小程序,谢谢。"; } - if (templateId == "SMS_226786362") { + if (AliyunTemplate.INTERFLOW_STREAM_PILE_STOP_CHARGE.equals(templateId)) { + String sumMoney = paramMap.get("sumMoney"); + return "尊敬的用户,你的爱车已停止充电,请尽快挪车。总费用为:" + sumMoney + "元,充电费用明细,请查询小华充电小程序,谢谢。"; + } + if (AliyunTemplate.VALIDATE_CODE.equals(templateId)) { String code = paramMap.get("code"); - String templateContent = "您的验证码是:" + code + ",有效期为5分钟。如非本人操作,可不用理会。"; - return templateContent; + return "您的验证码是:" + code + ",有效期为5分钟。如非本人操作,可不用理会。"; } - if (templateId == "SMS_231445428") { - String templateContent = "【小华充电】退款-尊敬的用户,当前退款人数较多,申请退款失败,请您重新提交申请!"; - return templateContent; + if (AliyunTemplate.REFUND_FAIL.equals(templateId)) { + return "【小华充电】退款-尊敬的用户,当前退款人数较多,申请退款失败,请您重新提交申请!"; } - throw new Exception("没有对应的模板id"); - } - - }