<?php

$content = file_get_contents('php://input');

$data =json_decode($content,true);

create_log('info','美团来了'.'---'.$content);

if($content){
    //推送消息
    // if($data['status'] =='1'){
    //     $urlso='https://api.layacms.com/index/Swoole/index'; 
    //     file_get_contents($urlso);
    // }
    //create_log('info','美团数据来了'.'---'.$data['orderid']);
   // file_put_contents('/www/wwwroot/mt.layacms.com/te.log', date('Y-m-d H:i:s').'————'.'美团数据来了————'.$data['orderid']."\r\n", FILE_APPEND); 
    $url = 'https://api.layacms.com/h5/meituan/index';
    $cdasres = hsttp_request($url,$content);
    create_log('info','美团数据来了'.'---'.$cdasres['msg']);
   // file_put_contents('/www/wwwroot/mt.layacms.com/te.log', date('Y-m-d H:i:s').'————'.$cdasres['msg']."\r\n", FILE_APPEND); 
}else{
    create_log('info','参数有误'.'---');
    //file_put_contents('/www/wwwroot/mt.layacms.com/te.log', date('Y-m-d H:i:s').'————'.'参数有误'."\r\n", FILE_APPEND); 
    echo '参数有误';
}

function create_log($msg,$data){
    
        $mulus = '/runtime/project_log/'.date('Ym').'/';
        $mulu = $_SERVER['DOCUMENT_ROOT'].'/runtime/project_log/'.date('Ym').'/';
        $pathArr = explode("/", $mulus);
        unset($pathArr[0]);
        unset($pathArr[6]);
        $pathed="";
        foreach ($pathArr as $key=>$row) {
            $pathed=$pathed.$row."/";
            if ($key==0) {
                continue;
            }
            
            if (is_dir($pathed)) {
                continue;
            }
            else{
                mkdir($pathed);
            }
        }
        file_put_contents($mulu.date('d').'.txt','['.date('Y-m-d H:i:s',time()).']'.'['.$msg.']'.' '.var_export($data, true) . PHP_EOL, FILE_APPEND);
    }


 function  hsttp_request($url, $data = null)
    {
        
        // Generated by ApiPost: https://www.apipost.cn/
            $ch = curl_init();
            
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            
            $headers = array();
            $headers[] = 'User-Agent: Apipost client Runtime/+https://www.apipost.cn/';
            $headers[] = 'Content-Type: application/json';
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            
            $result = curl_exec($ch);
            if (curl_errno($ch)) {
                echo 'Error:' . curl_error($ch);
            }
            curl_close($ch);
            return json_decode($result,true);
          

    }




?>