In this example you can learn how to send SMS messages and handle the delivery report through aninstalled API Extension.
Please write the following code into the right file on your web server:
- <?php
- $url = "http://yoursite.com/HandleDeliveryReport.php";
- $server = "http://ozekixepbx.ip:7780";
- $commandParams['Command'] = "SendSMS";
- $commandParams['ApiExtension'] = "9000";
- $commandParams['Sender'] = "777";
- $commandParams['Recipient'] = "882";
- $commandParams['Message'] = "This is a test SMS";
- $commandParams['DeliveryReportURL'] = $url;
- $command = http_build_query($commandParams);
- 'content' => $command));
- $context = stream_context_create($params);
- $fp = @fopen($server, 'r', false, $context);
- echo "Response: ";
- $response = @stream_get_contents($fp);
- echo $response;
- ?>
Code example 1 - Send SMS, by sending a Request to the API Extension
Figure 1 - HTTP API Tester
First of all, configure your Request parameters.
These are HTTP API commands. The HTTP API is an API available for the Ozeki Phone System XE that allows calls to be created, controlled and monitored, it also allows SMS messages to be sent. In this scenario the Commad must be „SendSMS” because we want to send a text message. (Check thecommand and the parameters of SendSms.) The ApiExtension parameter specifies which api extension is added to the command. The Sender is a phone number, the recipient will see as the sender and the Recipient is the destination phone number. The Message parameter is the content of the message. The SMS delivery report is sent to the adjusted URL as a notification. The Sender and the DeliveryReportURL are optional paramteres.
You can reach the same features in your Ozeki Phone System XE at the HTTP API section. Click on the Productivity menu point on the top of the screen and select the HTTP API option. Important to mention this is only a test interface and with this you can simulate incoming requests to initiate calls or send messages. With HTTP API Tester you can try all of the HTTP API commands and features. If you select the SendSMS command you can see the parameter settings (Command, APIExtension, Sendter etc.) what we set in the code earlier. And you can send a HTTP request, only need to click on the 'Send request' button to make it happen.
Figure 1 - HTTP API Tester
If you would like to know more about the Ozeki Phone System XE HTTP API, click on this page.
Please change the ozekixepbx.ip text to that ip address where the Ozeki Phone System XE is installed. On the yoursite.com the address should be that where the sample applications are running. After the configuration, make a HTTP Request with these values and send it to the API Extension. The API will send back a delivery report (if your SMS service provider supports it) to the given DeliveryReportURL.
At the DeliveryReportURL it is possible to make another application that will handle the reports, for example log it into file.
- <?php
- $receiveTime = date("c");
- $outString = "NotificationName=" .$_REQUEST['NotificationName'].
- ",Delivered=" .$_REQUEST['Delivered'].
- ",ID=" .$_REQUEST['ID'].
- ",ApiExtension=" .$_REQUEST['ApiExtension'].
- ",ReceiveDate=$receiveTime\r\n";
- file_put_contents('deliveryReports.txt', $outString , FILE_APPEND);
- ?>
Code example 2 - Handle delivery report.