// +---------------------------------------------------------------------- namespace crmeb\basic; use think\App; use app\Request; use think\Response; /** * 控制器基类 * Class BaseController * @package crmeb\basic * @property Request $request */ class BaseController { /** * @var App */ protected App $app; /** * @var Request */ protected Request $request; /** * BaseController constructor. * @param App $app */ public function __construct(App $app) { $this->app = $app; $this->request = $this->app->request; $this->initialize(); } /** * 初始化(供子类覆盖) */ protected function initialize() { } /** * 返回成功 JSON 响应 * @param string|array $message * @param array $data * @return Response */ public function success($message = 'ok', array $data = []): Response { if (is_array($message)) { $data = $message; $message = 'ok'; } return app('json')->success($message, $data ?: null); } /** * 返回失败 JSON 响应 * @param string|array $message * @param array $data * @return Response */ public function fail($message = 'fail', array $data = []): Response { if (is_array($message)) { $data = $message; $message = 'fail'; } return app('json')->fail($message, $data ?: null); } // ------------------------------------------------------------------------- // 授权相关方法 — 全部 stub,绕过商业授权检查 // ------------------------------------------------------------------------- /** * 检查授权(stub — 直接返回成功) * @return Response */ protected function checkAuthDecrypt(): Response { return $this->success('ok'); } /** * 获取授权信息(stub) * @return Response */ protected function getAuth(): Response { return $this->success(['auth' => true, 'auth_code' => 'authorized']); } /** * 查询版权(stub) */ protected function __6j3nfcwmWqrsDx8F0MjZGeQyWvLsqeFXww() { // stub: no-op } /** * 保存版权(stub) * @param mixed $copyright * @param mixed $copyrightImg */ protected function __qsG71NREI01vix2OkjH($copyright = null, $copyrightImg = null) { // stub: no-op } /** * 获取版权内容(stub) * @return array */ protected function __z6uxyJQ4xYa5ee1mx5(): array { return ['copyrightContext' => '', 'copyrightImage' => '']; } /** * 获取授权 token(stub) * @param mixed $phone * @return string */ protected function __k0dUcnKjRUs9lfEllqO9J($phone = null): string { return ''; } }