authRepository = $authRepositoryEloquent; $this->adminRepository = $adminRepositoryEloquent; } /** * * @param Request $request * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function handleMiniProgramLogin(Request $request) { $code = $request->code; $appid = $request->appid; $type = (int)$request->get('type', 0); list($session_key, $openID, $unionid) = $this->miniProgramByCodeGetOpenId($appid, $code, $type); $auth = Auth::query()->where([ 'identifier' => $appid, 'type' => $type, 'credential' => $openID, ])->first(); if ($auth) { Cache::put("cache:service:auth:session_key:api:" . $auth['id'], $session_key, Carbon::now()->addDay()); return $auth; } $auth = $this->authRepository->create([ 'identifier' => $appid, 'type' => $type, 'credential' => $openID, 'user_id' => 0, ]); Cache::put("cache:service:auth:session_key:api:" . $auth['id'], $session_key, Carbon::now()->addDay()); return $auth; } /** * * @param Request $request * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function handleIsMiniProgramLogin(Request $request) { $code = $request->code; $appid = $request->appid; $type = (int)$request->get('type', 0); list($session_key, $openID, $unionid) = $this->miniProgramByCodeGetOpenId($appid, $code, $type); $auth = Auth::query()->where([ 'identifier' => $appid, 'type' => $type, 'credential' => $openID, ])->first(); if ($auth) { Cache::put("cache:service:auth:session_key:api:" . $auth['id'], $session_key, Carbon::now()->addDay()); return $auth; } return false; } /** * 刷新token * @return mixed|object */ public function handleRefreshToken() { $token = auth()->refresh(); return $token; } }