<?php
include("RtcTokenBuilder2.php");

$appId = "0474415d8da64ed692111f7d0dce07c4";
$appCertificate = "3eb00e8082024a72bbb5eac9b34d94c2";

$data = json_decode(file_get_contents('php://input'), true);

if ($data == null || !array_key_exists('ChannelName', $data)) {
	    die(json_encode(array("code" =>1, "token"=>"param error")));
}

$channelName = $data['ChannelName'];
$uid = 0;
$tokenExpirationInSeconds = 86400;
$privilegeExpirationInSeconds = 86400;


$token = RtcTokenBuilder2::buildTokenWithUid(
    $appId,
    $appCertificate,
    $channelName,
    $uid,
    RtcTokenBuilder2::ROLE_PUBLISHER,
    $tokenExpirationInSeconds,
    $privilegeExpirationInSeconds);

echo json_encode(array(
    "code" => 200,
    "token" => $token
));
