WorkermanHandle.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace crmeb\services\workerman;
  3. use think\facade\Middleware;
  4. use think\facade\Session;
  5. use Workerman\Connection\TcpConnection;
  6. class WorkermanHandle
  7. {
  8. protected $service;
  9. public function __construct(WorkermanService &$service)
  10. {
  11. $this->service = &$service;
  12. }
  13. public function login(TcpConnection &$connection, array $res, Response $response)
  14. {
  15. if (!isset($res['data']) || !$sessionId = $res['data']) {
  16. return $response->close([
  17. 'msg' => '授权失败!'
  18. ]);
  19. }
  20. $session = app('session', [], true);
  21. $session->setId($sessionId);
  22. $session->init();
  23. if (!$session->has('adminId') || !$session->has('adminInfo')) {
  24. return $response->close([
  25. 'msg' => '授权失败!'
  26. ]);
  27. }
  28. $connection->adminInfo = $session->get('adminInfo');
  29. $connection->sessionId = $sessionId;
  30. $this->service->setUser($connection);
  31. return $response->success();
  32. }
  33. }