生成日志文件
<?php
/**
* 接收历史,名片数据推送解析
* */
$post = serialize($_POST);
$get = serialize($_GET);
// 获取POST数据
$result = file_get_contents ( "php://input" );
$ttt1 = fopen('ks_datas'.date('Y-m').'.txt', 'a+');//记录日志
fwrite($ttt1, "\r\n");
fwrite($ttt1, "\t" . date('Y-m-d H:i:s')." \r\n");
// $result = '%7B%22recId%22%3A1118848177%2C%22visitorId%22%3A%229c4df41cadf04d3fa80ab72a486f61ac%22%2C%22visitorName%22%3A%22%E7%A6%8F%E5%BB%BA%E5%8E%A6%E9%97%A8%7Ckuaishang%7C%E9%BB%98%E8%AE%A4%E4%BB%A3%E7%A0%81%22%2C%22curEnterTime%22%3A%222017-08-10+14%3A29%3A22%22%2C%22curStayTime%22%3A1634%2C%22sourceIp%22%3A%2261.131.78.82%22%2C%22sourceProvince%22%3A%22%E7%A6%8F%E5%BB%BA%E5%8E%A6%E9%97%A8%22%2C%22sourceIpInfo%22%3A%22%E7%94%B5%E4%BF%A1%22%2C%22requestType%22%3A%22rt_v%22%2C%22endType%22%3A%22et_d_t%22%2C%22diaStartTime%22%3A%222017-08-10+14%3A29%3A45%22%2C%22diaEndTime%22%3A%222017-08-10+14%3A56%3A36%22%2C%22terminalType%22%3A%22tt_mb%22%2C%22visitorSendNum%22%3A4%2C%22csSendNum%22%3A2%2C%22sourceUrl%22%3A%22%22%2C%22sourceType%22%3A%22%E7%9B%B4%E6%8E%A5%E8%BE%93%E5%85%A5%22%2C%22searchEngine%22%3A%22%22%2C%22keyword%22%3A%22%22%2C%22firstCsId%22%3A%22%E8%8A%92%E6%9E%9C%5B%E8%8A%92%E6%9E%9Cmango%E8%8A%92%E6%9E%9C%5D%22%2C%22joinCsIds%22%3A%22%E8%8A%92%E6%9E%9C%5B%E8%8A%92%E6%9E%9Cmango%E8%8A%92%E6%9E%9C%5D%22%2C%22dialogType%22%3A%22dt_d_o%22%2C%22firstVisitTime%22%3A%222017-07-27+15%3A33%3A28%22%2C%22preVisitTime%22%3A%222017-08-03+11%3A47%3A27%22%2C%22totalVisitTime%22%3A6%2C%22diaPage%22%3A%22%22%2C%22curFirstViewPage%22%3A%22%22%2C%22curVisitorPages%22%3A0%2C%22preVisitPages%22%3A1%2C%22operatingSystem%22%3A%22iPhone%22%2C%22browser%22%3A%22Safari+5.0.2%22%2C%22info%22%3A%22%22%2C%22siteName%22%3A%22kuaishang.com.cn%22%2C%22siteId%22%3A55851%2C%22dialogs%22%3A%5B%7B%22addTime%22%3A%222017-08-10+14%3A36%3A34%22%2C%22dialogId%22%3A%22%22%2C%22id%22%3A946170412%2C%22recContent%22%3A%2244%22%2C%22recId%22%3A1118848177%2C%22recType%22%3A1%2C%22sender%22%3A%22%E7%A6%8F%E5%BB%BA%E5%8E%A6%E9%97%A8%7Ckuaishang%7C%E9%BB%98%E8%AE%A4%E4%BB%A3%E7%A0%81%22%7D%2C%7B%22addTime%22%3A%222017-08-10+14%3A30%3A42%22%2C%22dialogId%22%3A%22%22%2C%22id%22%3A946163855%2C%22recContent%22%3A%223%22%2C%22recId%22%3A1118848177%2C%22recType%22%3A1%2C%22sender%22%3A%22%E7%A6%8F%E5%BB%BA%E5%8E%A6%E9%97%A8%7Ckuaishang%7C%E9%BB%98%E8%AE%A4%E4%BB%A3%E7%A0%81%22%7D%2C%7B%22addTime%22%3A%222017-08-10+14%3A30%3A07%22%2C%22dialogId%22%3A%22%22%2C%22id%22%3A946163100%2C%22recContent%22%3A%222%22%2C%22recId%22%3A1118848177%2C%22recType%22%3A1%2C%22sender%22%3A%22%E7%A6%8F%E5%BB%BA%E5%8E%A6%E9%97%A8%7Ckuaishang%7C%E9%BB%98%E8%AE%A4%E4%BB%A3%E7%A0%81%22%7D%2C%7B%22addTime%22%3A%222017-08-10+14%3A30%3A01%22%2C%22dialogId%22%3A%22%22%2C%22id%22%3A946163006%2C%22recContent%22%3A%221%22%2C%22recId%22%3A1118848177%2C%22recType%22%3A1%2C%22sender%22%3A%22%E7%A6%8F%E5%BB%BA%E5%8E%A6%E9%97%A8%7Ckuaishang%7C%E9%BB%98%E8%AE%A4%E4%BB%A3%E7%A0%81%22%7D%2C%7B%22addTime%22%3A%222017-08-10+14%3A29%3A51%22%2C%22dialogId%22%3A%22%22%2C%22id%22%3A946162855%2C%22recContent%22%3A%22q%22%2C%22recId%22%3A1118848177%2C%22recType%22%3A2%2C%22sender%22%3A%22%E8%8A%92%E6%9E%9Cmango%E8%8A%92%E6%9E%9C%22%7D%2C%7B%22addTime%22%3A%222017-08-10+14%3A29%3A45%22%2C%22dialogId%22%3A%22%22%2C%22id%22%3A946162767%2C%22recContent%22%3A%22%E4%BD%A0%E5%A5%BD%EF%BC%8C%E8%AF%B7%E9%97%AE%E6%9C%89%E4%BB%80%E4%B9%88%E5%8F%AF%E4%BB%A5%E5%B8%AE%E5%8A%A9%E6%82%A8%E7%9A%84%EF%BC%9F%22%2C%22recId%22%3A1118848177%2C%22recType%22%3A2%2C%22sender%22%3A%22%E8%8A%92%E6%9E%9Cmango%E8%8A%92%E6%9E%9C%22%7D%2C%7B%22addTime%22%3A%222017-08-10+14%3A29%3A45%22%2C%22dialogId%22%3A%22%22%2C%22id%22%3A946162765%2C%22recContent%22%3A%22+%E8%8A%92%E6%9E%9Cmango%E8%8A%92%E6%9E%9C+%E6%AD%A3%E5%9C%A8%E4%B8%BA%E6%82%A8%E6%9C%8D%E5%8A%A1%22%2C%22recId%22%3A1118848177%2C%22recType%22%3A3%2C%22sender%22%3A%22%E8%8A%92%E6%9E%9Cmango%E8%8A%92%E6%9E%9C%22%7D%2C%7B%22addTime%22%3A%222017-08-10+14%3A29%3A22%22%2C%22dialogId%22%3A%22%22%2C%22id%22%3A946162392%2C%22recContent%22%3A%22%E8%AF%A5%E8%AE%BF%E5%AE%A2%E8%AF%B7%E6%B1%82%E4%BA%86%E5%AF%B9%E8%AF%9D%2C%E6%AD%A3%E5%9C%A8%E7%AD%89%E5%BE%85%E5%AE%A2%E6%9C%8D%E5%BA%94%E7%AD%94%22%2C%22recId%22%3A1118848177%2C%22recType%22%3A3%2C%22sender%22%3A%22%22%7D%2C%7B%22addTime%22%3A%222017-08-10+14%3A29%3A22%22%2C%22dialogId%22%3A%22%22%2C%22id%22%3A946162391%2C%22recContent%22%3A%22%E7%94%B1%E4%BA%8E+MJDDDD%E5%B0%8F%E5%BE%90+%E6%9A%82%E6%97%B6%E7%A6%BB%E5%BC%80%EF%BC%8C%E6%AD%A4%E5%AF%B9%E8%AF%9D%E5%B0%86%E8%87%AA%E5%8A%A8%E5%88%86%E9%85%8D%E7%BB%99%E5%85%B6%E4%BB%96%E5%AE%A2%E6%9C%8D%E6%8E%A5%E5%BE%85%22%2C%22recId%22%3A1118848177%2C%22recType%22%3A3%2C%22sender%22%3A%22%22%7D%5D%7D';
fwrite($ttt1, 'Post:'.$post." \r\n");
fwrite($ttt1, 'Get:'.$get." \r\n");
if($result){
/**解码已编码的 URL 字符串*/
$result = urldecode($result);
fwrite($ttt1, $result." \r\n");
/**将json对象解析为json数组*/
$jd_res = json_decode($result,true);
/**
* 循环json数组
* 由于$jd_res包含多个json数组,需要再次遍历循环,如果值不是数组的,直接将key及value输出
* 如果值是数组的,再次遍历输出key及值
* */
// foreach ($jd_res as $k=>$v){
// //
// // var_dump($jd_res);
// if(!is_array($v)){
// //如果不是数组,直接遍历输出key及值
// echo $k.':'.$v.'<br>';
// //记录到日志
// fwrite($ttt1, $k.':'.$v);
// }else{
// //如果是数组,再次遍历输出key及值
// $count_json = count($v);
// for ($i = 0; $i < $count_json; $i++)
// {
// // var_dump($v);
// // var_dump($v['0']);
// //循环出每个数组的key及value
// foreach ($v[$i] as $key=>$value){
// $arr = array();
// $arr = array_push($arr, $value);
// foreach ($arr as $k=>$v ){
// echo $k.':'.$v.'<br>';
// //记录到日志
// fwrite($ttt1, $k.':'.$v.'\r\n');
// }
// }
// }
// }
// }
foreach ($jd_res as $k=>$v){
if(!is_array($v)){
//如果不是数组,直接遍历输出key及值
echo $k.':'.$v.'<br>';
//记录到日志
// fwrite($ttt1, $k.':'.$v." \r\n");
}else{
//如果是数组,再次遍历输出key及值
$count_json = count($v);
for ($i = 0; $i < $count_json; $i++)
{
//循环出每个数组的key及value
foreach ($v[$i] as $key=>$value){
echo $key.':'.$value.'<br>';
//记录到日志
// fwrite($ttt1, $key.':'.$value." \r\n");
}
}
}
}
echo "ok";
}else{
fwrite($ttt1, "暂无获取到数据,请检查接收的网址是否正确!或者联系快商售后!");
}
fclose($ttt1);//关闭写入
?>