Advanced Services - SMS Connectivity

PHP Sample application using HTTP to send a UCS2 or Unicode message

HSL Mobile Messaging

The following sample application written in PHP sends a UCS2 or Unicode message to a single mobile telephone. The application uses HTTP to communicate with HSL's systems. To send to more than one mobile telephone at a time, separate each mobile number in the destaddr field by a comma (e.g. "447968000111,447720000111,3378100100").

<html>
<head>
    <title>Simple PHP example of UCS2 via the HSL HTTP interface</title>
</head>
<body>

<?php

// These variables fill out the various parts described in the interface
// specification
$host = 'sms.haysystems.com';
$port = '80';
$action = 'senducs';
$client_id = '<your client_id>';
$destaddr = '<some fully-qualified MSISDN>';
$ucs2 = '06450631062d0628064b06270020063906270644064500200021';
$secret = '<your secret>';

// Compute the MD5 hash (digest)
$hash = md5($secret . $ucs2 . $destaddr);

// Build and encode the URL.
$url = "http://$host:$port/$action/?client_id=$client_id&destaddr=$destaddr"
       . "&message=$ucs2&key=$hash";

// Make the HTTP call (you could use CURL on PHP 4+) we nab the content that
// readfile would normally output directly with the ob_start, ob_get_contents
// and ob_end_clean calls.
ob_start();
$result = @readfile($url);
$data = ob_get_contents();
ob_end_clean();

// Examine the results
if($result === false) {
    echo '<p>Could not make HTTP request; is the URL correct?</p>';
    echo "<p>$url</p>";

} else {
    echo "<p>Submission result: $data</p>";
}

?>

</body>
</html>

ucs2_http_example.php


Copyright © Hay Systems Ltd 2004

Owner: support@haysystems.com 20 September 2004

Sample code link | Developers section link