file_get_contents("php://input");
https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7
public function xmlToArray($xml=‘‘){
$temp = json_encode(simplexml_load_string($xml, ‘SimpleXMLElement‘, LIBXML_NOCDATA));
return json_decode($temp, true);
}
$testxml = file_get_contents("php://input");
$jsonxml = json_encode(simplexml_load_string($testxml, ‘SimpleXMLElement‘, LIBXML_NOCDATA));
$result = json_decode($jsonxml, true);//转成数组,
echo ‘<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>‘;
function arrayToXml($arr) {
$xml = "<xml>";
foreach ($arr as $key => $val){
if (is_numeric($val)){
$xml.="<$key>$val</$key>";
}
else
$xml.="<$key><![CDATA[$val]]></$key>";
}
$xml.="</xml>";
return $xml;
}
原文:https://www.cnblogs.com/xc-study/p/14731665.html