Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Integrate SMS Gateway API with SS

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 5076 Views
  • Yash
    Avatar
    Community Member
    3 Posts

    Integrate SMS Gateway API with SS Link to this post

    Hello Friends,
    I'm seeking for helping hand for building SMS Gateway API Script that will co-exists with

    SS and able to send User Input (ie. Sender, PhoneNumber(international format), Message Text,

    Message Type (Text only/Flash SMS etc.) using SS to SMS Gateway API @ sms.alertzap.com.

    here is copy of PHP Script which has to be worked with SS.
    ( I have purchased one bulk sms pack from alertzap.com in php script i'm going to have my

    account details. later on when user will post info this script should send URL to sms

    gateway @ sms.alertzap.com

    <?php
    $sndr = '';
    $phonenum ='';
    $message = '';
    $sndr = $_POST['sender'];
    $phonenum = $_POST['PhoneNumber'];
    $message = $_POST['text'];

    $res = sendsms ($sndr,$phonenum,$message);

       
    // Call this function when ever you wish to Send SMS
    function sendsms($sndr,$mobile,$text)
       {
       $host = "sms.alertzap.com";
       $request = "";                //initialize the request variable
       $param["user"] = "username";       //   this is the username of your SMS

    account
       $param["password"] = "password";    //this is the password of our SMS account
       $param["text"] = substr($text,0,159);    //this is the message that we want to send
       $param["PhoneNumber"] = $mobile;       //these are the recipients of the

    message
       $tmp=substr($mobile,0,4);
       
       if ($tmp=="9198" || $tmp=="9194" || $tmp=="9199" || $tmp=="9192" || $tmp=="9197")
          {
          if ($sndr != NULL)
          $sender = $sndr;
          else
          $sender = "SwiftGet.net";         // SenderID for GSM and TATA
          }
       else
          $sender= "919860609000";      // SenderID for CDMA (Reliance0
          
       $param["sender"] = $sender;
       $param["track"] = "1";
          
       foreach($param as $key=>$val)    // Traverse through each member of the param array
          {
           $request.= $key."=".urlencode($val); //we have to urlencode the values
           $request.= "&"; //append the ampersand (&) sign after each paramter/value

    pair
          }
       $request = substr($request, 0, strlen($request)-1); //remove the final ampersand

    sign from the request
       $script = "/sendsmsv2.asp";
       $request_length = strlen($request);
       $method = "POST";
    //   if ($method == "GET")
    //      {
          //$script .= "?$request";
    //      }
       //Now comes the header which we are going to post.
       $header = "$method $script HTTP/1.1\r\n";
       $header .= "Host: $host\r\n";
       $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
       $header .= "Content-Length: $request_length\r\n";
       $header .= "Connection: close\r\n\r\n";
       $header .= "$request\r\n";

       //Now we open up the connection
       $socket = @fsockopen($host, 80, $errno, $errstr);
       if ($socket) //if its open, then...
          {
           fputs($socket, $header); // send the details over
           while(!feof($socket))
              {
             $output=$output.fgets($socket); //get the results
              }
           fclose($socket);
          }

       $pos=strpos($output,"Submitted");
       if ($pos===false)
          return(0); // SMS Not Successful
       else
          return(1); // SMS Was successful
       }

       //Check Result of Sending SMS
       if ($res==1)
       {
       echo "SMS to $phonenum was successful...";
       echo "$track";
       }
       else
       {
       echo "SMS to $phonenum was not successful...";
       }

    ?>
    [\code]

    SMS Gateway API As follows:

    The post either via GET or POST needs to be done on

    http://sms.alertzap.com/sendsmsv2.asp

    The variables to be used are:

    user -> Your username on the website

    password -> Your password on the website

    sender -> Alphanumeric/Number SenderID from your approved list of SenderID's to be used for GSM Recipients

    sendercdma -> Number SenderID from your approved list of SenderID's to be used for CDMA Recipients

    PhoneNumber -> Mobile number of the recipients. for multiple recipients enter numbers seperated by comma.

    group -> (optional) The name of the group you wish to send message to. (Groups can be created and managed on the alertzap.com website.)

    text -> The text of the message. (Charged 1 unit for 160 characters per recipient.)

    flash = 1/0 -> (1) If the message should flash directly on the screen/(0)For standard SMS.

    track = 1 -> if you wish to Track the delivery status of the message. (Optional)

    A sample post to send sms would be like

    Simple Text Messages:


    Output:
    Message Submitted
    Credits Consumed: 2
    Balance Credits: 98
    Mobile=919822012345 MsgId=1177855328
    Mobile=919370119223 MsgId=1177855329

    --------------------------------------------

    Features Expected:
    1] i want to give registered users to send SMS thro this script.
    2] i want to keep copy of every sms in database with username. (optional)
    3] i want to count every users total message count. (160 chars par sms)

    Please someone help me out..

    Thank you very much for your precious time..

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Integrate SMS Gateway API with SS Link to this post

    this will be great I will make a widget out of this ;)
    so people will be able to send SMS useing their blogs

  • Yash
    Avatar
    Community Member
    3 Posts

    Re: Integrate SMS Gateway API with SS Link to this post

    when it will be available? can you share your more ideas about it? or help me with it? i need some clues to get into development..

  • Tim
    Avatar
    Core Development Team
    201 Posts

    Re: Integrate SMS Gateway API with SS Link to this post

    We've actually done a few implementations of this in the past. The main reason this code hasn't made it's way into the open source branch is because each implementation is quite different, as much of the code needs to be specific to the API's of the SMS gateway you choose.

    So in order to make a useful OS widget out of this, you'll need to pick a SMS gateway which can be used by developers all over the world (one of the reasons again we haven't released any code is we've done integration with relatively obscure SMS gateways historically)

  • Yash
    Avatar
    Community Member
    3 Posts

    Re: Integrate SMS Gateway API with SS Link to this post

    @Tim
    If widget is not possible, can you please help me with custom hack to make it work with my current SS installation? i want to make this service available for free to my small community.

    5076 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.