Exetel Web SMS API / PHP Class / Windows GUI (eXeSMS)

Old, inactive threads
Montaro
Posts: 59
Joined: Thu Jun 28, 2007 11:10 pm
Location: Hervey Bay, QLD
Contact:

Exetel Web SMS API / PHP Class / Windows GUI (eXeSMS)

Post by Montaro » Tue Aug 14, 2007 1:40 pm

I've been attempting to make a PHP tool to send SMS without needing to log into the exetel user facility.. But I'm having trouble finding the cookies the site expects to receive to have the user authenticated enough to allow access.

If anyone has any insights into this, I would be very appreciative.

For now it's a CLI app, not a web based script.

Code: Select all

#!/usr/bin/php -q
<?php
    $user = "usernamehere";
    $pass = "passwordhere";

    print "eXeSMS -- by Montaro\n\nMobile number (From): ";
    $from = trim(fgets(STDIN));
    print "Mobile number (To): ";
    $to = trim(fgets(STDIN));
    print "Please enter your message (160 char max) followed by the Enter key:\n";

    $msg = trim(fgets(STDIN));

    if (strlen($msg) > 160) { die("\nSorry, maximum of 160 characters per message.\n"); }

    $host = "ssl://www.exetel.com.au";
    $path = "/members/send_web_sms.php";
    $port = 443;
    //$host = "localhost";
    //$path = "/test.php";
    //$port = 80;

    $smsdata = "original_mobile_number=".urlencode($from)."&to_mobile_number=".urlencode($to)."&message=".urlencode($msg);
    $cookie = "login_name=".urlencode($user)."; password=".urlencode($pass)."; DoLogin=1";

    $data = "POST {$path} HTTP/1.1\r\n";
    $data .= "Host: www.exetel.com.au\r\n";
    $data .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-AU; rv:1.8.1) eXeSMS/1.0\r\n";
    $data .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $data .= "Content-Length: ".strlen($smsdata)."\r\n";
    $data .= "Cookie: {$cookie}\r\n";
    $data .= "Connection: close\r\n\r\n";
    $data .= $smsdata;

    print "\nConnecting to eXeTeL SMS Gateway...";
    $sock = fsockopen($host, $port, $errno, $errstr, 30);
    if (!$sock) {
        die("Failed.\n\n{$errstr} ({$errno})\n");
    }
    print "OK\nSending Message...";
    fwrite($sock, $data);
    print "OK\nReading response...\n\n";
    while (!feof($sock)) {
        print fgets($sock, 128);
    }
    fclose($sock);
?>
Last edited by Montaro on Wed Aug 22, 2007 9:45 pm, edited 3 times in total.

ForumAdmin
Posts: 3663
Joined: Sun Jan 04, 2004 2:31 pm
Location: Sydney

Post by ForumAdmin » Tue Aug 14, 2007 1:42 pm

Exetel will make an HTTPS API available shortly.

Montaro
Posts: 59
Joined: Thu Jun 28, 2007 11:10 pm
Location: Hervey Bay, QLD
Contact:

Post by Montaro » Tue Aug 14, 2007 1:48 pm

ForumAdmin wrote:Exetel will make an HTTPS API available shortly.
Do you need any help?
I see its in fairly high demand, so if you would require any assistance I'd be more than happy to help. For free of course.

My PHP one would probably work if only I knew what cookies the page was expecting to receive..

How are you thinking of approaching this?
I would be included to think perhaps even an XML API, over HTTPS of course. Or even just the ability to pass user/pass in the actual POST for the SMS sending page, instead of needing to fake a login.

User avatar
Munka
Posts: 289
Joined: Sat Oct 22, 2005 8:22 pm
Location: Rural NSW

Post by Munka » Tue Aug 14, 2007 2:21 pm

ForumAdmin wrote:Exetel will make an HTTPS API available shortly.
Excellent news, will have a look at Montaro's too in the meantime,

I have been using Pennytel for this functionality, as there are a growing number of app's to streamline features, and could be persuaded to use Exetel's if it becomes more convenient with an API.

It seems a common shortcoming that many of these hog memory, if this could be avoided.......a double plus.

Well done again Exetel, keep those new features rolling, to stay ahead of the pack :D :D
Munka

Montaro
Posts: 59
Joined: Thu Jun 28, 2007 11:10 pm
Location: Hervey Bay, QLD
Contact:

Post by Montaro » Tue Aug 14, 2007 2:55 pm

Munka wrote:I have been using Pennytel for this functionality, as there are a growing number of app's to streamline features, and could be persuaded to use Exetel's if it becomes more convenient with an API.
As soon as an API comes out I'll (hopefully) be the first one to bring out two apps.

Actually three.

Firstly finish my CLI PHP app, then make a web-based (secured obviously) one, and finally a windows application.

The day the API comes out, I should have all those three finished in that day also.. won't take too long at all. :)

Looking forward to it!

[edit]
also might get bored and do a gtk app :P
and the windows app will probably come before the web-based one.
[/edit]

Luddenham
Posts: 1
Joined: Tue Aug 14, 2007 1:32 pm
Location: Luddenham

