CashierHandler.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * +----------------------------------------------------------------------
  4. * | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  5. * +----------------------------------------------------------------------
  6. * | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  7. * +----------------------------------------------------------------------
  8. * | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  9. * +----------------------------------------------------------------------
  10. * | Author: CRMEB Team <admin@crmeb.com>
  11. * +----------------------------------------------------------------------
  12. */
  13. namespace app\webscoket\handler;
  14. use app\services\cashier\LoginServices;
  15. use app\webscoket\BaseHandler;
  16. use app\webscoket\Response;
  17. use crmeb\exceptions\AuthException;
  18. /**
  19. * Class CashierHandler
  20. * @package app\webscoket\handler
  21. */
  22. class CashierHandler extends BaseHandler
  23. {
  24. public function login(array $data, Response $response)
  25. {
  26. if (!isset($data['token']) || !$token = $data['token']) {
  27. return $response->fail('授权失败!');
  28. }
  29. try {
  30. /** @var LoginServices $services */
  31. $services = app()->make(LoginServices::class);
  32. $authInfo = $services->parseToken($token);
  33. } catch (AuthException $e) {
  34. return $response->fail($e->getMessage());
  35. }
  36. if (!$authInfo || !isset($authInfo['id'])) {
  37. return $response->fail('授权失败!');
  38. }
  39. return $response->success(['uid' => $authInfo['id']]);
  40. }
  41. }