/** * Send request to IMASYS Messaging Platform * * @param RequestInterface $request * @throws \Exception */ public function send(RequestInterface $request) { $url = $request->buildUrl($this->credentials, $this->portalServers->getPortalServer(), 443); $body = $request->buildBody(); $curlRequest = new CurlRequest($url); $curlRequest->setPostBody(urlencode($body)); $curlRequest->run(); if (!$curlRequest->wasSuccessful()) { throw new \Exception(); } $curlResponse = $curlRequest->response; return $request->parseResponse($curlResponse); }
<?php require '../vendor/autoload.php'; use Comsolit\ImasysPhp\PortalServers; use Comsolit\ImasysPhp\Credentials; use Comsolit\ImasysPhp\Connection; use Comsolit\ImasysPhp\ApiMethods\SendMessageRequest; use Comsolit\ImasysPhp\ApiMethods\BatchStatusRequest; $config = (require __DIR__ . '/config.php'); if (count($argv) !== 4) { die('usage: send_message.php MESSAGE ADDRESS ORIGINATOR'); } $credentials = new Credentials($config['user'], $config['password']); $portalServers = PortalServers::fetchPortalServers($config['host'], $credentials); $connection = new Connection($credentials, $portalServers); $sendMessageRequest = new SendMessageRequest($argv[1], $argv[2], $argv[3]); $sendMessageResponse = $connection->send($sendMessageRequest); sleep(10); $batchStatusRequest = new BatchStatusRequest($sendMessageResponse->getBatchId()); $batchStatusResponse = $connection->send($batchStatusRequest); foreach ($batchStatusResponse->getBatch()->getMessages() as $message) { print_r($message->getStatus()); }