|
Advanced Services - SMS Connectivity PHP Sample application using HTTP to send a picture message |
![]() |
The following sample application written in PHP sends a picture 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 Nokia Picture Graphics 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 = 'sendnok';
$client_id = '<your client_id>';
$destaddr = '<some fully-qualified MSISDN>';
$type = "pg";
$content = '50340a232043726561746564206279205061696e742053686f702050726f20370a'
. '37322032380a0000000000000000000003ffffffffffffff000000000000000000'
. '00e0000000000000000338000000000000000cee00000000000000131b01f81f8f'
. 'e7c0006c06c0600618630000f001e0600630230000e000e0600630030000e000e0'
. '600618030000e000e060061c030000e000e060060f030000e000e07ffe07830000'
. 'e000e0600601c30000e000e0600600e30000e000e0600600730000e000e0600600'
. '730000e000e0600620730080f001e0600630e301807c07c1f81fbf87ff801f1f00'
. '0000000000000ffe0000000000000003f80000000000000000e000000000000000'
. '0000000000000000000003ffffffffffffff000000000000000000';
$text = 'this is a test message';
$secret = '<your secret>';
// Compute the MD5 hash (digest)
$hash = md5($secret . $type . $content . $text . '00000' . $destaddr);
// Build and encode the URL.
// Note we are careful to URL-encode the message content as it is the only part
// of the URL likely to contain reserved characters.
$url = "http://$host:$port/$action/?client_id=$client_id&destaddr=$destaddr"
. "&type=$type&content=$content&text=" . urlencode($text) . "&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>
picture_message_http_example.php
Copyright © Hay Systems Ltd 2004
Owner: support@haysystems.com 20 September 2004