From 9bf240e4fe9396714b1bbd5fb4e93d4104570bec Mon Sep 17 00:00:00 2001 From: devil_gong Date: Wed, 16 Jan 2019 11:46:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=AD=E9=97=B4=E4=BB=B6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Common.php | 22 -------- application/api/controller/Common.php | 22 -------- .../http/middleware/AccessInAppCheck.php | 53 +++++++++++++++++++ .../middleware/SystemEnvCheck.php} | 34 ++++++++++-- application/index/controller/Common.php | 22 -------- application/middleware.php | 20 +++++++ 6 files changed, 102 insertions(+), 71 deletions(-) create mode 100644 application/http/middleware/AccessInAppCheck.php rename application/{service/OtherService.php => http/middleware/SystemEnvCheck.php} (60%) create mode 100644 application/middleware.php diff --git a/application/admin/controller/Common.php b/application/admin/controller/Common.php index b6569eac1..6dbd4e079 100755 --- a/application/admin/controller/Common.php +++ b/application/admin/controller/Common.php @@ -13,7 +13,6 @@ namespace app\admin\controller; use think\Controller; use app\service\AdminPowerService; use app\service\ConfigService; -use app\service\OtherService; /** * 管理员公共控制器 @@ -60,29 +59,8 @@ class Common extends Controller // 视图初始化 $this->ViewInit(); - - // 其它处理 - $this->OtherHandle(); } - /** - * 其它处理 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-12-07 - * @desc description - */ - private function OtherHandle() - { - // 环境检查 - $ret = OtherService::EnvironmentCheck(); - if($ret['code'] != 0) - { - exit(json_encode($ret)); - } - } - /** * 系统初始化 * @author Devil diff --git a/application/api/controller/Common.php b/application/api/controller/Common.php index d9339aa51..f1b4e4579 100755 --- a/application/api/controller/Common.php +++ b/application/api/controller/Common.php @@ -13,7 +13,6 @@ namespace app\api\controller; use think\Controller; use app\service\ConfigService; use app\service\UserService; -use app\service\OtherService; /** * 接口公共控制器 @@ -61,27 +60,6 @@ class Common extends Controller // 公共数据初始化 $this->CommonInit(); - - // 其它处理 - $this->OtherHandle(); - } - - /** - * 其它处理 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-12-07 - * @desc description - */ - private function OtherHandle() - { - // 环境检查 - $ret = OtherService::EnvironmentCheck(); - if($ret['code'] != 0) - { - exit(json_encode($ret)); - } } /** diff --git a/application/http/middleware/AccessInAppCheck.php b/application/http/middleware/AccessInAppCheck.php new file mode 100644 index 000000000..ff8056252 --- /dev/null +++ b/application/http/middleware/AccessInAppCheck.php @@ -0,0 +1,53 @@ +header('user-agent'))) + { + $request->in_app = 'weixin'; + + // 是否支付宝 + } else if (preg_match('~alipay~i', $request->header('user-agent'))) + { + $request->in_app = 'alipay'; + + // 默认app + } else { + $request->in_app = 'app'; + } + + return $next($request); + } +} +?> \ No newline at end of file diff --git a/application/service/OtherService.php b/application/http/middleware/SystemEnvCheck.php similarity index 60% rename from application/service/OtherService.php rename to application/http/middleware/SystemEnvCheck.php index 3d2ce47be..420cd19c9 100644 --- a/application/service/OtherService.php +++ b/application/http/middleware/SystemEnvCheck.php @@ -8,17 +8,40 @@ // +---------------------------------------------------------------------- // | Author: Devil // +---------------------------------------------------------------------- -namespace app\service; +namespace app\http\middleware; /** - * 其它处理服务层 + * 系统环境检查 * @author Devil * @blog http://gong.gg/ * @version 0.0.1 * @datetime 2016-12-01T21:51:08+0800 */ -class OtherService +class SystemEnvCheck { + /** + * 入口 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2019-01-16 + * @desc description + * @param [object] $request [请求对象] + * @param \Closure $next [闭包] + * @return [object] [请求对象] + */ + public function handle($request, \Closure $next) + { + // 环境检查 + $ret = $this->EnvironmentCheck(); + if($ret['code'] != 0) + { + exit(json_encode($ret)); + } + + return $next($request); + } + /** * 环境校验 * @author Devil @@ -27,13 +50,14 @@ class OtherService * @date 2018-12-07 * @desc description */ - public static function EnvironmentCheck() + public function EnvironmentCheck() { if(IS_AJAX) { // 请求参数数量校验是否超出php.ini限制 $max_input_vars = intval(ini_get('max_input_vars'))-5; - if(count(input('post.')) >= $max_input_vars) + $params_counbt = count(input('post.')); + if($params_counbt >= $max_input_vars) { return DataReturn('请求参数数量已超出php.ini限制[max_input_vars]', -1000); } diff --git a/application/index/controller/Common.php b/application/index/controller/Common.php index d88d17d89..bf575f593 100755 --- a/application/index/controller/Common.php +++ b/application/index/controller/Common.php @@ -18,7 +18,6 @@ use app\service\MessageService; use app\service\SearchService; use app\service\ConfigService; use app\service\LinkService; -use app\service\OtherService; /** * 前端公共控制器 @@ -65,27 +64,6 @@ class Common extends Controller // 视图初始化 $this->ViewInit(); - - // 其它处理 - $this->OtherHandle(); - } - - /** - * 其它处理 - * @author Devil - * @blog http://gong.gg/ - * @version 1.0.0 - * @date 2018-12-07 - * @desc description - */ - private function OtherHandle() - { - // 环境检查 - $ret = OtherService::EnvironmentCheck(); - if($ret['code'] != 0) - { - exit(json_encode($ret)); - } } /** diff --git a/application/middleware.php b/application/middleware.php new file mode 100644 index 000000000..227c61516 --- /dev/null +++ b/application/middleware.php @@ -0,0 +1,20 @@ + \ No newline at end of file -- GitLab