* Date: 2019/6/19 * Time: 6:29 PM */ namespace app\common; use app\BaseController; use app\model\UserInfo; use think\App; abstract class ApiController extends BaseController { /** * @var UserInfo */ private $currentUserInfo; public function __construct(App $app) { parent::__construct($app); $this->initCurrentUserInfo(); } protected function initCurrentUserInfo() { $this->currentUserInfo = $this->request->user; } /** * 获取当前请求api的用户信息, * 前提为必须有参数open_id * @return UserInfo */ protected function getCurrentUserInfo() { if (empty($this->currentUserInfo)) { $this->initCurrentUserInfo(); } return $this->currentUserInfo; } }