Integrating SMS in your web or desktop application

Web services make integrating SMS in your applications very easy. As always I would like to divide this into following steps:
Note: Here in this tutorial I am using FSMSAPI as SMS-gateway.Step 1: Get a domain name
Go and get a domain name. I personally recommend bigrock.in and set a email account by setting MX entries.

Step 2: Register on freesmsapi.com
Go to fsmsapi.com and register their. Start information will be mailed to you

Step 3: Get secret key
Login on fsmsapi.com . and get your secret key by scrolling down.

Step 4: Integration
As most web-services are technology independent , so is it. You can integrate it in any technology of your choice. Using FSMSAPI is so simple that requires only one URL request! Below goes the tech terms:

Parameters of URL
* skey – put your secret key e.g. d67ddf90df1019b0dd63b5f1842f6617
* message – proper url encoded message.
* recipient – whom to send, Can be comma seperated multiple values
* response – json or xml (default is xml)

For php:
Simply writing this works:

echo file_get_contents(“http://s1.freesmsapi.com/messages/send?skey=d67cdf98df1019b0dd63b5f1842f6617&message=”.urlencode(‘YOUR MESSAGE’).”&recipient=MOBILE_NUMBERS”);
?>

For java:
You have to write:

import java.net.*;
import java.io.*;
public class JavaGetUrl {
public static void main(String[] args) throws Exception {
URL myurl = new URL(“http://s1.freesmsapi.com/messages/send?skey=d67cdf98df1019b0dd63b5f1842f6617&message=YOUR_MESSAGE&recipient=MOBILE_NUMBER”);
BufferedReader in = new BufferedReader(
new InputStreamReader(
myurl.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}

For C#:
.netties can go via following way:

using System.IO;
using System.Net;
string connectionString = “http://s1.freesmsapi.com/messages/send?skey=d67cdf98df1019b0dd63b5f1842f6617&message=YOUR_MESSAGE&recipient=MOBILE_NUMBER”;
try
{
System.IO.Stream SourceStream = null;
System.Net.HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(connectionString);
myRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse webResponse = (HttpWebResponse)myRequest.GetResponse();
SourceStream = webResponse.GetResponseStream();
StreamReader reader = new StreamReader(webResponse.GetResponseStream());
string str = reader.ReadLine();
MessageBox.Show(str);
}
catch (Exception ex)
{       MessageBox.Show(ex.Message);
}

Step 5: My recommendations(you may or may not follow this)
For php:
Write down the above code(d’t forget to set your own skey) after wrapping in a function in a file named smssender.php and include it wherever necessary in your script files using:

 

and make a proper function call.

For java and C#:
Just make a file and include it using below and make proper function call:

import yourpackage.smssender.java;
or
using yournamespace;

If you are on another technologies, then find a equivalent inbuilt function call in your technology of choice. OR get code in SMS API section of fsmsapi.
Happy integration!
I will be happy to solve any problem during this process, let me know via comments.

Posted in SMS

2 Replies to “Integrating SMS in your web or desktop application”

Leave a Reply

Your email address will not be published. Required fields are marked *