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