API Availability

Post by Luddenham » Tue Aug 14, 2007 9:29 pm

ForumAdmin wrote:Exetel will make an HTTPS API available shortly.
I can't wait! 5 years ago I wrote a PHP SMS client sending 8 cent not 100% reliable messages from overseas.

Earlier this afternoon someone queried the possibility of Exetel providing a (paid for) outbound number - a number to reply to (and perhaps sound files could be emailed to a specific address). That would be nice. . .

ForumAdmin
Posts: 3663
Joined: Sun Jan 04, 2004 2:31 pm
Location: Sydney

Re: API Availability

Post by ForumAdmin » Wed Aug 15, 2007 7:40 am

Luddenham wrote:
ForumAdmin wrote:Exetel will make an HTTPS API available shortly.
I can't wait! 5 years ago I wrote a PHP SMS client sending 8 cent not 100% reliable messages from overseas.

Earlier this afternoon someone queried the possibility of Exetel providing a (paid for) outbound number - a number to reply to (and perhaps sound files could be emailed to a specific address). That would be nice. . .
It will be possible to provide paid for numbers and the costings are being established.

Montaro
Posts: 59
Joined: Thu Jun 28, 2007 11:10 pm
Location: Hervey Bay, QLD
Contact:

Post by Montaro » Sat Aug 18, 2007 12:35 am

thanks to the new api
the php cli app is working right
i didnt realise until about 15mins ago that the api was out :P

ill clean it up and post it tomorrow
and ill work on a windows app aswell

Montaro
Posts: 59
Joined: Thu Jun 28, 2007 11:10 pm
Location: Hervey Bay, QLD
Contact:

Post by Montaro » Sun Aug 19, 2007 3:28 pm

I've written a PHP class that can be used by developers to send SMS from their websites. This is extremely useful for sending things like authorization codes, site updates, or just general customer/staff communications.

Documentation

First create the class object

Code: Select all

$sms = new eXeSMS();
Now you need to setup the details for authentication to the Exetel SMS gateway

Code: Select all

$sms->SetUserPass("myusername", "mypassword");
Then tell the class the details of where the SMS is going, where its from, and the message contents. Note; all the below functions will return false if they are above the length limit (11 for numbers, 160 for message), otherwise they will return true. You could add an if conditional in order to check this as you go along.

Code: Select all

$sms->SetToNumber("0123456789")
$sms->SetFromNumber("9876543210");
$sms->SetMessage("hello from eXeSMS class!");
Now you need to send the SMS. This is done with the SendSMS() function, this function returns either: -1 for not enough information (see above two steps), -2 for failure to connect to SMS gateway, or an array with the results of the SMS sending status (explained below).

Code: Select all

$result = $sms->SendSMS();
If SendSMS() returns an array, it will be like follows:

Code: Select all

    status => 0 for rejected, 1 for sent, 2 for failed.
    destination => the mobile number passed by SetToNumber()
    reference => the internal reference we used
    exetel_id => Exetel's reference number
    exetel_notes => Some textual notes on the status (ie. OK)
Here is the PHP class:
exesms.class.php

Code: Select all

<?php

    define("ERROR_SMS_INVALIDINFO", "-1");
    define("ERROR_SMS_CONNECT", "-2");

    class eXeSMS {
        var $sms_username;
        var $sms_passwd;
        var $sms_tonumber;
        var $sms_fromnumber;
        var $sms_message;

        function SetUserPass($user, $pass) {
            $this->sms_username = $user;
            $this->sms_passwd = $pass;
        }

        function SetToNumber($tonum) {
            if (strlen($tonum) > 11) { return false; }
            else {
                $this->sms_tonumber = $tonum;
                return true;
            }
        }

        function SetFromNumber($fromnum) {
            if (strlen($fromnum) > 11) { return false; }
            else {
                $this->sms_fromnumber = $fromnum;
                return true;
            }
        }

        function SetMessage($msg) {
            if (strlen($msg) > 160) { return false; }
            else {
                $this->sms_message = $msg;
                return true;
            }
        }

        function SendSMS() {
            if ((!isset($this->sms_username)) || (!isset($this->sms_passwd)) || (!isset($this->sms_tonumber)) || (!isset($this->sms_fromnumber)) || (!isset($this->sms_message))) {
                return ERROR_SMS_INVALIDINFO;
            }
            else {
                $host = "ssl://www.exetel.com.au";
                $path = "/sendsms/api_sms.php";
                $port = 443;

                $refnum = "";
                for ($i = 0; $i < 10; $i++) {
                    $refnum .= rand(0,9);
                }

                $smsdata = "username=".urlencode($this->sms_username)."&password=".urlencode($this->sms_passwd)."&sender=".urlencode($this->sms_fromnumber)."&mobilenumber=".urlencode($this->sms_tonumber)."&message=".urlencode($this->sms_message)."&messagetype=Text&referencenumber=".urlencode($refnum);

                $data = "POST {$path} HTTP/1.1\r\n";
                $data .= "Host: www.exetel.com.au\r\n";
                $data .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-AU; rv:1.8.1) eXeSMS/1.0\r\n";
                $data .= "Content-Type: application/x-www-form-urlencoded\r\n";
                $data .= "Content-Length: ".strlen($smsdata)."\r\n";
                $data .= "Connection: close\r\n\r\n";
                $data .= $smsdata;

                $sock = fsockopen($host, $port, $errno, $errstr, 30);
                if (!$sock) {
                    return ERROR_SMS_CONNECT;
                }
                else {
                    fwrite($sock, $data);
                    $ret = "";
                    while (!feof($sock)) {
                        $ret .= fgets($sock, 128);
                    }
                    fclose($sock);
                    list($headers, $body) = explode("\r\n\r\n", $ret);
                    $body = trim($body);
                    $junk = explode("\n", $body);
                    $result = $junk[1];
                    unset($junk);
                    unset($body);
                    $result = str_replace("<br>", "", $result);
                    $retval = explode("|", $result);
                    $status = array(
                                    "status" => $retval[0],
                                    "destination" => $retval[1],
                                    "reference" => $retval[2],
                                    "exetel_id" => $retval[3],
                                    "exetel_notes" => $retval[4]);
                    return $status;
                }
            }
        }
    }
