AuthService.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Services\Base;
  3. use App\Repositories\Eloquent\Base\AuthRepositoryEloquent;
  4. use App\Repositories\Enums\ModelStatusEnum;
  5. use App\Repositories\Models\Base\Auth;
  6. use Illuminate\Http\Request;
  7. class AuthService
  8. {
  9. /**
  10. * @var AuthRepositoryEloquent
  11. */
  12. private $repository;
  13. /**
  14. * AuthService constructor.
  15. *
  16. * @param AuthRepositoryEloquent $authRepositoryEloquent
  17. */
  18. public function __construct(AuthRepositoryEloquent $authRepositoryEloquent)
  19. {
  20. $this->repository = $authRepositoryEloquent;
  21. }
  22. /**
  23. *
  24. * @param Request $request
  25. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed
  26. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  27. * @throws \Prettus\Validator\Exceptions\ValidatorException
  28. */
  29. public function handleCodeToAuth($appid, $openID, $type = 0)
  30. {
  31. $auth = Auth::query()->where([
  32. 'identifier' => $appid,
  33. 'type' => $type,
  34. 'credential' => $openID,
  35. ])->first();
  36. if ($auth) {
  37. return $auth;
  38. }
  39. $auth = $this->repository->create([
  40. 'identifier' => $appid,
  41. 'type' => $type,
  42. 'credential' => $openID,
  43. 'user_id' => 0,
  44. 'status' => ModelStatusEnum::OK,
  45. ]);
  46. return $auth;
  47. }
  48. /**
  49. * 刷新token
  50. * @return mixed|object
  51. */
  52. public function handleRefreshToken()
  53. {
  54. $token = auth()->refresh();
  55. return $token;
  56. }
  57. }