gpt4 book ai didi

php - 如何使用开发人员 key 、应用程序 ID 和用户名在 php 中生成 token ?

转载 作者:行者123 更新时间:2023-12-02 06:19:18 26 4
gpt4 key购买 nike

任何人都可以描述我如何使用开发人员 key 、应用程序 ID 和用户名在 php 中生成 token 。 Videoyo只提供html js,他们对php没有任何支持。请提示我。 token 长度为 200 以上。

最佳答案

这里是生成 token 的示例 php 代码。不要忘记将 $DEV_KEY 和 $APP_ID 替换为您的开发人员 key 和应用程序 ID,您可以在 - https://developer.vidyo.io/dashboard 上找到它们。 。对于用户名,不要添加任何特殊字符,尤其是“@”符号。该代码使用“@”将 appId 附加到用户名,因此如果在用户名中使用它,将会扰乱应用程序 ID 的解码。对于更短或更长的 token 持续时间,请更改 $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>

关于php - 如何使用开发人员 key 、应用程序 ID 和用户名在 php 中生成 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47278120/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com