config change & bug fix

This commit is contained in:
候学杰 2019-01-31 16:27:56 +08:00
parent 9ef81c53e3
commit 13637d201f
2 changed files with 18 additions and 3 deletions

View File

@ -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) { if (!$name) {
$name = env('APP_NAME'); $name = env('APP_NAME');
} }

View File

@ -67,7 +67,8 @@ class PdAuthServiceProvider extends ServiceProvider
//添加获取token的路由 //添加获取token的路由
$this->app['router']->get('auth/token.json', function (Request $request) { $this->app['router']->get('auth/token.json', function (Request $request) {
$code = $request->input('pd_code'); $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'])); $cookie = new Cookie(Authenticate::CookieName, $token['access_token'], strtotime($token['expired_at']));
return response()->json([ return response()->json([
'code' => 0, 'code' => 0,