zx/vendor/qiniu/php-sdk/examples/rtc/rtc_create_roomToken.php

35 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once __DIR__ . '/../../autoload.php';
use Qiniu\Auth;
use Qiniu\Rtc\AppClient;
// 控制台获取密钥https://portal.qiniu.com/user/key
$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$auth = new Auth($accessKey, $secretKey);
$client = new AppClient($auth);
// app 的唯一标识,创建的时候由系统生成
$appId = 'xxxx';
// 房间名称,需满足规格 ^[a-zA-Z0-9_-]{3,64}$
$roomName = 'room01';
// 请求加入房间的用户 ID需满足规格 ^[a-zA-Z0-9_-]{3,50}$
$userId = '001';
// 鉴权的有效时间传入以秒为单位的64位 Unix 绝对时间token 将在该时间后失效
$expireAt = time()+3600;
// "admin"或"user",默认为"user" 。当权限角色为"admin"时,拥有将其他用户移除出房间等特权
$permission = 'admin';
// 生成加入房间的令牌 RoomToken
// 参考文档https://doc.qnsdk.com/rtn/docs/server_overview#1
$RoomToken = $client->appToken($appId, $roomName, $userId, $expireAt, $permission);
echo "\n====> Create RoomToken Successfully \n";
var_dump($RoomToken);