Kirim SMS dari OzekiPhone




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:
  1. <?php
  2. $url = "http://yoursite.com/HandleDeliveryReport.php";
  3. $server = "http://ozekixepbx.ip:7780";
  4. $commandParams['Command'] = "SendSMS";
  5. $commandParams['ApiExtension'] = "9000";
  6. $commandParams['Sender'] = "777";
  7. $commandParams['Recipient'] = "882";
  8. $commandParams['Message'] = "This is a test SMS";
  9. $commandParams['DeliveryReportURL'] = $url;
  10. $command = http_build_query($commandParams);
  11. $params = array('http' => array('method' => "POST",
  12. 'content' => $command));
  13. $context = stream_context_create($params);
  14. $fp = @fopen($server, 'r', false, $context);
  15. echo "Response: ";
  16. $response = @stream_get_contents($fp);
  17. echo $response;
  18. ?>
Code example 1 - Send SMS, by sending a Request to the API Extension

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.

  1. <?php
  2. $receiveTime = date("c");
  3. $outString = "NotificationName=" .$_REQUEST['NotificationName'].
  4. ",Delivered=" .$_REQUEST['Delivered'].
  5. ",ID=" .$_REQUEST['ID'].
  6. ",ApiExtension=" .$_REQUEST['ApiExtension'].
  7. ",ReceiveDate=$receiveTime\r\n";
  8. file_put_contents('deliveryReports.txt', $outString , FILE_APPEND);
  9. ?>
Code example 2 - Handle delivery report.