function calculateSignature(&$params, $secretKey, $chosenFields=NULL)
{
if ($chosenFields == NULL) {
$chosenFields = array_keys($params);
}
// Sort the key fields //
sort($chosenFields);
$requestsString = '';
// Assemble them by using '&' as a separator string //
foreach ($chosenFields as $field) {
if (isset($params[$field])) {
$requestsString .= $field . '=' . ($params[$field]) .'&';
}
}
// Embed the secret key //
$requestsString .= 'secret_key=' . $secretKey;
// Finally hash the request string //
$signature = md5($requestsString);
return $signature;
}
static function checkSignatureForRDPConnectAPI (&$params, $secretKey)
{
// Calculate our-own the signature based on the received response parameters //
$copyParams = $params;
unset($copyParams['signature']);
$calculatedSignature = self::calculateSignature($copyParams, $secretKey);
// Compare our-own calculated signature and the one that received //
if ($calculatedSignature != $params['signature']) {
return false;
}
return true;
}
function post ($url, $data=array())
{
// Get cURL resource //
$curl = curl_init();
$postfields = substr((http_build_query($data) . "&"), 0, -1);
// Set some options - we are passing in a user agent too here //
curl_setopt_array ($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $postfields,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE
));
// Send the request & save response to $resp //
$resp = curl_exec($curl); //echo $url;
// Close request to clear up some resources //
curl_close($curl);
return $resp;
}