From ebae07175d6698565ca64ffe6383aa11a97c85fa Mon Sep 17 00:00:00 2001 From: billge1205 Date: Thu, 29 Apr 2021 11:05:49 +0800 Subject: [PATCH] fix restful --- lib/business/Request.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/business/Request.php b/lib/business/Request.php index 73d9fdb..bbc0f7c 100644 --- a/lib/business/Request.php +++ b/lib/business/Request.php @@ -91,8 +91,14 @@ private function __construct($module, $method=null) */ public function setRestApi() { - parse_str(file_get_contents('php://input'), $this->params); + if (strstr($this->getContentType(), '/json')) { + $this->buildJson(); + $this->params = $this->jsons; + } else { + parse_str(file_get_contents('php://input'), $this->params); + } $this->params = array_merge($this->params, $this->gets); +// var_dump($this->params ); exit(); } /** @@ -569,7 +575,7 @@ public function get($key, $default=null) public function json($key, $default=null) { if ($this->jsons === NULL){ - $this->jsons = json_decode($this->getRowPost(), true) ?: []; + $this->buildJson(); } return isset($this->jsons[$key]) ? $this->jsons[$key] : $default; } @@ -578,7 +584,7 @@ public function json($key, $default=null) * 获取post数据 * @return string */ - public function getRowPost(){ - return file_get_contents('php://input'); + public function buildJson(){ + $this->jsons = json_decode(file_get_contents('php://input'), true) ?: []; } } \ No newline at end of file