2017-11-14 4 views
0

誰でも、私はどのように開発者キー、アプリケーションIDとユーザー名を使用してPHPでトークンを生成するかを記述することができます。 Videyoはhtml jsのみを提供しています。彼らはPHPをサポートしていません。私には分かります。トークンの長さは200プラスです。どのように私は開発者キー、アプリケーションIDとユーザー名を使用してPHPでトークンを生成できますか?

+0

あなたは、私はスコット答えhttps://stackoverflow.com/questions/1846202/php-how-to-generate-a-random-unique-alphanumeric-string –

+0

@ maytham-ɯɐɥʇʎɐɯでこの外観を見ています私は3つのセグメントをすべてマージし、トークンを生成する方法、あなたは私に提供しているすべての機能、私はすでにこのリンクをチェックするが、それは単純なトークンを生成しています。 –

答えて

1

あなたはトークンを生成するコードの下に使用することができます:

 


    class secureToken{ 
     private static $secretKey = 'Your Desired key(Hash)'; 
     private static $secretIv = 'www.domain.com'; 
     private static $encryptMethod = "AES-256-CBC"; 
     public static function tokenencrypt($data) { 
      $key = hash('sha256', self::$secretKey); 
      $iv = substr(hash('sha256', self::$secretIv), 0, 16); 
      $result = openssl_encrypt($data, self::$encryptMethod, $key, 0, $iv); 
      return $result= base64_encode($result); 
     } 
     public static function tokendecrypt($data) { 
      $key = hash('sha256', self::$secretKey); 
      $iv = substr(hash('sha256', self::$secretIv), 0, 16); 
      $result = openssl_decrypt(base64_decode($data), self::$encryptMethod, $key, 0, $iv); 
      return $result; 
     } 
    } 


 

方法を使用する:



    $tokenencrypt = secureToken::tokenencrypt(Your APP ID and Userid); 
    $tokendecrypt = secureToken::tokendecrypt($tokenencrypt); 

 
0

あなたは与えられたパラメータを使用してトークンを生成するためにtwilo PHPを使用することができます。ここ

twilo docs

2

トークンを生成するためにサンプルのPHPコードです。 $ DEV_KEYと$ APP_IDをデベロッパーキーとアプリIDに置き換えることを忘れないでください。これはhttps://developer.vidyo.io/dashboardにあります。 usernameには、特別な文字、特に "@" sysmbolを追加しないでください。このコードはappIdを「@」を使ってユーザー名に追加します。そのため、ユーザーIDでapp 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> 
関連する問題