iYuuChannel.php 1.0 KB

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