PushBearChannel.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Channels;
  3. use Helpers;
  4. use Http;
  5. use Illuminate\Notifications\Notification;
  6. use Log;
  7. class PushBearChannel
  8. {
  9. public function send($notifiable, Notification $notification)
  10. {
  11. $message = $notification->toCustom($notifiable);
  12. $response = Http::timeout(15)->get('https://pushbear.ftqq.com/sub', [
  13. 'sendkey' => sysConfig('push_bear_send_key'),
  14. 'text' => $message['title'],
  15. 'desp' => $message['content'],
  16. ]);
  17. if ($response->ok()) {
  18. $ret = $response->json();
  19. // 发送成功
  20. if ($ret) {
  21. Helpers::addMarketing(2, $message['title'], $message['content']);
  22. return $ret;
  23. }
  24. // 发送失败
  25. Helpers::addMarketing(2, $message['title'], $message['content'], -1, $ret['message']);
  26. return false;
  27. }
  28. // 发送错误
  29. Log::error('Bark消息推送异常:'.var_export($response, true));
  30. return false;
  31. }
  32. }