123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace App\Services\Base;
- use App\Repositories\Eloquent\Base\AuthRepositoryEloquent;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Models\Base\Auth;
- use Illuminate\Http\Request;
- class AuthService
- {
- /**
- * @var AuthRepositoryEloquent
- */
- private $repository;
- /**
- * AuthService constructor.
- *
- * @param AuthRepositoryEloquent $authRepositoryEloquent
- */
- public function __construct(AuthRepositoryEloquent $authRepositoryEloquent)
- {
- $this->repository = $authRepositoryEloquent;
- }
- /**
- *
- * @param Request $request
- * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleCodeToAuth($appid, $openID, $type = 0)
- {
- $auth = Auth::query()->where([
- 'identifier' => $appid,
- 'type' => $type,
- 'credential' => $openID,
- ])->first();
- if ($auth) {
- return $auth;
- }
- $auth = $this->repository->create([
- 'identifier' => $appid,
- 'type' => $type,
- 'credential' => $openID,
- 'user_id' => 0,
- 'status' => ModelStatusEnum::OK,
- ]);
- return $auth;
- }
- /**
- * 刷新token
- * @return mixed|object
- */
- public function handleRefreshToken()
- {
- $token = auth()->refresh();
- return $token;
- }
- }
|