johnmahugu

smpp-sms

May 25th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.84 KB | None | 0 0
  1. <?php
  2.   // Clear Fields
  3.   $strResult = "n/a";
  4.   $strMessageStatus = "";
  5.  
  6.   // Default Values
  7.   $strServer = "smpp.activexperts-labs.com";
  8.   $strPort = "2775";
  9.   $strAccount = "[SystemId]";
  10.   $strPassword = "[Password]";
  11.   $strRecipient = "[ToAddress]";
  12.   $strSystemType = "SMPP";
  13.  
  14.   GetSmsDemoAccountInfo($strAccount, $strPassword);
  15.  
  16.   $objSmpp = new COM("AxSms.Smpp");
  17.   $objSmpp->LogFile = sys_get_temp_dir()."ActiveXperts.Smpp.log";
  18.   // Windows default: 'C:\Windows\Temp\ActiveXperts.Smpp.log'
  19.  
  20.   // Form submitted
  21.   if (isset($_POST["btnSendMessage"]))
  22.   {  
  23.     $objSmsMessage   = new COM("AxSms.Message",   NULL, CP_UTF8 );
  24.     $objSmsConstants = new COM("AxSms.Constants", NULL, CP_UTF8 );
  25.    
  26.     $strServer = $_POST['txtServer'];
  27.     $strPort = $_POST['txtServerPort'];
  28.    
  29.     $objSmpp->Connect( $strServer, intval ( $strPort ), 0);
  30.    
  31.     if ($objSmpp->LastError != 0)
  32.     {
  33.       $strResult = $objSmpp->LastError.": " . $objSmpp->GetErrorDescription($objSmpp->LastError);
  34.     }
  35.     else
  36.     {
  37.       $strAccount = $_POST['txtSystemID'];
  38.       $strPassword = $_POST['txtPassword'];
  39.       $strSystemType = $_POST['txtSystemType'];
  40.       $strRecipient = $_POST['txtToAddress'];
  41.      
  42.       $iSystemMode = $objSmsConstants->SMPP_BIND_TRANSCEIVER;
  43.       $iVersion = $objSmsConstants->SMPP_VERSION_34;
  44.      
  45.       $objSmpp->Bind($iSystemMode, $strAccount, $strPassword, $strSystemType, $iVersion, 0, 0, "", 0);
  46.      
  47.       if ($objSmpp->LastError != 0)
  48.       {
  49.         $strResult = $objSmpp->LastError.": " . $objSmpp->GetErrorDescription($objSmpp->LastError);
  50.       }
  51.       else
  52.       {
  53.         $objSmsMessage->Clear();
  54.         $objSmsMessage->ToAddress = $strRecipient;       
  55.         $objSmsMessage->Body = $_POST["txtMessage"];
  56.        
  57.         if (isset($_POST['cbxUnicode']))
  58.         {
  59.           $objSmsMessage->DataCoding = $objSmsConstants->DATACODING_UNICODE;
  60.         }
  61.  
  62.         $objSmpp->SubmitSms($objSmsMessage, $objSmsConstants->MULTIPART_TRUNCATE);
  63.         $strResult = $objSmpp->LastError . ": " . $objSmpp->GetErrorDescription($objSmpp->LastError);                
  64.        
  65.         if ($objSmpp->LastError != 0)
  66.         {
  67.           $strResult = $objSmpp->LastError . ": " . $objSmpp->GetErrorDescription($objSmpp->LastError);                
  68.         }
  69.         else
  70.         {
  71.           if ($objSmpp->WaitForSmsUpdate(3000))
  72.           $objSmsMessage = $objSmpp->FetchSmsUpdate();
  73.          
  74.           if ($objSmpp->LastError == 0)
  75.           {
  76.             // SMPP command status codes are provider specific. The ActiveXperts SMPP Demo Gateway uses command status 1025
  77.             // to communicate there are no more credits left for this account on the ActiveXperts SMPP Demo Gateway.
  78.             if ($objSmsMessage->SmppCommandStatus != 0)
  79.             {
  80.               if ($objSmsMessage->SmppCommandStatus == 1025 AND $strServer == "smpp.activexperts-labs.com")
  81.                 $strResult = "Message not send. Reason: No credits left.";
  82.               else
  83.                 $strResult = "Message not sent. Reason: server error [" . $objSmsMessage->SmppCommandStatus . "].";
  84.             }
  85.           }
  86.         }
  87.        
  88.         $objSmpp->Disconnect();
  89.       }      
  90.     }
  91.   }
  92.  
  93.   function GetSmsDemoAccountInfo(&$strGwAccount, &$strGwPassword)
  94.   {
  95.     // NOTE: during installation of the SMS Component, a unique login and password is created for you.
  96.     // This login and password can be used to send a few SMS messages through the smpp.activexperts-labs.com gateway, for free
  97.    
  98.     $objDemoAccount = new COM("AxSms.DemoAccount");  
  99.     $strGwAccount = $objDemoAccount->SystemId;
  100.     $strGwPassword = $objDemoAccount->Password;
  101.   }
  102.  
  103. //HTML-CSS layout includes, no code there!
  104. include('css/Header.html');
  105. include('css/Menu.html');
  106. ?>
  107.     <div class="container">
  108.       <h1>SMS Component PHP SMPP Sample</h1>
  109.       <hr />
  110.       <p>
  111.         This demo allows you to send SMS messages over SMPP. If you don't have an SMPP subscription,
  112.         you can use the ActiveXperts SMPP Demo Gateway. You can send out a few SMS messages
  113.         for free through this gateway.
  114.       </p>
  115.       <form action="smpp.php" method="post">
  116.         <h2>SMS Component:</h2>
  117.         <h3>Build: <?php echo $objSmpp->Build; ?>; Module: <?php echo $objSmpp->Module; ?></h3>
  118.        
  119.         <!-- Server -->
  120.         <label for="Server">Server:</label>
  121.         <p>
  122.           <input type="text" id="Server" name="txtServer" value="<?php echo $strServer; ?>" />
  123.           : <input type="text" name="txtServerPort" style="width: 75px;" value="<?php echo $strPort; ?>" />
  124.         </p>
  125.        
  126.         <!-- System ID -->
  127.         <label for="SystemID">System ID:</label>
  128.         <p>
  129.           <input type="text" id="SystemID" name="txtSystemID" value="<?php echo $strAccount; ?>" />
  130.         </p>
  131.        
  132.         <!-- Password -->
  133.         <label for="Password">Password:</label>
  134.         <p>
  135.           <input type="text" id="Password" name="txtPassword" value="<?php echo $strPassword; ?>" />
  136.         </p>
  137.        
  138.         <!-- System Type -->
  139.         <label for="SystemType">System Type:</label>
  140.         <p>
  141.           <input type="text" id="SystemType" name="txtSystemType" value="<?php echo $strSystemType; ?>" />
  142.         </p>
  143.        
  144.         <!-- Recipient -->
  145.         <label for="ToAddress">Recipient:</label>
  146.         <p>
  147.           <input type="text" id="ToAddress" name="txtToAddress" value="<?php echo $strRecipient; ?>" />
  148.         </p>
  149.        
  150.         <!-- Message, Multipart, Flash -->
  151.         <label for="Message">Message:</label>
  152.         <p>
  153.           <textarea id="Message" name="txtMessage" style="height:45px;"><?php if (!empty ($_POST['txtMessage'])) echo $_POST['txtMessage']; else echo "Hello world send from ActiveXperts SMS Component!" ?></textarea><br />
  154.          
  155.           <input type="checkbox" class="cbFix" id="Unicode" name="cbxUnicode" <?php if (isset($_POST['cbxUnicode'])) echo "checked=\"yes\""; ?> />
  156.           <label for="Unicode">Unicode</label>
  157.         </p>
  158.        
  159.         <!-- Send button -->
  160.         <div class="clearLabel"></div>
  161.         <p>
  162.           <input type="submit" name="btnSendMessage" value="Send SMS Message!" />
  163.         </p>
  164.        
  165.         <!-- Empty row -->
  166.         <div class="clearRow"></div>
  167.        
  168.         <!-- Result -->
  169.         <label for="Result"><b>Result:</b></label>
  170.         <p>
  171.           <input type="text" id="Result" name="txtResult" class="FullWidth Bold" value="<?php echo $strResult; ?>" />
  172.         </p>
  173.       </form>
  174.       <p>
  175.         This demo uses the ActiveXperts SMS Component, an <a href="http://www.activexperts.com" target="_blank">ActiveXperts Software</a> product.<br />
  176.         <a href="index.php">Back to main page</a>
  177.       </p>
  178.     </div><!-- /container -->
  179. <?php
  180. //HTML-CSS layout include, no code there!
  181. include('css/Footer.html'); ?>
Add Comment
Please, Sign In to add comment