Примеры интеграции

PHP


Код отправки сообщения:

    <?php
        require("smshost.php");
        try{
            $result=sendSms($_GET["receiverAddress"], $_GET["messageText"]);
            print_r($result);
        } catch (SoapFault $fault) { 
            echo "SmsHost returned the following ERROR: ".$fault->faultcode."-".$fault->faultstring."."; 
        }
    ?>

smshost.php (для PHP версии 5.0.1 и выше):

    <?php 
        function guid(){
            if (function_exists('com_create_guid')){
                return com_create_guid();
            }else{
                mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
                $charid = strtoupper(md5(uniqid(rand(), true)));
                $hyphen = chr(45);// "-"
                $uuid = chr(123)// "{"
                        .substr($charid, 0, 8).$hyphen
                        .substr($charid, 8, 4).$hyphen
                        .substr($charid,12, 4).$hyphen
                        .substr($charid,16, 4).$hyphen
                        .substr($charid,20,12)
                        .chr(125);// "}"
                return $uuid;
             }
        }
        
        function sendSms($receiverAddress, $messageText){
            $login="логин";
            $password="пароль";
            $validityPeriod="000000010000000R";
            $senderAddress="SMS-Host.ru";
            
            $soapClient = new SoapClient("https://sms-host.ru/Service/SmsHostWs.asmx?WSDL"); 
        
            // Prepare SoapHeader parameters 
            $sh_param = array( 
                      'User'        =>    $login, 
                      'Password'    =>    $password
                    ); 
            $headers = new SoapHeader('http://sms-host.ru/', 'Authentication', $sh_param); 
            
            // Prepare Soap Client 
            $soapClient->__setSoapHeaders(array($headers)); 
            
            // Setup the RemoteFunction parameters 
            $submitSm=array(
                        "MessageId"             => guid(),
                        "ReceiverAddress"         =>  $receiverAddress,
                        "SenderAddress"         => $senderAddress,
                        "MessageText"             => $messageText,
                        "ValidityPeriodSmpp"     => $validityPeriod
                    );
            $submitSmCollection=array("WsSubmitSm" => $submitSm);
        
            // Call SumbitSm() 
            $result = $soapClient->SumbitSm(array("messageList" => $submitSmCollection));
            unset($soapClient); 
            return $result;
        }
    ?>
 

smshost.php (для более ранних версий):

    <?php 
    
    function guid(){
        if (function_exists('com_create_guid')){
            return com_create_guid();
        }else{
            mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
            $charid = strtoupper(md5(uniqid(rand(), true)));
            $hyphen = chr(45);// "-"
            $uuid = chr(123)// "{"
                    .substr($charid, 0, 8).$hyphen
                    .substr($charid, 8, 4).$hyphen
                    .substr($charid,12, 4).$hyphen
                    .substr($charid,16, 4).$hyphen
                    .substr($charid,20,12)
                    .chr(125);// "}"
            return $uuid;
        }
    }
    
    function sendSMSMessage($messageText, $receiverAddress){
    
    $request="<?xml version=\"1.0\" encoding=\"utf-8\"?> 
    <soap:Envelope 
        xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 
        xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" 
        xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
      <soap:Header>
        <Authentication xmlns=\"http://sms-host.ru/\">
          <User>логин</User>
          <Password>пароль</Password>
        </Authentication>
      </soap:Header>
      <soap:Body>
        <SumbitSm xmlns=\"http://sms-host.ru/\">
            <messageList>
            <WsSubmitSm 
                ValidityPeriodSmpp=\"000000010000000R\" 
                MessageText=\"".iconv("WINDOWS-1251","UTF-8",$messageText)."\" 
                SenderAddress=\"Имя отправителя\" 
                ReceiverAddress=\"".$receiverAddress."\" 
                MessageId=\"".substr(guid(),1,36)."\" />
          </messageList>
        </SumbitSm>
      </soap:Body>
    </soap:Envelope>";
    
    $ch=curl_init("https://sms-host.ru/service/smshostws.asmx");
    $header = Array("POST /service/smshostws.asmx HTTP/1.1", "Host: sms-host.ru", 
            "Content-Type: text/xml; charset=utf-8", 
            "Content-Length: ".strlen($request),
            "SOAPAction: \"http://sms-host.ru/SumbitSm\"");
    
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_PORT, 443); 
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_POST,1); 
    curl_setopt($ch, CURLOPT_TIMEOUT,10); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
    
    $data = curl_exec($ch);
    echo $data."\n";
    }
    
    ?>