Skip to content

Commit

Permalink
fix restful
Browse files Browse the repository at this point in the history
  • Loading branch information
billge1205 committed Apr 29, 2021
1 parent 82214fd commit ebae071
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/business/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) ?: [];
}
}

0 comments on commit ebae071

Please sign in to comment.