PushPlusChannel.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Channels;
  3. use Helpers;
  4. use Http;
  5. use Illuminate\Notifications\Notification;
  6. use Log;
  7. class PushPlusChannel
  8. {
  9. public function send($notifiable, Notification $notification)
  10. {
  11. $message = $notification->toCustom($notifiable);
  12. $response = Http::timeout(15)->post('https://www.pushplus.plus/send', [
  13. 'token' => sysConfig('pushplus_token'),
  14. 'title' => $message['title'],
  15. 'content' => $message['content'],
  16. 'template' => 'markdown',
  17. ]);
  18. // 发送成功
  19. if ($response->ok()) {
  20. $ret = $response->json();
  21. if ($ret['code'] === 200) {
  22. Helpers::addNotificationLog($message['title'], $message['content'], 7);
  23. return $ret;
  24. }
  25. // 发送失败
  26. Helpers::addNotificationLog($message['title'], $message['content'], 7, 'admin', -1, $ret ? $ret['msg'] : '未知');
  27. return false;
  28. }
  29. // 发送错误
  30. Log::error('PushPlus消息推送异常:'.var_export($response, true));
  31. return false;
  32. }
  33. }