SupplierHandler.php 1.7 KB

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