I was presented with a problem the other day, regarding SMS’s. While Sara is overseas, her pre-paid mobile phone is on international roaming. While this means she can receive sms’s like normal, at no extra charge to the sender or her, it means that for her to send an SMS, it costs 65c. Now 65c per message starts adding up really quickly, especially if it’s a long message (so concatenated sms). And when your normal rate is 25c to anyone on another network, or cheaper to anyone on your network, it seems rather costly. But on the plus side, her mobile data packs costs the same as in Australia.
So naturally my brain started to think about ways to reduce her messaging cost, and the answer was simple, use the internet on her phone. I had heard that this mobile provider had a computer program for sending messages as if they had come from your mobile, at your normal cost. So what if I can rig it up, so she can write a message, and using this program, send the message and get it for the cheaper rate.
Well it works, but unfortunately the program is windows only, and it means you need a computer. That’s no good for normal messaging. So what did I do? What any geek in my position would do naturally.Â I observed. Quite simply, I observed what the program did. Of course, I didn’t just look at the screen while using the program, I also looked at what it did behind the scenes, in particular on the network (internet). As it uses SSL (HTTPS) it wasn’t the easiest thing to observe, but my perseverance paid off, and soon I had a transcript of the program talking to the server. Thankfully it was a rather simple conversation, using XML, and no fancy hand shakes. A single XML POST request would authenticate the user, and send a message, with a simple XML reply. So I didn’t have to worry about doing an authentication, keeping a cookie, or a fancy hash or something, and then working more fancy magic to send a message. A simple template XML request, fill in the blanks, and submit, and the server would send the message and give back an XML reply saying that the message was sent. A very simple API. And I didn’t have to reverse engineer anything to work it out.
Of course, the next step was to write a simple program that could be used on the phone to send a message via the API.Â The most basic of programs can be written in about 5 lines in PHP, but of course I needed it to be easy to use, with some security, so I’ve gone a little beyond the most basic. I present a simple form, a drop down to select the number to send to (to keep it secure, so that only predefined numbers can be sent to), a box to type the message, an input field for a security password, and a submit button. Of course, then below when you hit submit, it gives you feed back with the message length, it lets you know that it’s trying to connect to the API server, when it’s connected it sends it, and lets you know the results. Probably more feedback than is needed, but what the heck, it’s not for public use.
Now for anyone else wanting to do something similar, I’ll help you along a little, by providing some of the required components, namely the XML templates. You’ll have to work out how to use them, write your own software to use them, and also what the server is. Oh, and what the phone company is. I’m not going to risk some phone company getting upset at me, so nothing I provide will apply specifically to some phone company. It could be any one of them. If you work out the phone company, and contact me through the contact page, I’m probably more than willing to assist you in filling in the blanks, to save you some trouble. Or letting you know a way to fill them in yourself.
The POST request with xml template. You can see all the variables that need to be filled in. You may also be able to omit some things and simplify it. I did do some tests and you can simpify it a lot. A word of note, $userid is not your phone number, when you register for the service, there is an internet ID associated with your number, which you use for logging in. Discovering that is another thing I’ll leave up to you. $messagetype is ether “text” or “text/concatenated” if the message is longer than 160 chars, otherwise it’ll be cut off. There is a total message length limit for concatenated messages, of about 450 letters. You’ll also have to work out the page it submits to, the useragent (which may not be needed), and the host it submits it all to.
POST /OAK/$page HTTP/1.0 User-Agent: $useragent Cache-Control: no-cache Content-Length: $length <sms><authentication user="$userid" password="$userpassword" client_app="$appname"><product name="$appname"/> </authentication><message from="$usernumber" type="$messagetype" responseDetail="3" action="send"><content> <![CDATA[$message]]></content><message to="$number"/></message></sms>
A XML reply when the message is sucessfully sent looks like this.
HTTP/1.0 200 OK Content-Type: text/xml Content-Length: 167 <sms> <authentication> <product></product> </authentication> <message ref="1" status="0"> <content></content> <message ref="2" status="0"></message> </message> </sms>