Posts

Bulk Mobile SMS APIs – Application Programming Interface for Automated Messaging

Bulk SMS APIs – Application Programming Interface for Automated Messaging

An Application Programming Interface (SMS APIs) is one way to connect to Resellers Core Messaging Platform. SMS API provides an easy, efficient and flexible option to integrate with your website / application, facilitating auto-generated SMS Text messages to be delivered to the intended recipients mobile phones. This method does not require Resellers Software Platform at your Enterprise/Data Center site. Accessing gateway through HTTP API is one of the best and the quickest ways to deliver SMS messages. The HTTP API can be used to send various types of SMS messages including normal text messages and Unicode messages only by providing few parametersUser-username,password,mobilenumber,message,senderid,mtype=N for normal message and mtype=L for language sms.

Sending a Single MessageTo send a single message of any type (normal text messages, Unicode messages), the gateway requires parameters like User and Passwd for authentication purpose in below URL formathttp://domainname/WebServiceSMS.aspx?User=xxxxxx&passwd=xxxxxxxxxxxx&mobilenumber=xxxxxxxxxx&message=xxxxxxxxx&sid =xxxxxxxx&mtype=N

For sending Bulk SMS messages, the following URL, along with the required parameters, needs to be accessed –http://domainname/WebServiceSMS.aspx?User=xxxxxx&passwd=xxxxxxxxx&mobilenumber=xxxxxxx,xxxxxxx,xxxxxxxxx&message=xx xxxxxxx&sid=xxxxxxxx&mtype=N

For sending Remainder SMS messages, the following URL, along with the required parameters, needs to be accessed – http://domainname/WebService_RemainderSMS.aspx?User=xxxx&Passwd=xxxx&message=xxxxxxx&mobilenumber=xxxxxxxxxx,xxxxxxxxxx&sendername=xxxx&remname=xxxx&remddate=mm/dd/yyyy Hr:Min:Sec AM/PM&predate=mm/dd/yyyy Hr:Min:Sec AM/PM&mtype=N

Sample URL for Delivery Reports-http://domainname/SMSCWebService_SMS_GetDR.aspx?user=xxxx&pwd=xxxx&fromdate=xxxx&todate=xxxx&jobno=xxxx

Sample URL for Getting Balance Credits– http://domainname/Webservicesms_get_userbalance.aspx?user=xxxx&passwd=xxxx

 

For sample codes click here

 

                            VB.NET CODE

 

Imports System.Data

Imports System.IO

Imports System.Configuration

Imports System

Imports System.Net

