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,