johnmahugu

ussd-sms

May 25th, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.70 KB | None | 0 0
  1. <?php
  2.   $strResponse = "";
  3.   $strResult = "n/a";
  4.   $objGsm = new COM("AxSms.Gsm");
  5.   $objGsm->LogFile = sys_get_temp_dir()."Ussd.log";
  6.   // Windows default: 'C:\Windows\Temp\Ussd.log'
  7.  
  8.   // Form submitted
  9.   if (isset($_POST["btnSendMessage"]))
  10.   {
  11.     $objSmsConstans = new COM("AxSms.Constants");
  12.    
  13.     $strCommand = 'AT+CUSD=1,"'.$_POST['txtCommand'].'",15';
  14.     $strFields = array();
  15.     $strName = $_POST['ddlDevices'];
  16.     $strPincode = $_POST['txtPincode'];
  17.     $iDeviceSpeed = $_POST['ddlDeviceSpeed'];
  18.    
  19.     $objGsm->Open($strName, $strPincode, $iDeviceSpeed);
  20.     $strResponse = $objGsm->GetErrorDescription($objGsm->LastError);
  21.    
  22.     if ($objGsm->LastError == 0)
  23.     {
  24.       $objGsm->SendCommand($strCommand);
  25.       $strResponse = $objGsm->ReadResponse(0);
  26.      
  27.       if (strpos($strResponse, "OK") != false) //Response should be OK
  28.       {
  29.         $objGsm->SendCommand("");
  30.         $strResponse = $objGsm->ReadResponse(0);
  31.        
  32.         if (strpos($strResponse, "+CUSD:") !== false)
  33.         {
  34.           $strFields = explode("\\", $strResponse);
  35.          
  36.           $strResponse = (count($strFields) > 1) ?
  37.             $strFields[1] : $strFields[0];
  38.         }
  39.       }
  40.    
  41.       if ($objGsm->LastError != 0)
  42.       {
  43.         $strResponse = $objGsm->GetErrorDescription($objGsm->LastError);
  44.       }
  45.          
  46.       $objGsm->Close();
  47.     }    
  48.   }
  49.  
  50. // HTML-CSS layout includes, no code there!
  51. include('css/Header.html');
  52. include('css/Menu.html');
  53. ?>
  54.     <div class="container">
  55.       <h1>SMS Component PHP USSD Sample</h1>
  56.       <hr />
  57.       <p>
  58.         USSD stands for Unstructured Supplementary Services Data. It is a way of sending
  59.         short commands from the mobile phone to the GSM network. It uses, like SMS, the
  60.         signalling channel of the GSM connection. Unlike SMS, it does not use a store
  61.         and forward architecture, but a session oriented connection. USSD text messages
  62.         can be up to 182 bytes in length. Messages received on the mobile phone are not
  63.         stored.
  64.       </p>
  65.       <form action="ussd.php" method="post">
  66.         <h2>SMS Component:</h2>
  67.         <h3>Build: <?php echo $objGsm->Build; ?>; Module: <?php echo $objGsm->Module; ?></h3>
  68.        
  69.         <!-- Device -->
  70.         <label for="Devices">Device:</label>
  71.         <p>
  72.           <select id="Devices" name="ddlDevices">
  73.           <?php
  74.             $strDevice = $objGsm->FindFirstDevice();
  75.            
  76.             while ($objGsm->LastError == 0)
  77.             {
  78.               echo '
  79.              <option value="'.$strDevice.'">'.$strDevice.'</option>';
  80.               $strDevice = $objGsm->FindNextDevice();
  81.             }
  82.            
  83.             $strPort = $objGsm->FindFirstPort();
  84.             while ($objGsm->LastError == 0)
  85.             {
  86.               echo '
  87.            <option value="'.$strPort.'">'.$strPort.'</option>';
  88.               $strPort = $objGsm->FindNextPort();
  89.             }
  90.           ?>
  91.           </select>
  92.         </p>
  93.        
  94.         <!-- Device Speed -->
  95.         <label for="DeviceSpeed">Device Speed:</label>
  96.         <p>
  97.           <select id="DeviceSpeed" name="ddlDeviceSpeed">
  98.             <option value="0">Default</option>
  99.             <option value="110">110</option>
  100.             <option value="300">300</option>
  101.             <option value="600">600</option>
  102.             <option value="1200">1200</option>
  103.             <option value="2400">2400</option>
  104.             <option value="4800">4800</option>
  105.             <option value="9600">9600</option>
  106.             <option value="14400">14400</option>
  107.             <option value="19200">19200</option>
  108.             <option value="38400">38400</option>
  109.             <option value="56000">56000</option>
  110.             <option value="57600">57600</option>
  111.             <option value="64000">64000</option>
  112.             <option value="115200">115200</option>
  113.             <option value="128000">128000</option>
  114.             <option value="230400">230400</option>
  115.             <option value="256000">256000</option>
  116.             <option value="460800">460800</option>
  117.             <option value="921600">921600</option>
  118.           </select>
  119.           Only applies to direct ports, i.e. COM1, COM2, etc.
  120.         </p>
  121.        
  122.         <!-- Pincode -->
  123.         <label for="Pincode">Pincode:</label>
  124.         <p>
  125.           <input type="password" id="Pincode" name="txtPincode" />
  126.           Only use when SIM card requires PIN code
  127.         </p>
  128.        
  129.         <!-- Command -->
  130.         <label for="Command">Command:</label>
  131.         <p>
  132.           <input type="text" id="Command" name="txtCommand" value="[Command]" />
  133.         </p>
  134.          
  135.         <!-- Send button -->
  136.         <div class="clearLabel"></div>
  137.         <p>
  138.           <input type="submit" name="btnSendMessage" value="Send USSD Command" />
  139.         </p>
  140.        
  141.         <!-- Empty row -->
  142.         <div class="clearRow"></div>
  143.        
  144.         <!-- Result -->
  145.         <label for="Result"><b>Result:</b></label>
  146.         <p>
  147.           <input type="text" id="Result" name="txtResult" class="FullWidth Bold" value="<?php echo $strResult; ?>" />
  148.         </p>
  149.        
  150.         <!-- Response -->
  151.         <label for="Response">Response:</label>
  152.         <p>
  153.           <input type="text" id="Response" name="txtResponse" class="FullWidth" value="<?php echo $strResponse; ?>" />
  154.         </p>
  155.       </form>
  156.       <p>
  157.         This demo uses the ActiveXperts SMS Component, an <a href="http://www.activexperts.com" target="_blank">ActiveXperts Software</a> product.<br />
  158.         <a href="index.php">Back to main page</a>
  159.       </p>
  160.     </div><!-- /container -->
  161. <?php
  162. //HTML-CSS layout include, no code there!
  163. include('css/Footer.html'); ?>
Add Comment
Please, Sign In to add comment