Hi all

I'm building a two-way SMS (mobile short message) service using a 3rd party SMS gateway over SOAP.

I've managed to get outgoing messages (web to phone) working nicely using PHP5's built in SoapClient object - that's all fine.

I'm now trying to work out how to recieve and process mobile-originated messages via the SMS gateway. The documentation says that "The SOAP connection is made over an HTTP connection using the POST command. " Trouble is, I'm not sure what this means in reality and how to actually deal with it using PHP5 etc. I'm guessing I do something like:

if ($_SERVER['REQUESTMETHOD']=='POST')
{
// do something SOAPy, not sure what.
}

😕

Can anyone point me in the right direction for more help on this? Do I need to write a SOAP server of some kind??

Any tips greatly appreciated. If you're interested, the doc is here: SMS to SOAP API

Many thanks,

sim

    note that all variables passed to a script in an HTTP POST request are in the array $_POST... so try this, it should give you the first start:

    echo print_r($_POST);

    I don't know a lot about the SOAP stuff in PHP but I suspect you can probably pass it the $_POST array (maybe with some massaging) to have it parsed/processed.

    best,
    Eric

      Hi Eric,

      That's a speedy reply - thanks! Yes, that sounds like a good start and I'm already trying something along those lines:

      // TEST SCRIPT TO LOG INCOMING REQUESTS
      if ($_SERVER['REQUEST_METHOD']=='POST')
      {
      	$fp = fopen("..../sms_log.txt", "w");
      	if (!$fp) die("Unable to create file.");
      
      ob_start();
      var_dump($_POST);
      $data = ob_get_clean();
      fwrite($fp, $data."\n");	
      fclose($fp);
      }
      

      It's not doing anything yet for some reason so I'll have to play with it a little more.

      Cheers,

      sim

        hey, excellent debugging technique; you'll have some good visibility into what's happening now.

        fwiw note that error_log will do all the fopen, fwrite, etc for you:

        error_log(var_export($_POST)."\n\n", 3, "..../sms_log.txt");

        the '3' means "send it to the file I specify"... sweet!

        E

          Thanks for the 'error_log' tip Eric - didn't know about that one!

          My latest effort, based on an example in my O'Reilly book ('Upgrading to PHP5') :

          function DeliverMessage($username,$pin,$recipient,$message,$reply_to)
          {
          	ob_start();
          	var_dump($username);
          	var_dump($pin);
          	var_dump($recipient);
          	var_dump($message);
          	var_dump($reply_to);
          	$data = ob_get_clean();
          
          error_log($data."\n", 3, "..../sms_log.txt"); 
          
          $ret = array('MessageIdentifier'=>'','Report'=>'0','Text'=>'OK');
          return $ret;			
          }
          
          $server = new SoapServer("http://www.csoft.co.uk/dtd/sendsms4.wsdl");
          $server->addFunction('DeliverMessage');
          $server->handle();
          
          

          No joy yet though. I fully accept I may have got this hideously wrong - I'm shooting blind here. Will keep fiddling anyway. (At this rate I can see this is going to cost me a small fortune in losts test SMSs :bemused: )

          sim

            use curl it'll be much easier and this kind of stuff is what it is intended for [man]curl[/man]

              hmm, note that cURL is disappearing in PHP5 and if you're getting SOAP-formated msgs then the SOAP library is really the right way to go, isn't it?

              simonk- re having to test the SMS messages yourself :-) keep in mind you can make a simple HTML form (with form action='post') that mimics exactly what the SMS gateway would be POSTing to your script. voila, no more SMSing, just type something into the form and click 'submit' for your receiver script to have data to test with.

              E

                drawmack - thanks for the heads-up. I haven't got into curl yet and whilst I've got my hands full with this SOAP stuff (which is just one small part of a much bigger project) I'm reluctant to open a whole new can of worms at this stage! 😃

                Eric - you're right about the text form idea. I did that in fact to check that my rudimentary logging was working (it was). But there must be something different about the soap request because no logging occurs when I try the sms service.

                The SMS Gateway co I'm using (c-soft) also offers message delivery over old-skool HTTP POST form submission (as opposed to this SOAP via POST which isn't working). I tried it and it worked first time out! Bearing in mind the often neglected KISS principle, is there any reason why I should persist with this SOAP stuff over simple POST form data. Performance?? All I really want to do is read an incoming SMS message and store it in a database. What do you guys think?

                sim

                  Write a Reply...