feat: 实现后台请求兼容接口的模式

This commit is contained in:
augushong
2025-03-10 18:06:51 +08:00
parent afd5f6b1dd
commit 7f92b0e07a
6 changed files with 119 additions and 9 deletions

View File

@@ -2,8 +2,43 @@
namespace base\common\provider;
use think\facade\Config;
// 应用请求对象类
class RequestBase extends \think\Request
{
protected $filter = [];
/**
* 当前是否JSON请求
* @return bool
*/
public function isJson(): bool
{
$acceptType = $this->type();
$is_json = str_contains($acceptType, 'json');
if (!$is_json) {
return false;
}
if (!Config::get('app.auto_parse_api')) {
return true;
}
if ($this->has('get_page_data')) {
return false;
}
return true;
}
/**
* 仅通过实际请求参数判断请求
*
* @return bool
*/
public function isJsonPure()
{
return parent::isJson();
}
}