PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function base64url_encode($data) { return rtrim(strtr(base64_encode($data), '+/', '-_'), '='); } function encode_token($key, $data, $aad) { $nonce = random_bytes(24); return base64url_encode( $nonce . sodium_crypto_aead_xchacha20poly1305_ietf_encrypt( json_encode($data), json_encode($aad, JSON_UNESCAPED_SLASHES), $nonce, base64_decode($key) ) ); } $stream_url = "https://box5.gideo.video/hls/123/directorscut.m3u8"; $token = encode_token( // Base64-encoded encryption key. 'HdEg0dJZXaamOlqQ7D8IgVbxt1d3OlVw8/BOwO/bUKM=', array( // Amember user ID. "sub" => 1234, // Current unix time. "iat" => time(), // User's current IP ($_GET['REMOTE_ADDR'] if no CDN or reverse proxy). "ip" => "255.255.255.255", // Platform (always use "web"; OTT will use a different value) "os" => "web", ), array( // Stream URL. $stream_url, ), ); $stream_url .= '?t=' . $token; echo $stream_url;
Show:  
Copy Clear