From 46bd26318675314ca7447cae16635af152744ce9 Mon Sep 17 00:00:00 2001 From: Karson Date: Mon, 31 Aug 2020 14:28:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EAPI=E5=9F=BA=E7=B1=BBToken?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=20=E4=BC=98=E5=8C=96=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E5=8D=A1=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/Crud/stubs/html/heading-html.stub | 4 ++-- application/common/controller/Api.php | 17 +++++++++++++++++ application/common/controller/Backend.php | 2 +- application/common/controller/Frontend.php | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/application/admin/command/Crud/stubs/html/heading-html.stub b/application/admin/command/Crud/stubs/html/heading-html.stub index 354f6ae7..9392c802 100644 --- a/application/admin/command/Crud/stubs/html/heading-html.stub +++ b/application/admin/command/Crud/stubs/html/heading-html.stub @@ -2,9 +2,9 @@
{:build_heading(null,FALSE)}
diff --git a/application/common/controller/Api.php b/application/common/controller/Api.php index 2867a5d9..54cbcc0a 100644 --- a/application/common/controller/Api.php +++ b/application/common/controller/Api.php @@ -12,6 +12,7 @@ use think\Loader; use think\Request; use think\Response; use think\Route; +use think\Validate; /** * API控制器基类 @@ -304,4 +305,20 @@ class Api return true; } + + /** + * 刷新Token + */ + protected function token() + { + $token = $this->request->param('__token__'); + + //验证Token + if (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) { + $this->error(__('Token verification error'), ['__token__' => $this->request->token()]); + } + + //刷新Token + $this->request->token(); + } } diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php index 6e3b4da2..2f9ecf77 100644 --- a/application/common/controller/Backend.php +++ b/application/common/controller/Backend.php @@ -531,7 +531,7 @@ class Backend extends Controller */ protected function token() { - $token = $this->request->post('__token__'); + $token = $this->request->param('__token__'); //验证Token if (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) { diff --git a/application/common/controller/Frontend.php b/application/common/controller/Frontend.php index 593e360c..f76fda0f 100644 --- a/application/common/controller/Frontend.php +++ b/application/common/controller/Frontend.php @@ -142,7 +142,7 @@ class Frontend extends Controller */ protected function token() { - $token = $this->request->post('__token__'); + $token = $this->request->param('__token__'); //验证Token if (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) {