Imports System.Text

 

 Public Function SendSMS(ByVal User As String, ByVal password As String, ByVal Mobile_Number As String, ByVal Message As String, Optional ByVal MType As String = “N”) As String

        Dim stringpost As String = “User=” & User & “&passwd=” & password & “&mobilenumber=” & Mobile_Number & “&message=” & Message & “&MTYPE=” & MType

        ‘Response.Write(stringpost)

        Dim functionReturnValue As String = Nothing

        functionReturnValue = “”

 

        Dim objWebRequest As HttpWebRequest = Nothing

        Dim objWebResponse As HttpWebResponse = Nothing

        Dim objStreamWriter As StreamWriter = Nothing

        Dim objStreamReader As StreamReader = Nothing

 

        Try

            Dim stringResult As String = Nothing

 

        objWebRequest = DirectCast(WebRequest.Create(“http://Domain name/WebserviceSMS.aspx”), HttpWebRequest)

 //domain name: Domain name Replace With Your Domain 

            objWebRequest.Method = “POST”

 

            ‘ Response.Write(objWebRequest)

 

            ‘ Use below code if you want to SETUP PROXY.

            ‘Parameters to pass: 1. ProxyAddress 2. Port

            ‘You can find both the parameters in Connection settings of your internet explorer.

 

            ‘ If you are in the proxy then Uncomment below lines and enter IP and Port.

           ‘ Dim myProxy As New Net.WebProxy(“192.168.1.108”, 6666)

            ‘myProxy.BypassProxyOnLocal = True

            ‘objWebRequest.Proxy = myProxy

 

            objWebRequest.ContentType = “application/x-www-form-urlencoded”

 

            objStreamWriter = New StreamWriter(objWebRequest.GetRequestStream())

            objStreamWriter.Write(stringpost)

            objStreamWriter.Flush()

            objStreamWriter.Close()

 

            objWebResponse = DirectCast(objWebRequest.GetResponse(), HttpWebResponse)

 

 

            objWebResponse = DirectCast(objWebRequest.GetResponse(), HttpWebResponse)

 

            objStreamReader = New StreamReader(objWebResponse.GetResponseStream())

            stringResult = objStreamReader.ReadToEnd()

            objStreamReader.Close()

            Return (stringResult)

        Catch ex As Exception

            Return (ex.ToString)

        Finally

 

            If (objStreamWriter IsNot Nothing) Then

                objStreamWriter.Close()

            End If

            If (objStreamReader IsNot Nothing) Then

                objStreamReader.Close()

            End If

            objWebRequest = Nothing

            objWebResponse = Nothing

 

        End Try

    End Function

 

    Protected Sub btnsubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsubmit.Click

        Dim str As String

        str = SendSMS(Trim(User1.Value), Passwd.Value, mobilenumber.Value, message.Value)

        Response.Write(str)

    End Sub

 

                                CSHARP CODE

  

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Configuration;
using System.Net;
using System.Text;
using System.Net;

 

 public string SendSMS(string User, string password, string Mobile_Number, string Message, [System.Runtime.InteropServices.OptionalAttribute, System.Runtime.InteropServices.DefaultParameterValueAttribute("N")]  // ERROR: Optional parameters aren't supported in C#
string MType)
            {
        string stringpost = "User=" + User + "&passwd=" + password + "&mobilenumber=" + Mobile_Number + "&message=" + Message + "&MTYPE=" + MType;
        //Response.Write(stringpost)
                string functionReturnValue = null;
                functionReturnValue = "";
        
                HttpWebRequest objWebRequest = null;
                HttpWebResponse objWebResponse = null;
                StreamWriter objStreamWriter = null;
                StreamReader objStreamReader = null;
        
                try {
                    string stringResult = null;
        
                 objWebRequest = (HttpWebRequest)WebRequest.Create("(http://Domain name/WebserviceSMS.aspx");
                        //domain name: Domain name Replace With Your Domain  
                    objWebRequest.Method = "POST";
        
                    // Response.Write(objWebRequest)
        
                    // Use below code if you want to SETUP PROXY.
                    //Parameters to pass: 1. ProxyAddress 2. Port
                    //You can find both the parameters in Connection settings of your internet explorer.
                    
                    
                    // If You are In the proxy Then You Uncomment the below lines and Enter IP And Port Number
        
             
                    //System.Net.WebProxy myProxy = new System.Net.WebProxy("192.168.1.108", 6666);
                    //myProxy.BypassProxyOnLocal = true;
                    //objWebRequest.Proxy = myProxy;
        
                    objWebRequest.ContentType = "application/x-www-form-urlencoded";
        
                    objStreamWriter = new StreamWriter(objWebRequest.GetRequestStream());
                    objStreamWriter.Write(stringpost);
                    objStreamWriter.Flush();
                    objStreamWriter.Close();
        
                    objWebResponse = (HttpWebResponse)objWebRequest.GetResponse();
        
         
                    objWebResponse = (HttpWebResponse)objWebRequest.GetResponse();
        
                    objStreamReader = new StreamReader(objWebResponse.GetResponseStream());
                    stringResult = objStreamReader.ReadToEnd();
                    objStreamReader.Close();
                    return (stringResult);
                } catch (Exception ex) {
                    return (ex.ToString());
        
                } finally {
                    if ((objStreamWriter != null)) {
                        objStreamWriter.Close();
                    }
                    if ((objStreamReader != null)) {
                        objStreamReader.Close();
                    }
                    objWebRequest = null;
                    objWebResponse = null;
        
                }
            }
        
            protected void btnsubmit_Click(object sender, System.EventArgs e)
            {
                string str = null;
                str = SendSMS(User.Value, Passwd.Value, mobilenumber.Value, message.Value,"N");
                Response.Write(str);
            }

 

                            PHP CODE

 

<?php
//Please Enter Your Details
 $user="XXXXXX"; //your username
 $password="XXXXXX"; //your password
 $mobilenumbers="919XXXXXXXXX"; //enter Mobile numbers comma seperated
 $message = "test messgae"; //enter Your Message
 $senderid="DEMO"; //Your senderid
 $messagetype="N"; //Type Of Your Message
$url="http://Domain name)/WebserviceSMS.aspx";
 //domain name: Domain name Replace With Your Domain  
 $message = urlencode($message);
 $ch = curl_init();
 if (!$ch){die("Couldn't initialize a cURL handle");}
 $ret = curl_setopt($ch, CURLOPT_URL,$url);
 curl_setopt ($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);          
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
 curl_setopt ($ch, CURLOPT_POSTFIELDS,
"User=$user&passwd=$password&mobilenumber=$mobilenumbers&message=$message&sid=$senderid&mtype=$messagetype");
 $ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  

//If you are behind proxy then please uncomment below line and provide your proxy ip with port.
// $ret = curl_setopt($ch, CURLOPT_PROXY, "PROXY IP ADDRESS:PORT");

   

 $curlresponse = curl_exec($ch); // execute
if(curl_errno($ch))
        echo 'curl error : '. curl_error($ch);

 

 if (empty($ret)) {
    // some kind of an error happened
    die(curl_error($ch));
    curl_close($ch); // close cURL handler
 } else {
    $info = curl_getinfo($ch);
    curl_close($ch); // close cURL handler
    //echo "<br>";
        echo $curlresponse;    //echo "Message Sent Succesfully" ;
   
 }
?>

 

XML API

XML SUBMIT URL (SENDING SINGLE MESSAGE To MULTIPLE MOBILENUMBERS)

To send SMS using XML the user has to create an interface (form) having a form element with name as ‘XML_DATA’.

e.g. <input name=”XML_DATA” type=”text”>

Post/Submit your case-sensitive XML through that form as HTTP post to the following URL: http://domainname/WebServicexmlapi.aspx

ILLUSTRATIVE EXAMPLE
<reseller>
<sendMsg>
<user>xxxxx</user>
<passwd>xxxxx</passwd>
<to>91988xxxxx,919848xxxxxxxx</to>
<sid>demo</sid>
<text>Hi! Hru?</text>
<DR>Y</DR>
<MTYPE>N</MTYPE>
</sendMsg>
</reseller>
Description of the XML format: –

S. NO

PARAMETER NAME

PARAMETER VALUE

PARAMETER DESCRIPTION

1.

User

xxxxx

User name of the account

2.

Passwd

xxxxx

Password of the account

3.

To

9198xxxx

Destination Mobile Number

4.

Sid

demo

Name of the Sender / Sender-Id

5.

Text

Hi!H r u?

Message to be send

6.

DR

Y

Delivery Report Required

7.

MTYPE

N

Type of message
(U for Unicode, N for normal text, P for picture messages)

 

 

ASP

' This is  ASP sample code

 

<%@ ENABLESESSIONSTATE = False %>
<% option explicit %>

 

<%

 

 Dim objXMLHTTP, sRemoteURL,posturl

 

'Create & initialize the XMLHTTP object
Set objXMLHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
sRemoteURL = "http://Domain name/WebserviceSMS.aspx"

 

'Open the connection to the remote server
objXMLHTTP.Open "POST", sRemoteURL
objXMLHTTP.setProxy 2, "192.168.1.108:6666"'If you are behind proxy please mention the proxy ip with port. Or just comment this particular line...
objXMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

 

posturl = "User=xxxx&passwd=xxxx&mobilenumber=919xxxxxxxxx&message=xxxx&sid=xxxx&mtype=N&DR=Y"
objXMLHTTP.setRequestHeader "Content-Length",LEN(posturl)
'Send the request to the eProcessingNetwork Transparent Database Engine
objXMLHTTP.Send  posturl

 

'store the response
response.Write (objXMLHTTp.responseText)

  

%>

 

 

JAVA

 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Properties;

 

public class CallSmscApi {

 

        public CallSmscApi() {

 

        }       
        /*      
    1   Create a URL.
        2       Retrieve the URLConnection object.
        3       Set output capability on the URLConnection.
        4       Open a connection to the resource.
        5       Get an output stream from the connection.
        6       Write to the output stream.
        7       Close the output stream.
        */
        public static void main( String[] args) throws Exception{
               String postData="";
               String retval = "";

 

               //give all Parameters In String
               String User ="User_Name";
               String passwd = "Password";
               String mobilenumber = "Mno1,Mno2,,,,Mnon";
               String message = "SMS MEssage";
               String sid = "Sender_Id";
               String mtype = "N";
               String DR = "Y";               

 

               
               
               postData += "User=" + URLEncoder.encode(User,"UTF-8") + "&passwd=" + passwd + "&mobilenumber=" + mobilenumber + "&message=" + URLEncoder.encode(message,"UTF-8") + "&sid=" + sid + "&mtype=" + mtype + "&DR=" + DR;
               URL url = new URL("http://Domain Name/WebserviceSMS.aspX");
               HttpURLConnection urlconnection = (HttpURLConnection) url.openConnection();

 

               // If You Are Behind The Proxy Server Set IP And PORT else Comment Below 4 Lines
               //Properties sysProps = System.getProperties();
               //sysProps.put("proxySet", "true");
               //sysProps.put("proxyHost", "Proxy Ip");
               //sysProps.put("proxyPort", "PORT");

 

               urlconnection.setRequestMethod("POST");
               urlconnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
               urlconnection.setDoOutput(true);
               OutputStreamWriter out = new OutputStreamWriter(urlconnection.getOutputStream());
               out.write(postData);
               out.close();
               BufferedReader in = new BufferedReader(       new InputStreamReader(urlconnection.getInputStream()));
               String decodedString;
               while ((decodedString = in.readLine()) != null) {
                       retval += decodedString;
               }
               in.close();

 

               System.out.println(retval);
        }
}

 

 

Courtesy 160by2.com & SMS Country