...

View Full Version : how can i linking my smsgateway 2 site $send message



donline
03-20-2010, 04:08 PM
please, forum members i have been trying 2 link my smsgateway to my site /how 2 send message from my site to any phone no in the world.my smsgateway are not requesting to my problem, am using php code .please house can any help me out
thanks
i need very code explaination on how to go about it
thanks

mlseim
03-21-2010, 01:22 AM
Hard to tell without seeing any of your scripting.
Also, every phone service has a slightly different SMS "syntax" or "protocol".

Here is an example for "Nextel Wireless" ...


<?php
$recipient = "6515557879@messaging.nextel.com";
$subject = "This is a test";
$email = "johndoe@aol.com";

$message = "New item added to website, go online and check it.";

$extraheaders = "From: $email\nReply-To: $email\n\n";

if (! mail($recipient, $subject, $message, $extraheaders))
echo "Mail did not send for some reason.";

?>

donline
03-22-2010, 05:07 AM
thanks for your reply sir this is all my coding and my smsgateway site
sending sms my gateway is smsfactory.biz

<?php

include 'SMSfactory.php';

//Required php.ini settings:
// allow_url_fopen = On
// track_errors = On
//
//NOTE: To use https you will need the OpenSSL extension module

$sendresult_detailed = "";
$sendresult_summary = "";


if ( isset($_POST['recipients']) && strlen($_POST['recipients'])!=0 && isset($_POST['message']) )
{
$objSMSfactory = new SMSfactory();


//Set you account login details below:
$objSMSfactory->Username = 'MyUsername';
$objSMSfactory->Password = 'MyPassword';

$objSMSfactory->MaxConCatMsgs = $_POST['maxconcat'];


//Send message

$SendStatusCollection = $SMSfactory->SendMessage ( $_POST['recipients'], $_POST['message'], $_POST['from'] );


//Generate result summaries for display in browser

$sendresult_detailed = "<b>Result Details:</b><br>";

$sendcount = 0;
foreach ( $SendStatusCollection as $SendStatus )
{
$sendresult_detailed = $sendresult_detailed . $SendStatus["To"] . " " . $SendStatus["MessageId"] . " " . $SendStatus["Result"] . "<BR>";

if ( $SendStatus["Result"] == "OK" ) $sendcount++;
}

$sendresult_summary = $sendcount . " out of " . count($SendStatusCollection) . " messages have been sent ok";
}


?>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Send SMS</title>
</head>
<body>
<h1>Send SMS</h1>
<form method="post">
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td>Recipient(s):</td>
<td><input name="recipients" type="text" value="" size="30"></td>
</tr>
<tr>
<td>Sender's Id:</td>
<td><input name="from" type="text" value="" size="30"></td>
</tr>
<tr>
<td valign="top">Message:</td>
<td><textarea name="message" cols="25" rows="5"></textarea></td>
</tr>
<tr>
<td valign="top">Max Msg Parts:</td>
<td><input name="maxconcat" type="from" value="1" size="4"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Send message"></td>
</tr>
</table>
<br>
<br>
<b><?php echo $sendresult_summary; ?></b>
<br>
<br>
<?php echo $sendresult_detailed; ?>
</form>
</body>
</html>

smsfactory.php file
<?php


