TgChatChannel.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Channels;
  3. use Helpers;
  4. use Http;
  5. use Illuminate\Notifications\Notification;
  6. use Log;
  7. class TgChatChannel
  8. {
  9. public function send($notifiable, Notification $notification)
  10. {
  11. $message = $notification->toCustom($notifiable);
  12. $response = Http::timeout(15)->get('https://tgbot-red.vercel.app/api?token='.sysConfig('tg_chat_token').'&message='.$message['title'].PHP_EOL.'=========='.PHP_EOL.$message['content']);
  13. // 发送成功
  14. if ($response->ok()) {
  15. $ret = $response->json();
  16. if ($ret['code'] === 200) {
  17. Helpers::addNotificationLog($message['title'], $message['content'], 6);
  18. return $ret;
  19. }
  20. // 发送失败
  21. Helpers::addNotificationLog($message['title'], $message['content'], 6, 'admin', -1, $ret ? $ret['message'] : '未知');
  22. return false;
  23. }
  24. // 发送错误
  25. Log::critical('TG酱消息推送异常:'.var_export($response, true));
  26. return false;
  27. }
  28. }