From e550137ebfa106fe1de69cd066e476ee7c0571b8 Mon Sep 17 00:00:00 2001 From: lyf66 Date: Thu, 25 Sep 2025 14:32:23 +0800 Subject: [PATCH] =?UTF-8?q?test(sms):=20=E6=B7=BB=E5=8A=A0=E7=94=9F?= =?UTF-8?q?=E6=97=A5=E7=9F=AD=E4=BF=A1=E5=8F=91=E9=80=81=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95-=20=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=20BirthdaySmsServiceTest=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=B1=BB-=20=E9=85=8D=E7=BD=AE=E6=B5=8B=E8=AF=95=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=BD=BF=E7=94=A8=20dev=20profile=20-=20=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E6=B5=8B=E8=AF=95=E6=96=B9=E6=B3=95=20testSendBirthda?= =?UTF-8?q?ySms=20=E7=94=A8=E4=BA=8E=E9=AA=8C=E8=AF=81=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E5=8F=91=E9=80=81=E9=80=BB=E8=BE=91=20-=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=B8=93=E5=AE=B6=E6=95=B0=E6=8D=AE=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E4=B8=8E=E6=A8=A1=E6=9D=BF=E6=9B=BF=E6=8D=A2=E9=80=BB?= =?UTF-8?q?=E8=BE=91=20-=20=E9=9B=86=E6=88=90=20SmsHelper=20=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E5=AE=9E=E9=99=85=E7=9F=AD=E4=BF=A1=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=20-=20=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=92=8C=E6=B5=8B=E8=AF=95=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SmsBirthdayServiceImpl.java | 5 +- .../service/impl/BirthdaySmsServiceTest.java | 85 +++++++++++++++++++ 2 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/whdc/service/impl/BirthdaySmsServiceTest.java diff --git a/src/main/java/com/whdc/service/impl/SmsBirthdayServiceImpl.java b/src/main/java/com/whdc/service/impl/SmsBirthdayServiceImpl.java index da27cfa..5c6f870 100644 --- a/src/main/java/com/whdc/service/impl/SmsBirthdayServiceImpl.java +++ b/src/main/java/com/whdc/service/impl/SmsBirthdayServiceImpl.java @@ -87,9 +87,9 @@ public class SmsBirthdayServiceImpl extends ServiceImpl specialists = Arrays.asList(specialist); + + System.out.println("专家信息:"); + System.out.println("姓名:" + specialist.getName()); + System.out.println("电话:" + specialist.getPhone()); + System.out.println("模板:{姓名},测试短信接口"); + + try { + // 直接使用你提供的模板内容测试发送逻辑 + String template = "{姓名},测试短信接口"; + System.out.println("使用模板:" + template); + + // 调用内部方法进行测试 + testSendWithTemplate(specialists, template); + + System.out.println("=== 生日短信发送测试完成!==="); + } catch (Exception e) { + System.err.println("测试过程中发生异常:" + e.getMessage()); + e.printStackTrace(); + throw e; + } + } + + /** + * 使用指定模板测试发送短信 + */ + private void testSendWithTemplate(List specialists, String template) { + System.out.println("开始使用模板发送短信..."); + + for (Specialist specialist : specialists) { + try { + // 替换模板中的占位符 + String content = template.replace("{姓名}", specialist.getName()); + System.out.println("生成的短信内容:" + content); + + // 使用SmsHelper发送个性化短信 + List phoneList = Collections.singletonList(specialist.getPhone()); + String sendResult = smsHelper.send(phoneList, content); + + System.out.println("向专家" + specialist.getName() + "发送生日短信结果: " + sendResult); + System.out.println("短信发送完成,结果:" + sendResult); + + } catch (Exception e) { + System.err.println("向专家" + specialist.getName() + "发送生日短信时发生异常: " + e.getMessage()); + e.printStackTrace(); + } + } + } +} \ No newline at end of file