The Zoom signature uses UTC as a timestamp origin, therefore if you’re running another timezone, PHP’s time()
function will return an incorrect time.
You can get around this using the date_default_timezone_set()
function, which sets the timezone for the remainder of the PHP script.
function generate_signature ( $api_key, $api_secret, $meeting_number, $role){
//Set the timezone to UTC
date_default_timezone_set("UTC");
//Time in milliseconds (or close enough)
$time = time() * 1000 - 30000;
$data = base64_encode($api_key . $meeting_number . $time . $role);
$hash = hash_hmac('sha256', $data, $api_secret, true);
$_sig = $api_key . "." . $meeting_number . "." . $time . "." . $role . "." . base64_encode($hash);
// Return signature, url safe base64 encoded
return rtrim(strtr(base64_encode($_sig), '+/', '-_'), '=');
}
@tommy, I’m wondering it it’s worth adding the date_default_timezone_set("UTC");
line to the documentation, in case anyone else’s server doesn’t run on UTC. Having looked at my server, I’m actually running on ‘Europe/London’ time, meaning that for half the year, my signatures will be 60 minutes out, so I’l be adding this to my implementation too!
Cheers,
Alex