Files
cunkebao_v3/Server/application/chukebao/controller/BaseController.php
Manus AI 99cbabbaaf fix: 修复生产 JWT 鉴权导致全站数据接口 500
getUserInfo 改从 Authorization 解析 token,避免 userInfo 写入 param 触发
variable type error;补齐 app\http\middleware\jwt 并统一 middleware 别名。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-25 05:27:07 +08:00

38 lines
914 B
PHP

<?php
namespace app\chukebao\controller;
use app\common\util\JwtUtil;
use think\Controller;
/**
* 基础控制器
*/
class BaseController extends Controller
{
/**
* 获取用户信息
*
* @param string $column
* @return mixed
* @throws \Exception
*/
protected function getUserInfo(?string $column = null)
{
static $userCache = null;
if ($userCache === null) {
$token = JwtUtil::getRequestToken();
$userCache = $token ? JwtUtil::verifyToken($token) : false;
if ($userCache === false) {
$userCache = $this->request->param('userInfo/a', null);
}
}
if (!$userCache) {
throw new \Exception('未授权访问,缺少有效的身份凭证', 401);
}
return ($column !== null && $column !== '') ? ($userCache[$column] ?? null) : $userCache;
}
}