From f8bd3ba20ac91b524cdf2e3af7797266b9e6aee8 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Thu, 10 Aug 2023 16:55:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=8E=B7=E5=8F=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=A2=9E=E5=8A=A0token=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/application/api/controller/library/Pass.php | 13 +++++++++++++ source/application/api/controller/pass/Passcc.php | 4 ++++ source/application/api/controller/xtool/Token.php | 13 +++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 source/application/api/controller/xtool/Token.php diff --git a/source/application/api/controller/library/Pass.php b/source/application/api/controller/library/Pass.php index 6c34190..72d4483 100644 --- a/source/application/api/controller/library/Pass.php +++ b/source/application/api/controller/library/Pass.php @@ -3,13 +3,22 @@ namespace app\api\controller\library; use app\api\controller\Controller; use app\common\dm\Dm; +use app\common\exception\BaseException; use app\common\logic\PassFlow; +use think\Session; class Pass extends Controller { protected $url = 'http://balib.cn:8999'; + public function requestValiDate() + { + $token = $this->request->param('token'); + if (empty($token)) throw new BaseException(['msg' => '缺少token参数']); + if ($token != Session::pull('__token__')) throw new BaseException(['msg' => 'token验证失败']); + } + /** * 图书管数据接口 * @return array @@ -19,6 +28,7 @@ class Pass extends Controller */ public function allFlowTrends() { + $this->requestValiDate(); $data = PassFlow::allFlowTrends(); return $this->renderSuccess(compact('data')); } @@ -204,6 +214,7 @@ class Pass extends Controller */ public function getLibraryHours24List() { + $this->requestValiDate(); $data = PassFlow::getLibraryHours24List(); return $this->renderSuccess(compact('data')); } @@ -217,6 +228,7 @@ class Pass extends Controller */ public function getLibraryGroupHoursList() { + $this->requestValiDate(); $data = PassFlow::getLibraryGroupHoursList(); return $this->renderSuccess(compact('data')); } @@ -264,6 +276,7 @@ class Pass extends Controller */ public function getLibraryLeaseData() { + $this->requestValiDate(); $data = PassFlow::getLibraryLeaseData(); return $this->renderSuccess(compact('data')); } diff --git a/source/application/api/controller/pass/Passcc.php b/source/application/api/controller/pass/Passcc.php index b68eb14..f243347 100644 --- a/source/application/api/controller/pass/Passcc.php +++ b/source/application/api/controller/pass/Passcc.php @@ -9,6 +9,7 @@ use app\common\exception\BaseException; use app\common\logic\PassFlow; use app\common\model\Pass; use think\Db; +use think\Session; class Passcc extends Controller { @@ -19,6 +20,9 @@ class Passcc extends Controller public function _initialize() { + $token = $this->request->param('token'); + if (empty($token)) throw new BaseException(['msg' => '缺少token参数']); + if ($token != Session::pull('__token__')) throw new BaseException(['msg' => 'token验证失败']); $type = $this->request->param('type'); if (!empty($type) || is_numeric($type)) { if (!preg_match('/^[1-2]$/',$type)) throw new BaseException(['msg' => 'type字段参数错误']); diff --git a/source/application/api/controller/xtool/Token.php b/source/application/api/controller/xtool/Token.php new file mode 100644 index 0000000..02357af --- /dev/null +++ b/source/application/api/controller/xtool/Token.php @@ -0,0 +1,13 @@ +renderSuccess(['token' => $this->request->token()]); + } +} \ No newline at end of file