BarkChannel.php 967 B

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