?>
Here is also a primitive CLI test application:
exesms.test

Code: Select all

#!/usr/bin/php
<?php
    error_reporting(E_ALL);
    require_once("exesms.class.php");
    $sms = new eXeSMS();
    $sms->SetUserPass("myuser", "mypass");
    $sms->SetToNumber("0123456789");
    $sms->SetFromNumber("9876543210");
    $sms->SetMessage("hello from eXeSMS class!");
    $result = $sms->SendSMS();
    if ($result == -1) { die("Invalid information was passed to the class.\n"); }
    elseif ($result == -2) { die("Failed to connect to SMS gateway\n"); }
    else {
        print_r($result);
    }
?>
I hope someone can find this useful.
Would like to hear tips, bug fixes, ideas, etc.

Montaro
Posts: 59
Joined: Thu Jun 28, 2007 11:10 pm
Location: Hervey Bay, QLD
Contact:

Post by Montaro » Sun Aug 19, 2007 3:33 pm

Well I think even a trained monkey can work from that PHP class to make it into whatever they like so I won't bother to post my actual PHP CLI app.. since its basically just a whole heap of trim(fgets(STDIN)) to read the information into a variable and pass it to the class. I'm sure anyone would do that themselves ;)

I'm starting work on the windows GUI app now.
Wish me luck :D

Any idea who I need to specifically ask in order to gain permission to use the Exetel logo in my application? Thought it might be a nice touch considering its going to useless for any other provider except Exetel.

Montaro
Posts: 59
Joined: Thu Jun 28, 2007 11:10 pm
Location: Hervey Bay, QLD
Contact:

Post by Montaro » Mon Aug 20, 2007 12:13 am

Windows GUI app is nearly finished, just having a few issues with the OpenSSL library, once the problem is ironed out i'll post a link.

In the mean time.. some screenshots:

Main window
Image

Setup window
Image

Log window
Image

Montaro
Posts: 59
Joined: Thu Jun 28, 2007 11:10 pm
Location: Hervey Bay, QLD
Contact:

Post by Montaro » Mon Aug 20, 2007 4:51 am

eXeSMS, the Windows GUI application for the Exetel SMS API is OUT!

I guess its only beta, so please try it out and comment back on changes I need to make!

Enjoy!

http://www.montarotech.net/projects/eXeSMS

Montaro
Posts: 59
Joined: Thu Jun 28, 2007 11:10 pm
Location: Hervey Bay, QLD
Contact:

Post by Montaro » Mon Aug 20, 2007 9:42 pm

eXeSMS (Exetel SMS Windows GUI Interface) version 1.1 is out.

Fixed a few bugs
Few cosmetic changes
and a fully functional address book system

Next I plan to handle bulk SMS. I don't like the idea of 7c per sms when I'm testing the bulk sms feature lol :P

Anyway here is the link: http://www.montarotech.net/projects/eXeSMS

Direct download link here too if you are feeling lazy: http://www.montarotech.net/includes/pro ... S&type=bin

Would appreciate any suggestions or bug fixes..

User avatar
ottyacat
Posts: 159
Joined: Fri Mar 24, 2006 9:41 pm
Location: Mornington, VIC

Post by ottyacat » Mon Aug 20, 2007 11:20 pm

Hello Montaro,

This is a great little APP, thanks :D

One minor bug fix is the exit from the file menu doesn't work.

Cheers

Montaro
Posts: 59
Joined: Thu Jun 28, 2007 11:10 pm
Location: Hervey Bay, QLD
Contact:

Post by Montaro » Tue Aug 21, 2007 12:39 am

ottyacat wrote:Hello Montaro,

This is a great little APP, thanks :D

One minor bug fix is the exit from the file menu doesn't work.

Cheers
hahaha oh my god
i cant believe I forgot that :P

I dont think I'll bother reposting another release for that fix
ill just make sure its done for the next major one (bulk sms inclusion)

Post Reply