true, CURLOPT_RETURNTRANSFER=>true, CURLOPT_POST=>true, CURLOPT_POSTFIELDS =>$body, CURLOPT_HTTPHEADER=>$headers )); $res=curl_exec($curl); curl_close($curl); return($res); } if(!file_exists($tokenfile)){ $json=post('https://api.amazon.com/auth/o2/token',http_build_query(array( 'grant_type'=>'refresh_token', 'refresh_token'=>$token, 'client_id'=>$client_ID, 'client_secret'=>$client_secret, )),array('Content-Type: application/x-www-form-urlencoded;Accept-Charset=UTF-8')); file_put_contents($tokenfile,$json); $token=json_decode($json,true); }else{ $token=json_decode(file_get_contents($tokenfile),true); if(filemtime($tokenfile)+$token['expires_in']'refresh_token', 'refresh_token'=>$token['refresh_token'], 'client_id'=>$client_ID, 'client_secret'=>$client_secret, )),array('Content-Type: application/x-www-form-urlencoded;Accept-Charset=UTF-8')); file_put_contents($tokenfile,$json); $token=json_decode($json,true); } } $access_token=$token['access_token']; $t=time()-5; foreach(array('NOT_DETECTED','DETECTED') as $state){ $messageId=$device_name.'-'.$t; $time=gmdate("Y-m-d\\TH:i:s",$t).'.00Z'; post('https://api.fe.amazonalexa.com/v3/events',<<