From 13637d201f259f3bdbebb8c4a1d7234e58d96a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=99=E5=AD=A6=E6=9D=B0?= Date: Thu, 31 Jan 2019 16:27:56 +0800 Subject: [PATCH] config change & bug fix --- src/Auth.php | 18 ++++++++++++++++-- src/PdAuthServiceProvider.php | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index 3de0edc..c2576ff 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -54,11 +54,25 @@ class Auth ], ]); } - $this->choose(); } - public function choose($name = null) + protected function matchConfigById($id) { + foreach ($this->config['apps'] as $name => $app) { + if ($app['id'] == $id) { + return $name; + } + } + return null; + } + + public function choose($name = null, $id = null) + { + if ($id) { + $name = $this->matchConfigByid($id); + $this->choose($name); + } + if (!$name) { $name = env('APP_NAME'); } diff --git a/src/PdAuthServiceProvider.php b/src/PdAuthServiceProvider.php index 5464b0e..99dd353 100644 --- a/src/PdAuthServiceProvider.php +++ b/src/PdAuthServiceProvider.php @@ -67,7 +67,8 @@ class PdAuthServiceProvider extends ServiceProvider //添加获取token的路由 $this->app['router']->get('auth/token.json', function (Request $request) { $code = $request->input('pd_code'); - $token = app('pd.auth')->getAccessToken($code); + $id = $request->input('app_id'); + $token = app('pd.auth')->choose(null, $id)->getAccessToken($code); $cookie = new Cookie(Authenticate::CookieName, $token['access_token'], strtotime($token['expired_at'])); return response()->json([ 'code' => 0,