Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
themeEclipse
languagephp
titleMeridixSign.class.php
<?php
class MeridixSign {
    private $url;
    private $token;
    private $secret;
    public function __construct($url, $token, $secret, $uid) {
        // Set the correct timezone to ensure that gmtime gives the right result.
        date_default_timezone_set("Europe/Stockholm");
        $this->url = $url;
        $this->token = $token;
        $this->secret = $secret;
    }

    public function getSignedUrl() {
        // Create a random hex-value to use as nonce
        $nonce = substr(md5(rand()), 0, 8);
        // Create an array with the parameters to be used
        $params = array(
            "auth_nonce=" . $nonce,
            "auth_timestamp=" . gmdate("YmdHis"),
            "auth_token=" . $this->token
        );
        // Sort query params in alphabetical order
        sort($params);
        // Reassemble the sorted parameters into a query string by putting and
        // ampersand character between each parameter.
        $qs = implode("&", $params);
        // Concatenate method, url (without query string), query string and
        // the secret with ampersands inbetween
        $encodedurl = "GET&" .  urlencode($this->url) . "&" .urlencode($qs) .
                "&" . $this->secret;
        // Create an md5 signature of the complete encoded url
        $sig = md5($encodedurl);
        // Return the signed url
        return $this->url . "?" . $qs . "&auth_signature=" . $sig;
    }
}
 ?> 

...