diff --git a/wchat/common/Help.php b/wchat/common/Help.php index 2905d30..a030378 100644 --- a/wchat/common/Help.php +++ b/wchat/common/Help.php @@ -35,26 +35,13 @@ class Help extends Miniprogarampage if (is_array($xml)) { return $xml; } + if (($data = @simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)) !== false) { + return json_decode(json_encode($data), TRUE); + } if (!is_null($json = json_decode($xml, TRUE))) { return $json; } - if (is_array($json)) { - return $json; - } - if (!static::isXml($xml)) { - return $xml; - } - $data = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); - if (is_array($data)) { - return $data; - } - return json_decode(json_encode($data), TRUE); - } - - - public static function isXml($body) - { - return preg_match('/^<[a-zA-Z_]+>(.*?)?<\/[a-zA-Z_]+>$/', $body); + return $xml; } /** diff --git a/wchat/common/HttpClient.php b/wchat/common/HttpClient.php index eeecf6f..5938a45 100644 --- a/wchat/common/HttpClient.php +++ b/wchat/common/HttpClient.php @@ -478,9 +478,6 @@ class HttpClient $data = new Result(['code' => 500, 'message' => curl_error($ch)]); } else { [$header, $body, $status] = $this->explode($output); - - var_dump($header, $body, $status);exit; - if ($status != 200) { $data = new Result(['code' => 500, 'message' => $body, 'header' => $header]); } else { @@ -542,11 +539,14 @@ class HttpClient $type = $data['content-type']; if (strpos($type, 'text/html') !== false) { return $body; - } else if (strpos($type, 'json') !== false) { + } + if (strpos($type, 'json') !== false) { return Help::toArray($body); - } else if (strpos($type, 'xml') !== false) { + } + if (strpos($type, 'xml') !== false) { return Help::toArray($body); - } else if (strpos($type, 'plain') !== false) { + } + if (strpos($type, 'plain') !== false) { return Help::toArray($body); } return $body;