mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 22:55:36 +00:00
feat:增加一个获取用户鉴权 token 的公共函数
This commit is contained in:
parent
ca04172291
commit
c46e15bc13
@ -402,3 +402,30 @@ if (!function_exists('get_upload_config')) {
|
|||||||
return array_merge($upload, $uploadConfig);
|
return array_merge($upload, $uploadConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('get_auth_token')) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取鉴权 token
|
||||||
|
* @param array $names
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function get_auth_token(array $names = ['ba', 'token']): string
|
||||||
|
{
|
||||||
|
$separators = [
|
||||||
|
'header' => ['', '-'], // batoken、ba-token【ba_token 不在 header 的接受列表内因为兼容性不高,改用 http_ba_token】
|
||||||
|
'param' => ['', '-', '_'], // batoken、ba-token、ba_token
|
||||||
|
'server' => ['_'], // http_ba_token
|
||||||
|
];
|
||||||
|
|
||||||
|
$tokens = [];
|
||||||
|
$request = request();
|
||||||
|
foreach ($separators as $fun => $sps) {
|
||||||
|
foreach ($sps as $sp) {
|
||||||
|
$tokens[] = $request->$fun(($fun == 'server' ? 'http_' : '') . implode($sp, $names));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$tokens = array_filter($tokens);
|
||||||
|
return array_values($tokens)[0] ?? '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user