Index.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\admin\controller\shopro\chat;
  3. use app\admin\controller\shopro\Common;
  4. use app\admin\model\shopro\chat\CustomerService;
  5. class Index extends Common
  6. {
  7. protected $noNeedRight = ['init'];
  8. /**
  9. * socket 初始化
  10. *
  11. * @return void
  12. */
  13. public function init()
  14. {
  15. // 当前管理员
  16. $admin = auth_admin();
  17. $token = $this->getUnifiedToken('admin:' . $admin['id']); // 统一验证 token
  18. // 客服配置
  19. $chatSystem = sheep_config('chat.system');
  20. // 初始化 socket ssl 类型, 默认 cert
  21. $ssl = $chatSystem['ssl'] ?? 'none';
  22. $chat_domain = ($ssl == 'none' ? 'http://' : 'https://') . request()->host(true) . ($ssl == 'reverse_proxy' ? '' : (':' . $chatSystem['port'])) . '/chat';
  23. $data = [
  24. 'token' => $token,
  25. 'chat_domain' => $chat_domain,
  26. 'default_rooms' => CustomerService::defaultRooms()
  27. ];
  28. $this->success('获取成功', null, $data);
  29. }
  30. }