diff --git a/app/controller/api/Base.php b/app/controller/api/Base.php index 2ec29afc..f18f4f5a 100644 --- a/app/controller/api/Base.php +++ b/app/controller/api/Base.php @@ -8,7 +8,20 @@ // +---------------------------------------------------------------------- namespace app\controller\api; +use think\App; + class Base { + /** + * Request实例 + * @var \think\Request + */ + protected $request; + + /** + * 应用实例 + * @var \think\App + */ + protected $app; public $middleware = [ '\app\http\middleware\Validate', @@ -20,20 +33,27 @@ class Base { protected $data = ['data' => [], 'code' => 0, 'msg' => '']; - protected function initialize() { + /** + * 构造方法 + * @access public + * @param App $app 应用对象 + */ + public function __construct(App $app) { + $this->app = $app; + $this->request = $this->app->request; } protected function success($msg, $url = '') { $this->data['code'] = 1; - $this->data['msg'] = $msg; - $this->data['url'] = $url ? $url->__toString() : ''; + $this->data['msg'] = $msg; + $this->data['url'] = $url ? $url->__toString() : ''; return $this->data; } protected function error($msg, $url = '') { $this->data['code'] = 0; - $this->data['msg'] = $msg; - $this->data['url'] = $url ? $url->__toString() : ''; + $this->data['msg'] = $msg; + $this->data['url'] = $url ? $url->__toString() : ''; return $this->data; } } \ No newline at end of file diff --git a/app/controller/api/User.php b/app/controller/api/User.php index 91be2c7e..5e3e5dbb 100644 --- a/app/controller/api/User.php +++ b/app/controller/api/User.php @@ -26,6 +26,7 @@ class User extends Base { */ public function index(Member $user) { $list = $user->getUserList($this->request); + $this->data['code'] = 1; $this->data['data'] = $list; return $this->data; } @@ -37,6 +38,7 @@ class User extends Base { */ public function detail(Member $user) { $info = $user->getUserDetail($this->request); + $this->data['code'] = 1; $this->data['data'] = $info; return $this->data; } diff --git a/config/jwt.php b/config/jwt.php index 12901db9..98abbecc 100644 --- a/config/jwt.php +++ b/config/jwt.php @@ -7,7 +7,7 @@ return [ 'private_key' => env('JWT_PRIVATE_KEY'), 'password' => env('JWT_PASSWORD'), //JWT time to live - 'ttl' => env('JWT_TTL', 60), + 'ttl' => env('JWT_TTL', 86400), //Refresh time to live 'refresh_ttl' => env('JWT_REFRESH_TTL', 20160), //JWT hashing algorithm