class smsfactory
{

//User Properties:


//Set the Username and Password properties with your account details
var $Username = "";
var $Password = "";

//Maximum multipart messages that will be used
var $MaxConCatMsgs = 1;

//Service URLs (change to https for secure connection)
//NOTE: To use https you will need the OpenSSL extension module
var $PrimaryGateway = "http://www.smsfactory.biz";
var $BackupGateway = "http://www.smsfactory.biz";




//User Methods:


//Send regular text message
public function SendMessage ( $to, $text, $from )
{
$FormParams = array ( 'username'=>$this->Username,
'password'=>$this->Password,
'to'=>$to,
'from'=>$from,
'text'=>$text,
'maxconcat'=>$this->MaxConCatMsgs );

$FormData = http_build_query($FormParams, '', '&');

$Response = $this->SMSfactory_MakeHTTPRequest ( $FormData );

$SendStatusCollection = $this->SMSfactory_ParseHTTPResponse ( $Response, $to );

return $SendStatusCollection;
}


//Send WAP Push message
public function SendWapPushMessage ( $to, $text, $href, $from)
{
$FormParams = array ( 'username'=>$this->Username,
'password'=>$this->Password,
'to'=>$to,
'type'=>'4',
'from'=>$from,
'text'=>$text,
'href'=>$href );

$FormData = http_build_query($FormParams, '', '&');

$Response = $this->SMSfactory_MakeHTTPRequest ( $FormData );

$SendStatusCollection = $this->SMSfactory_ParseHTTPResponse ( $Response, $to );

return $SendStatusCollection;
}


//Send Unicode message
public function SendUnicodeMessageHex ( $to, $unicodehex, $from )
{
$FormParams = array ( 'username'=>$this->Username,
'password'=>$this->Password,
'to'=>$to,
'type'=>'2',
'from'=>$from,
'hex'=>$unicodehex,
'maxconcat'=>$this->MaxConCatMsgs );

$FormData = http_build_query($FormParams, '', '&');

$Response = $this->SMSfactory_MakeHTTPRequest ( $FormData );

$SendStatusCollection = $this->SMSfactory_ParseHTTPResponse ( $Response, $to );

return $SendStatusCollection;
}


//Send Binary message
public function SendBinaryMessage ( $to, $userdataheaderhex, $userdatahex, $from )
{
$FormParams = array ( 'username'=>$this->Username,
'password'=>$this->Password,
'to'=>$to,
'type'=>'3',
'from'=>$from,
'udh'=>$userdataheaderhex,
'ud'=>$userdatahex );

$FormData = http_build_query($FormParams, '', '&');

$Response = $this->SMSfactory_MakeHTTPRequest ( $FormData );

$SendStatusCollection = $this->SMSfactory_ParseHTTPResponse ( $Response, $to );

return $SendStatusCollection;
}


//Send regular text message with UserContext
public function SendMessageWithUserContext ( $to, $text, $usercontext )
{
$FormParams = array ( 'username'=>$this->Username,
'password'=>$this->Password,
'to'=>$to,
'usercontext'=>$usercontext ,
'text'=>$text,
'maxconcat'=>$this->MaxConCatMsgs );

$FormData = http_build_query($FormParams, '', '&');

$Response = $this->SMSfactory_MakeHTTPRequest ( $FormData, $to );

$SendStatusCollection = $this->SMSfactory_ParseHTTPResponse ( $Response, $to );

return $SendStatusCollection;
}


//Get account balance
public function GetBalance ()
{
$FormParams = array ( 'username'=>$this->Username,
'password'=>$this->Password );

$FormData = http_build_query($FormParams, '', '&');

$Response = $this->SMSfactory_MakeHTTPRequestToURL ( $FormData, "/smsgateway/getbalance.aspx" );

$Results = $this->SMSfactory_ParseHTTPResponse_GetBalance ( $Response );

return $Results;
}




//Implementation Functions:


private function SMSfactory_MakeHTTPRequest ( $data )
{
return $this->SMSfactory_MakeHTTPRequestToURL ( $data, "/smsgateway/sendmsg.aspx" );
}

private function SMSfactory_MakeHTTPRequestToURL ( $data, $urlpath )
{
try
{
$Response = $this->SMSfactory_MakeHTTPRequestUsingGateway ( 1, $data, $urlpath );
}
catch (Exception $e)
{
try
{
//Try backup gateway SMSGateway
$Response = $this->IntelliSMS_MakeHTTPRequestUsingGateway ( 2, $data, $urlpath );
}
catch (Exception $e2)
{
//Throw first exception
throw $e;
}
}

return $Response;
}


private function SMSfactory_MakeHTTPRequestUsingGateway ( $gatewayid, $data, $urlpath )
{
if ( $gatewayid == 1 )
{
$gatewayurl = $this->PrimaryGateway . $urlpath;
}
else if ( $gatewayid == 2 )
{
$gatewayurl = $this->BackupGateway . $urlpath;
}
else
{
throw new Exception("Gateway Id invalid $gatewayid");
}

return $this->MakeHTTPFormPost ( $gatewayurl, $data, "Content-Type: application/x-www-form-urlencoded\r\n" );
}


private function SMSfactory_ParseHTTPResponse ( $response, $to )
{
$const_IdPrefix = "ID:";
$const_ErrPrefix = "ERR:";

$SendStatusCollection = array();

$msgresponses = split("\n", $response );

$idx = 0;

foreach ( $msgresponses as $msgresponse )
{
$msgresponse = trim($msgresponse);

if ( strlen($msgresponse) > 0 )
{
$msgresponseparts = split(",", $msgresponse );

$msisdn = null;
$msgid = null;
$errorstatus = null;

if ( count($msgresponseparts) >= 2 )
{
$msisdn = $msgresponseparts[0];
$msgresult = $msgresponseparts[1];
}
else
{
if ( count(split(",",$to))==1 )
{
$msisdn = $to;
}
else
{
$msisdn = "";
}
$msgresult = $msgresponseparts[0];
}

if ( strncmp($msgresult,$const_IdPrefix,strlen($const_IdPrefix))==0 )
{
$msgid = substr($msgresult,strlen($const_IdPrefix));
$errorstatus = "OK";
}
else if ( strncmp($msgresult,$const_ErrPrefix,strlen($const_ErrPrefix))==0 )
{
$msgid = "NoId";
$errorstatus = substr($msgresult,strlen($const_ErrPrefix));
}

$SendStatusCollection[$idx]["To"] = $msisdn;
$SendStatusCollection[$idx]["MessageId"] = $msgid;
$SendStatusCollection[$idx]["Result"] = $errorstatus;

$idx++;
}
}

return $SendStatusCollection;
}


private function SMSfactory_ParseHTTPResponse_GetBalance ( $response )
{
$const_BalancePrefix = "BALANCE:";
$const_ErrPrefix = "ERR:";

$Results = array();

if ( strncmp($response,$const_BalancePrefix,strlen($const_BalancePrefix))==0 )
{
$Results["Balance"] = substr($response,strlen($const_BalancePrefix));
$Results["ErrorStatus"] = "OK";
}
else if ( strncmp($response,$const_ErrPrefix,strlen($const_ErrPrefix))==0 )
{
$Results["Balance"] = -1;
$Results["ErrorStatus"] = substr($response,strlen($const_ErrPrefix));
}

return $Results;
}


private function MakeHTTPFormPost ( $url, $data, $optional_headers = null)
{
$params = array ( 'http' => array ( 'method' => 'POST', 'content' => $data ) );

if ($optional_headers !== null)
{
$params['http']['header'] = $optional_headers;
}

$ctx = stream_context_create($params);

$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem making HTTP request $url, $php_errormsg");
}

$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading HTTP Response $url, $php_errormsg");
}

