public function xx(){ $xml = '<xml><appid><![CDATA[xxxxxxxxxxxxx]]></appid> <bank_type><![CDATA[CFT]]></bank_type> <cash_fee><![CDATA[3500]]></cash_fee> <fee_type><![CDATA[CNY]]></fee_type> <is_subscribe><![CDATA[N]]></is_subscribe> <mch_id><![CDATA[xxxxxxxxxxxx]]></mch_id> <nonce_str><![CDATA[xxxxxxxxxxxxx]]></nonce_str> <openid><![CDATA[xxxxxxxxxxxxxxxxxxxxxxxxxx]]></openid> <out_trade_no><![CDATA[111400xxxxxxxxxxxxxx]]></out_trade_no> <result_code><![CDATA[SUCCESS]]></result_code> <return_code><![CDATA[SUCCESS]]></return_code> <sign><![CDATA[DBBB36A12ECE7E3Cxxxxxxxxxxxxxxxx]]></sign> <time_end><![CDATA[20191114005240]]></time_end> <total_fee>3500</total_fee> <trade_type><![CDATA[JSAPI]]></trade_type> <transaction_id><![CDATA[42000004xxxxxxxxxxxxxxxxxxxx3]]></transaction_id> </xml>'; $data = $this->FromXml($xml); dump($data); } public function FromXml($xml) { if(!$xml){ throw new WxPayException("xml数据异常!"); } //将XML转为array //禁止引用外部xml实体 libxml_disable_entity_loader(true); $this->values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); return $this->values; }
<pre>array(16) {
["appid"] => string(18) "xxxxxxxxxxxxxxxxxxx"
["bank_type"] => string(3) "CFT"
["cash_fee"] => string(4) "3500"
["fee_type"] => string(3) "CNY"
["is_subscribe"] => string(1) "N"
["mch_id"] => string(10) "xxxxxxxxxxxxx"
["nonce_str"] => string(16) "Oec5xxxxxxxxxxxxx"
["openid"] => string(28) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
["out_trade_no"] => string(18) "111400522494411933"
["result_code"] => string(7) "SUCCESS"
["return_code"] => string(7) "SUCCESS"
["sign"] => string(32) "DBBB36A12ECxxxxxxxxxxxxxxxxxxxxxxxxxx"
["time_end"] => string(14) "20191114005240"
["total_fee"] => string(4) "3500"
["trade_type"] => string(5) "JSAPI"
["transaction_id"] => string(28) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
</pre>