iYuuChannel.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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)->post('https://iyuu.cn/'.sysConfig('iYuu_token').'.send?title='.urlencode($message['title']).'&desp='.urlencode($message['content']));
  13. // 发送成功
  14. if ($response->ok()) {
  15. $ret = $response->json();
  16. if (! $ret['errcode']) {
  17. Helpers::addNotificationLog($message['title'], $message['content'], 8);
  18. return $ret;
  19. }
  20. // 发送失败
  21. Helpers::addNotificationLog($message['title'], $message['content'], 8, -1, $ret ? $ret['errmsg'] : trans('common.status.unknown'));
  22. return false;
  23. }
  24. // 发送错误
  25. Log::critical(trans('notification.error', ['channel' => trans('admin.system.notification.channel.iyuu'), 'reason' => var_export($response, true)]));
  26. return false;
  27. }
  28. }