Exemple #1
0
$ortcConfig->setApplicationKey('YOUR_APPLICATION_KEY');
$ortcConfig->setPrivateKey('YOUR_PRIVATE_KEY');
$ortcConfig->setVerifySsl(false);
$authToken = 'YOUR_AUTHENTICATION_TOKEN';
$channels = [];
$testChannel = new Channel();
$testChannel->setName('CHANNEL_NAME');
$testChannel->setPermission(Channel::PERMISSION_WRITE);
$channels[] = $testChannel;
$ortc = new Ortc($ortcConfig);
if (isset($_POST['message'])) {
    $sendMessageRequest = new SendMessageRequest();
    $sendMessageRequest->setAuthToken($authToken);
    $sendMessageRequest->setChannelName($testChannel->getName());
    $sendMessageRequest->setMessage($_POST['message']);
    $ortc->sendMessage($sendMessageRequest);
} else {
    $authRequest = new AuthRequest();
    $authRequest->setAuthToken($authToken);
    $authRequest->setExpireTime(5 * 60);
    $authRequest->setPrivate(true);
    $authRequest->setChannels($channels);
    $authResponse = $ortc->authenticate($authRequest);
}
?>
<!doctype html>
<html>
<head>
    <title>Send Message</title>
</head>
<body>
 /**
  * send (push) message to a channel
  *
  * @param string|SendMessageRequest $channelOrSendMessageRequest
  * @param string $authToken
  * @param string $message
  * @throws \Nikapps\OrtcPhp\Exceptions\BatchRequestException
  * @return \Nikapps\OrtcPhp\Models\Responses\SendMessageResponse
  */
 public function send($channelOrSendMessageRequest, $authToken = '', $message = '')
 {
     if (!$channelOrSendMessageRequest instanceof SendMessageRequest) {
         $channelName = $channelOrSendMessageRequest;
         $sendMessageRequest = new SendMessageRequest();
         $sendMessageRequest->setAuthToken($authToken);
         $sendMessageRequest->setChannelName($channelName);
         $sendMessageRequest->setMessage($message);
     } else {
         $sendMessageRequest = $channelOrSendMessageRequest;
     }
     $ortc = new Ortc($this->ortcConfig);
     return $ortc->sendMessage($sendMessageRequest);
 }