PushPlusChannel.php 1.2 KB

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