test_sms_notification.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // 直接测试短信发送功能
  2. const log = {
  3. app: console.log
  4. };
  5. const AlertLevel: Record<number, string> = {
  6. 1: '一级告警',
  7. 2: '二级告警',
  8. 3: '三级告警'
  9. };
  10. // 模拟短信发送
  11. async function testSmsSend() {
  12. const phone = '13800138000';
  13. const username = 'testuser';
  14. const alert = {
  15. device_id: 'device001',
  16. alert_level: 1,
  17. alert_message: '温度过高',
  18. created_at: new Date().toISOString()
  19. };
  20. const smsContent = `【告警通知】
  21. 设备ID: ${alert.device_id}
  22. 告警级别: ${AlertLevel[alert.alert_level] || '未知'}
  23. 告警时间: ${new Date(alert.created_at).toLocaleString()}
  24. 告警内容: ${alert.alert_message}`;
  25. console.log('=== 测试短信发送 ===');
  26. console.log('接收号码:', phone);
  27. console.log('短信内容:\n', smsContent);
  28. console.log('===================');
  29. log.app(`成功发送短信通知给用户 ${username}(${phone})`);
  30. }
  31. console.log('开始测试短信通知...');
  32. testSmsSend()
  33. .then(() => console.log('测试完成'))
  34. .catch(err => console.error('测试失败:', err));