johnmahugu

http_xml-sms

May 25th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.93 KB | None | 0 0
  1. <?php
  2.   $strXmlResult = "";
  3.   $strServerResponse = "";
  4.  
  5.   $strSystemID = "";
  6.   $strPassword = "";    
  7.  
  8.   $strUrl = "http://post.activexperts-labs.com:8080/sendsms/sendsmsHttpXML.asp";
  9.  
  10.   $strXmlTemplate = "";
  11.  
  12.   $objHttp = new COM("AxSms.Http");
  13.   $objSmsConstants = new COM("AxSms.Constants");
  14.  
  15.   GetSmsDemoAccountInfo($strSystemID, $strPassword);
  16.  
  17.   if ($strSystemID == "")
  18.   {
  19.     $strSystemID = "[SystemId]";
  20.     $strPassword = "[Password]";
  21.   }  
  22.  
  23.   //Create XML
  24.   $xmlDoc = new DOMDocument();
  25.  
  26.   $xmlRoot = $xmlDoc->createElement("httpmessage");
  27.   $xmlDoc->appendChild($xmlRoot);
  28.  
  29.   $xmlCredentials = $xmlDoc->createElement("credentials");
  30.   $xmlCredentials->setAttribute("systemid", $strSystemID);
  31.   $xmlCredentials->setAttribute("password", $strPassword);
  32.   $xmlRoot->appendChild($xmlCredentials);
  33.  
  34.   $xmlSettings = $xmlDoc->createElement("settings");
  35.   $xmlSettings->SetAttribute("bodyformat", $objSmsConstants->BODYFORMAT_TEXT);
  36.   $xmlSettings->SetAttribute("datacoding", $objSmsConstants->DATACODING_DEFAULT);
  37.   $xmlRoot->AppendChild($xmlSettings);
  38.  
  39.   $xmlMessage = $xmlDoc->CreateElement("message");
  40.   $xmlMessage->SetAttribute("toaddress", $objSmsConstants->HTTP_PLACEHOLDER_TOADDRESS);
  41.   $xmlRoot->AppendChild($xmlMessage);
  42.  
  43.   $xmlBody = $xmlDoc->CreateElement("body");
  44.   $xmlBody->nodeValue = $objSmsConstants->HTTP_PLACEHOLDER_BODY;
  45.   $xmlMessage->AppendChild($xmlBody);
  46.   $xmlRoot->AppendChild($xmlMessage);
  47.  
  48.    $strXmlTemplate = $xmlDoc->saveXML();
  49.  
  50.  
  51.   $objHttp->LogFile = sys_get_temp_dir()."HttpXml.log";
  52.   // Windows default: 'C:\Windows\Temp\HttpXml.log'
  53.  
  54.   //Form submitted
  55.   if (isset($_POST["btnSendMessage"]))
  56.   {
  57.     $objSmsMessage = new COM("AxSms.Message");
  58.    
  59.     $strSystemID = $_POST['txtSystemID'];
  60.     $strPassword = $_POST['txtPassword'];
  61.     $iDataCoding = $iDataCoding |= $objSmsConstants->DATACODING_DEFAULT;
  62.     $iBodyFormat = $objSmsConstants->BODYFORMAT_TEXT;
  63.    
  64.     $strBody = $objHttp->Base64Encode($_POST['txtBody']);
  65.     $strToAddress = $_POST['txtToAddress'];    
  66.     $strXmlToSend = stripslashes($_POST['txtXmlTemplate']);
  67.  
  68.     $strXmlToSend = str_replace($objSmsConstants->HTTP_PLACEHOLDER_TOADDRESS, $strToAddress, $strXmlToSend);
  69.     $strXmlToSend = str_replace($objSmsConstants->HTTP_PLACEHOLDER_BODY, $strBody, $strXmlToSend);
  70.    
  71.     $strUrl = $_POST['txtHost'];
  72.     $strServerResponse = $objHttp->Post($strUrl, $strXmlToSend);
  73.    
  74.     if ($objHttp->LastError != 0)
  75.     {
  76.       $strServerResponse = "ERROR: " + $objHttp->LastError . " " . $objHttp->GetErrorDescription($objHttp->LastError);
  77.     }
  78.   }
  79.  
  80.   function GetSmsDemoAccountInfo(&$strGwAccount, &$strGwPassword)
  81.   {
  82.     // NOTE: during installation of the SMS Component, a unique login and password is created for you.
  83.     // This login and password can be used to send a few SMS messages through the smpp.activexperts-labs.com gateway, for free
  84.    
  85.     $objDemoAccount = new COM("AxSms.DemoAccount");  
  86.     $strGwAccount = $objDemoAccount->SystemId;
  87.     $strGwPassword = $objDemoAccount->Password;
  88.   }
  89.  
  90. // HTML-CSS layout includes, no code there!
  91. include('css/Header.html');
  92. include('css/Menu.html');
  93. ?>
  94.     <div class="container">
  95.       <h1>SMS Component PHP HTTP XML Sample</h1>
  96.       <hr />
  97.       <p>
  98.         The HTTP protocol is used for medium volume SMS messaging. Messages are first
  99.         routed to the service provider via Internet/VPN. The provider delivers the
  100.         messages to the recipient&#39;s phone. If you are not subscribed to a provider, use
  101.         the ActiveXperts gateway to send 10 SMS messages for free.
  102.       </p>
  103.       <form action="httpxml.php" method="post">
  104.         <h2>SMS Component:</h2>
  105.         <h3>Build: <?php echo $objHttp->Build; ?>; Module: <?php echo $objHttp->Module; ?></h3>
  106.        
  107.         <!-- Host -->
  108.         <label for="Password">Host:</label>
  109.         <p>
  110.           <input type="text" id="Host" name="txtHost" value="<?php if (empty($_POST['txtHost'])) echo $strUrl; else echo $_POST['txtHost'] ?>" />
  111.         </p>
  112.        
  113.         <!-- XML Template -->
  114.         <label for="XML">XML Template:</label>
  115.         <p>
  116.             <textarea name="txtXmlTemplate" id="xmlTemplate" style="height:100px; overflow:auto;"><?php echo (empty($_POST['txtXmlTemplate'])) ? $strXmlTemplate : stripslashes($_POST['txtXmlTemplate']); ?></textarea>
  117.         </p><!--  -->
  118.        
  119.         <!-- Empty row -->
  120.         <div class="clearRow"></div>
  121.        
  122.         <!-- ToAddress -->
  123.         <label for="ToAddress">ToAddress:</label>
  124.         <p>
  125.           <input type="text" id="ToAddress" name="txtToAddress" value="<?php echo (empty($_POST['txtToAddress'])) ? "[ToAddress]" : $_POST['txtToAddress']; ?>" />
  126.           <a href="http://www.activexperts.com/support/xmstoolkit/?kb=Q4200015" target="_blank">Recipient number format</a>
  127.         </p>
  128.        
  129.         <!-- Body -->
  130.         <label for="Body">Body:</label>
  131.         <p>
  132.           <textarea id="Body" name="txtBody" style="height:45px;">Hello world send from ActiveXperts SMS Component!</textarea>
  133.         </p>
  134.        
  135.         <!-- Send button -->
  136.         <div class="clearLabel"></div>
  137.         <p>
  138.             <input type="submit" name="btnSendMessage" value="Send SMS Message!" />
  139.         </p>
  140.        
  141.         <!-- Empty row -->
  142.         <div class="clearRow"></div>
  143.        
  144.         <!-- Server Response -->
  145.         <label for="Response">Server response:</label>
  146.         <p>
  147.           <textarea name="txtServerResponse" id="Response" style="height:100px; overflow:auto;"><?php echo $strServerResponse; ?></textarea>
  148.         </p>
  149.       </form>
  150.       <p>
  151.         This demo uses the ActiveXperts SMS Component, an <a href="http://www.activexperts.com" target="_blank">ActiveXperts Software</a> product.<br />
  152.         <a href="index.php">Back to main page</a>
  153.       </p>
  154.     </div><!-- /container -->
  155. <?php
  156. //HTML-CSS layout include, no code there!
  157. include('css/Footer.html'); ?>
Add Comment
Please, Sign In to add comment