iYuuChannel.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. private ?string $token;
  10. public function __construct()
  11. {
  12. $this->token = sysConfig('iYuu_token');
  13. if ($this->token) {
  14. Log::critical('[爱语飞飞] TOKEN 为空');
  15. }
  16. }
  17. public function send($notifiable, Notification $notification)
  18. {
  19. $message = $notification->toCustom($notifiable);
  20. $response = Http::timeout(15)->post('https://iyuu.cn/'.$this->token.'.send?title='.urlencode($message['title']).'&desp='.urlencode($message['content']));
  21. // 发送成功
  22. if ($response->ok()) {
  23. $ret = $response->json();
  24. if (! $ret['errcode']) {
  25. Helpers::addNotificationLog($message['title'], $message['content'], 8);
  26. return $ret;
  27. }
  28. // 发送失败
  29. Helpers::addNotificationLog($message['title'], $message['content'], 8, -1, $ret ? $ret['errmsg'] : '未知');
  30. return false;
  31. }
  32. // 发送错误
  33. Log::critical('[爱语飞飞] 消息推送异常:'.var_export($response, true));
  34. return false;
  35. }
  36. }