任何人都可以描述我是如何使用开发者密钥、应用程序id和用户名在php中生成令牌的。Videyo只提供html js,他们不支持php。请给我个提示。令牌长度为200 +。
发布于 2017-11-15 02:41:06
以下是生成令牌的示例php代码。不要忘记将$DEV_KEY和$APP_ID替换为您的开发人员密钥和应用程序Id,您可以在https://developer.vidyo.io/dashboard上找到。对于用户名,不要添加任何特殊字符,特别是"@“符号。代码使用"@“将appId附加到用户名,所以如果在用户名中使用它,将会扰乱应用程序Id的解码。对于较短或较长的令牌持续时间,请更改$expiresInSecs值。
<!DOCTYPE html>
<html>
<head>
<title>Token Generation php script</title>
</head>
<body>
<p><?php echo "Token Generation Sample <br />";
$DEV_KEY = "XXXXX" ; // Copy your dev key from vidyo.io dashboard
$APP_ID = "XXXXX.vidyo.io" ; // Copy your app Id from vidyo.io dashboard
$username = "Batman" ; // Username, hard coded for debug purposes
$expiresInSecs = 1000 ; // Generated token will expire after these many seconds
// time() by default subtracts datetime(1970, 1, 1) from the datetime
// on which we call it, therefore the number of seconds is smaller
// by (pseudocode!) seconds("1970-01-01").
// In Erlang, on the other hand, we get the actual number of seconds,
// hence we adjust for this difference here.
// IMPORTANT! A 64bit architecture is assumed! Otherwise, the timestamp
// might be stored as a 32bit integer, therefore limiting the "capacity"
// to 2038 (see https://en.wikipedia.org/wiki/Year_2038_problem).
$EPOCH_SECONDS = 62167219200 ;
$expires = $EPOCH_SECONDS + $expiresInSecs + time();
echo "<br />" ;
echo "Developer key" . "\t" ."\t" ."\t" . ":" . $DEV_KEY . "<br />" ;
echo "App ID : " . $APP_ID . "<br />" ;
echo "Username : " . $username . "<br />" ;
echo "Expires : " . date("F j, Y, g:i a", $expiresInSecs + time()) . "<br />" ;
$jid = $username . "@" . $APP_ID ;
//echo "JID: " . $jid . "<br />" ;
// Must place \0 within double quotes, not single quotes.
$body = "provision" . "\0" . $jid . "\0" . $expires . "\0" . "" ;
echo "BODY: " . $body . "<br />" ;
// Important to convert to UTF8. I found this is what made the difference.
$utf8_body = utf8_encode( $body ) ;
echo "UTF8 BODY: " . $utf8_body . "<br />" ;
// Ensure the SHA384 Algo is being used.
$mac_hash = hash_hmac( "sha384", $utf8_body, $DEV_KEY ) ;
echo "HMAC (384): " . $mac_hash . "<br />" ;
// Again, ensure \0 are encapsulated with double quotes. Single quotes does not append the null character to the string
$serialized = $utf8_body . "\0" . $mac_hash ;
echo "SERIALIZED: " . $serialized . "<br />" ;
// Base64 Encode the serialized string
$b64_encoded = base64_encode( $serialized ) ;
echo "<br /> B64 ENCODED TOKEN :<br /><br />" . $b64_encoded . "<br />" ;
?></p>
</body>
</html>发布于 2017-11-14 13:49:20
您可以使用twilo php生成带有给定参数的令牌。
https://stackoverflow.com/questions/47278120
复制相似问题