diff --git a/wchat/common/Help.php b/wchat/common/Help.php index a030378..385b10c 100644 --- a/wchat/common/Help.php +++ b/wchat/common/Help.php @@ -31,6 +31,32 @@ class Help extends Miniprogarampage * @return mixed */ public static function toArray($xml) + { + if (is_array($xml)) { + return $xml; + } + try { + $data = @simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); + if ($data !== false) { + return json_decode(json_encode($data), TRUE); + } + $data = json_decode($xml, TRUE); + } catch (\Exception $exception) { + $data = json_decode($xml, TRUE); + } finally { + if (is_array($data)) { + return $data; + } + return $xml; + } + } + + + /** + * @param $xml + * @return mixed + */ + public static function xmlToArray($xml) { if (is_array($xml)) { return $xml;