public function testGetPostData()
 {
     $ortcConfig = new OrtcConfig();
     $ortcConfig->setApplicationKey('abcede');
     $ortcConfig->setPrivateKey('123456');
     $ortcConfig->setMaxChunkSize(10);
     $request = new SendMessageRequest();
     $request->setOrtcConfig($ortcConfig);
     $request->setAuthToken('wxyz123');
     $request->setMessage('{message:foo bar}');
     $request->setChannelName('channel_name');
     $postData = $request->getPostData();
     $this->assertEquals(2, count($postData));
     $this->assertEquals(5, count($postData[0]));
     $this->assertEquals('abcede', $postData[0]['AK']);
     $this->assertEquals('123456', $postData[0]['PK']);
     $this->assertEquals('wxyz123', $postData[0]['AT']);
     $this->assertEquals('channel_name', $postData[0]['C']);
     $this->assertRegExp('/^[A-Za-z0-9]{8}_1-2_\\{message:f$/', $postData[0]['M']);
     $this->assertEquals(5, count($postData[1]));
     $this->assertEquals('abcede', $postData[1]['AK']);
     $this->assertEquals('123456', $postData[1]['PK']);
     $this->assertEquals('wxyz123', $postData[1]['AT']);
     $this->assertEquals('channel_name', $postData[1]['C']);
     $this->assertRegExp('/^[A-Za-z0-9]{8}_2-2_oo bar\\}$/', $postData[1]['M']);
 }
Exemple #2
0
use Nikapps\OrtcPhp\Models\Requests\SendMessageRequest;
use Nikapps\OrtcPhp\Ortc;
require_once '../vendor/autoload.php';
$ortcConfig = new OrtcConfig();
$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>
 /**
  * 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);
 }
Exemple #4
0
 /**
  * send message (push).
  *
  * @param SendMessageRequest $sendMessageRequest
  *
  * @throws Exceptions\BatchRequestException
  *
  * @return Models\Responses\SendMessageResponse
  */
 public function sendMessage(SendMessageRequest $sendMessageRequest)
 {
     $this->prepare();
     $sendMessageRequest->setOrtcConfig($this->ortcConfig);
     $ortcClient = new OrtcClient();
     $ortcClient->setRequest($sendMessageRequest);
     $ortcClient->setGuzzleClient($this->guzzleClient);
     $ortcClient->setBaseUrl($this->baseUrl);
     return $ortcClient->batchExecute();
 }