<?php
$applicationName = "testattsapp";
$password = "testattspass";
echo "start";
date_default_timezone_set("UTC");
//Create the key using password + “_” + current UTC year + “-” + current UTC month + “-” + current UTC day then encrypt the key using SHA256
$key = hash ( "sha256" ,$password . "_" . date("Y-m-d", time()));
//POST request with parameters for service, username and key, in order to get the ephemeral credential
$service_url = "http://turn.anyfirewall.com/ephemeral-credential.php?service=turn&username=".$applicationName."&key=".$key;
$curl = curl_init($service_url);
$curl_post_data = array();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);
//If no response from server, return to here.
if ($curl_response === false) return NULL;
curl_close($curl);
$response = json_decode($curl_response);
echo $response;
return NULL;