return $response;
}

}



//Unicode helper functions

function utf8toucs2hex($utf8)
{
$utf8_hex = bin2hex( $utf8 );
return utf8hextoucs2hex($utf8_hex);
}

function utf8hextoucs2hex($str)
{
$ucs2 = "";

for ($i=0;$i<strlen($str);$i+=2)
{
$char1hex = $str[$i].$str[$i+1];

$char1dec = hexdec($char1hex);
if ( $char1dec < 128)
{
$results = $char1hex;
}
else if ( $char1dec < 224 )
{
$char2hex = $str[$i+2].$str[$i+3];
$results = dechex( ((hexdec($char1hex)-192)*64) + (hexdec($char2hex)-128) );
$i+=2;
}
else if ( $char1dec < 240 )
{
$char2hex = $str[$i+2].$str[$i+3];
$char3hex = $str[$i+4].$str[$i+5];
$results = dechex( ((hexdec($char1hex)-224)*4096) + ((hexdec($char2hex)-128)*64) + (hexdec($char3hex)-128) );
$i+=4;
}
else
{
//Not supported: UCS-2 only
$i+=6;
}

while ( strlen($results) < 4 )
{
$results = '0' . $results;
}

$ucs2 .= $results;
}

return $ucs2;
}


?>

balance checking
<?php

include 'smsfactory.php';


//Required php.ini settings:
// allow_url_fopen = On
// track_errors = On
//
//NOTE: To use https you will need the OpenSSL extension module




$objsmsfactory = new IntelliSMS();


//Set you account login details below:
$objsmsfactory->Username = 'MyUsername';
$objsmsfactory->Password = 'MyPassword';



//Get Balance

$Results = $smsfactory->GetBalance ();

$ErrorStatus = $Results["ErrorStatus"];
$Balance = $Results["Balance"];

?>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Get Balance</title>
</head>
<body>
<h1>Get Balance</h1>
<br>
<b>Error Status: <?php echo $ErrorStatus ?></b>
<br>
<b>Balance: <?php echo $Balance ?></b>
<br>
<br>
</form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum