PushDeerChannel.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Channels;
  3. use Helpers;
  4. use Http;
  5. use Illuminate\Notifications\Notification;
  6. use Log;
  7. class PushDeerChannel
  8. {
  9. public function send($notifiable, Notification $notification)
  10. {
  11. $message = $notification->toCustom($notifiable);
  12. $response = Http::timeout(15)
  13. ->post('https://api2.pushdeer.com/message/push?pushkey='.sysConfig('pushDeer_key').'&text='.urlencode($message['title']).'&desp='
  14. .urlencode($message['content']).'&type=markdown');
  15. // 发送成功
  16. if ($response->ok()) {
  17. $ret = $response->json();
  18. if (! $ret['code']) {
  19. Helpers::addNotificationLog($message['title'], $message['content'], 9);
  20. return $ret;
  21. }
  22. // 发送失败
  23. Helpers::addNotificationLog($message['title'], $message['content'], 9, -1, $ret ? $ret['error'] : '未知');
  24. return false;
  25. }
  26. // 发送错误
  27. Log::critical('[PushDeer] 消息推送异常:'.var_export($response, true));
  28. return false;
  29. }
  30. }