Sunday, June 13, 2010

Free SMS api

Yesterday I was searching for a free SMS api to integrate in my blog. And as you would have guessed I couldnot find any for Indian users. So here is what I did - A way2sms API in python which you can easily integrate in you web application.


The CODE ( FORMATTING HAS GONE HAYWIRE DO NOT COPY, DOWNLOAD FROM HERE)
http://code.google.com/p/way2sms-unofficial-api/downloads/detail?name=way2sms.py&can=2&q=

PROJECT HOMEPAGE AND GUI VERSION : http://code.google.com/p/way2sms-unofficial-api/

#######################################
#
#
# Unofficial way2SMS API 1.0
#
# Now send SMS by ONE CLICK on your PC
# OR
# Integrate this in your web or desktop service
#
#
#######################################


# Created by Abhishek Anand
# June 12, 2010
# You are free to use,modify this code in any form whatsoever but
# please tell me about the modification or use you have put this to
# I would be glad to hear your comments and suggestions.
# mail me at abhishek@bitproxy.co.cc
# http://proxyspeaks.blogspot.com



import urllib
import httplib2
import random



def sms(username,password,mobileNo, message):
#Check validity of MobileNumber and length of message ( should be less than 160)
if len(mobileNo) <> 10 or len(message) > 155:
return False
# These are some of the CNAMES or roughly servers you are directed
# (to balance load i guess)
serverList = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','1','2']
# Get a random server from list
server = serverList[random.randint(0,len(serverList)-1)]
# Make a authentication request and get the cookie
http = httplib2.Http()
url = 'http://www' + server + '.way2sms.com:80/auth.cl'
body = {'username': username, 'password': password,'login': 'Login'}
headers = {'Content-type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'}
try:
response, content = http.request(url,
'POST',
headers=headers,
body=urllib.urlencode(body))
except:
return False
# Set the cookie we got for future requests
headers = {'Content-type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
'Cookie': response['set-cookie']}
newBody = {'custid': 'undefined',
'HiddenAction': 'instantsms',
'Action':'custfrom650000',
'login': '',
'pass': '',
'MobNo': mobileNo,
'textArea': message}
newurl = "http://www"+ server +".way2sms.com:80//FirstServletsms?custid="
# Send message with the cookie we got
try:

response, content = http.request(newurl,
'POST',
headers=headers,
body=urllib.urlencode(newBody))
except:
return False
# If the returned text contains word successfully, your message is sent
if content.find("successfully") <> -1:
return True
else:
return False




## Wonder whats happening ? CHECK THESE RAW REQUESTS MADE BY IE 6.0 TO FIND OUT



##POST http://wwwd.way2sms.com:80/auth.cl HTTP/1.0
##Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
##Referer: http://wwwd.way2sms.com/content/index.html
##Accept-Language: en-us
##Content-Type: application/x-www-form-urlencoded
##Proxy-Connection: Keep-Alive
##User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
##Host: wwwd.way2sms.com
##Content-length: 49
##Pragma: no-cache
##Cookie: JSESSIONID=CD6B72CCD5EBC9BA1A26FB4BDA06097B.a402; __utma=247637761.1836730094.1276307773.1276307773.1276307773.1; __utmb=247637761.2.10.1276307773; __utmc=247637761; __utmz=247637761.1276307773.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
##
##username=9204741388&password=I_CANT_TELL_YOU_MY_PASSWORD&login=Login



##
##POST http://wwwd.way2sms.com:80//FirstServletsms?custid= HTTP/1.0
##Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
##Referer: http://wwwd.way2sms.com//jsp/InstantSMS.jsp?val=0
##Accept-Language: en-us
##Content-Type: application/x-www-form-urlencoded
##Proxy-Connection: Keep-Alive
##User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
##Host: wwwd.way2sms.com
##Content-length: 139
##Pragma: no-cache
##Cookie: JSESSIONID=018B38DCDC74E26289CD92DD0DD78D1B.a402; __utma=247637761.1836730094.1276307773.1276307773.1276307773.1; __utmb=247637761.2.10.1276307773; __utmc=247637761; __utmz=247637761.1276307773.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=21639229.1402244472.1276308031.1276308031.1276308031.1; __utmb=21639229.2.10.1276308031; __utmc=21639229; __utmz=21639229.1276308031.1.1.utmcsr=wwwd.way2sms.com|utmccn=(referral)|utmcmd=referral|utmcct=/content/index.html
##
##custid=undefined&HiddenAction=instantsms&Action=custfrom650000&login=&pass=&MobNo=9899949220&textArea=HI+POKA+HOW+R+U+I+M+FINE+THIS+IS+TEST





So Integrate and enjoy. If you have any problem please free to ask. And this can be easily converted in PHP or any language.

10 comments:

  1. hey guys try this out http://www.freesmsapi.com
    they give us free sms with an api to integrate with your website..
    seriously guys this is a boon to our developer community..
    thanx freesmsapi team

    ReplyDelete
  2. hi there nice work but it never worked with me. Always getting Message sending failed, try again. Do you have any idea about this. What is 'smsSent'

    ReplyDelete
  3. Seems way2SMS guys have changed something on their part, This code worked for me perfectly until last month. Please bring out a new version.

    ReplyDelete
  4. serverList[random.randint(0,len(serverList)-1)]
    should be written as
    random.choice(serverList)

    ReplyDelete
  5. way2sms has changes their CNAME records. Just change the serverList part with
    serverList = ['site1','site2','site3','site4','site5','site6']
    and the code works fine then :)

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Hiding sender's id is not possible as you still have to authenticate to send SMS. You can register using a new SIM (but in extreme cases they can still get your address provided by you as an address proof for the SIM).

    ReplyDelete
  8. Why not use the reliable API's available at ubaid.tk ? The API's are now used by developers of all platforms, let it be iOS , android or Windows Phone. These API's work the same way, whether you use it in your website, or your mobile app.
    The API is now sending more than 2 Million SMS per month, and is up from more than a year now.

    Give it a try, i'm sure it wont let you down!

    Thanks,
    Ubaid

    ReplyDelete
  9. MsgClub is one of the most amazing Bulk SMS API PHP instruction provider around the Nation. The company offers the option of integrating this function into the business websites for sending individual and Bulk SMS using various high qualities ready to use SMS scripts available with them.

    ReplyDelete