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.