api/app/common/ApiController.php
2019-06-22 22:03:22 +08:00

45 lines
885 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Created by PhpStorm.
* User: yancheng<cheng@love.xiaoyan.me>
* 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;
}
}