When using the payment interface recently, it is often necessary to test the content of the callback parameters for subsequent processing
<?php
class study{
/**
* 递归生成目录
*/
public function RecursiveMkdir($path){
if (!file_exists($path)) {
$this->RecursiveMkdir(dirname($path));
@mkdir($path, 0777);
}
}
/**
* 把xml转换成数组
* @param [type] $xml [description]
* @return [arr] [description]
*/
private function xmlToArray($xml){
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
$val = json_decode(json_encode($xmlstring),true);
return $val;
}
public function notiy(){
//ROOT_PATH:根目录
define('ROOT_PATH',str_replace('\\','/',realpath(dirname(__FILE__).'/'))."/");
$data_path = ROOT_PATH.'/Data/wxpaylogs/'.date('Y-m-d')."/";
$this->RecursiveMkdir($data_path);
$file = $data_path.date('Y-m-d').'.txt';
$handl = fopen($file,'a');
$data = "
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>";
$xmlarr = $this->xmlToArray($data);
fwrite($handl,"Queryorder");
fwrite($handl,"call back:" . json_encode($xmlarr));
fwrite($handl,"开始查询:");
fclose($handl);
}
}
$res = new study;
$re = $res->notiy();
var_dump($re);