应用初始化新增中间件处理

This commit is contained in:
devil_gong 2019-01-16 11:46:45 +08:00
parent fca4b184b2
commit 9bf240e4fe
6 changed files with 102 additions and 71 deletions

View File

@ -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

View File

@ -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));
}
}
/**

View File

@ -0,0 +1,53 @@
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2018 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\http\middleware;
/**
* 访问环境检查
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class AccessInAppCheck
{
/**
* 入口
* @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)
{
// 是否微信
if(preg_match('~micromessenger~i', $request->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);
}
}
?>

View File

@ -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);
}

View File

@ -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));
}
}
/**

View File

@ -0,0 +1,20 @@
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2018 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
// 中间件配置
return [
// 系统环境检查
app\http\middleware\SystemEnvCheck::class,
// 访问环境检查
app\http\middleware\AccessInAppCheck::class,
];
?>