Wiki Home

Smart SMS


Namespace: People
Smart SMS is a web portal that is designed for programmers (both web and desktop) to easily integrate SMS capabilities into their web space or desktop application.

You will need 2 extra functions with regard to Foxpro programming and a WINAPI declaration
DECLARE INTEGER Sleep IN WIN32API INTEGER nMSecs
FUNCTION encodeURL(mStr)
	LOCAL sValidChars,i,strLen,mChar,mRetStr
	sValidChars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz:/.?=_-$(){}~&"
	strLen = LEN(mStr)
	mRetStr = ""
	IF strLen > 0
		FOR m.i = 1 TO strLen
			mChar = SUBSTR(mStr,m.i,1)
			IF AT(mChar,sValidChars) > 0 && valid char
				mRetStr = mRetStr + mChar
			ELSE
				mRetStr = mRetStr + '%' + SUBSTR(TRANSFORM(ASC(mChar), "@0"),9)
			ENDIF
		ENDFOR
	ENDIF
	RETURN mRetStr
ENDFUNC

FUNCTION WaitForReadyState(oBrowser,lnReadyState, lnMilliSeconds)
	LOCAL lnX
	IF EMPTY(lnReadyState)
		lnReadyState = 4
	ENDIF
	IF EMPTY(lnMilliSeconds)
		lnMilliSeconds = 4000
	ENDIF
	lnX = 0
	DO WHILE oBrowser.ReadyState != lnReadyState AND lnX < lnMilliSeconds
		DOEVENTS
		lnX = lnX + 1
		Sleep(1)
	ENDDO
	IF lnX < lnMilliSeconds
		RETURN .T. && Not timed out
	ENDIF
	RETURN .F.
ENDFUNC 

I think the second function was gleaned from Rick Strahl (thanks)

The heart of the code is as follows
	&& Build the string to attach to the url
	mStr = "uid=0&pw=password&courierpn=" + ;
			ALLTRIM(this.parent.txtSMS.Value)+ "&msg=" + encodeURL(mStr)
	&& open an instance of IE
	loIE = CREATEOBJECT('InternetExplorer.Application')
	&& Open the url. Notice that IE is NOT made visible. You can add a loIE.Visible = .t. on the next line for development
	loIE.Navigate("http://www.smartsms.com.au/smsgate.php?"+mStr)
	&& Wait for the www to do its thing
	IF WaitForReadyState(loIE)
		mResponse = loIE.Document.Body.InnerHTML
		thisform.lblSmartSMS.Caption = mResponse
		IF SUBSTR(mResponse,1,5) = "MSGID"
			INSERT INTO fwBooking (dDate,cMessage,cReceipt,smsnumber) ;
				VALUES (DATETIME(),mCopy,mResponse,ALLTRIM(this.parent.txtSMS.Value))
			thisform.grdFwbooking.Refresh
		ELSE
			MESSAGEBOX("Message Failed, please call directly",64,"Tell Pete")
		ENDIF
	ELSE
		MESSAGEBOX("Unable to connect to the SmartSMS Server",16,;
			"Internet Connection Down")
	ENDIF
	loIE.Quit
	loIE = null


The messages that you can receive back are
1. A MSGID that is a unique receipt for the sent SMS (SUCCESS)
2. A Message : Smart SMS server rejected message. There can be many reasons for a SMS message not to comply (illegal characters being one)
3. A Message : Password Incorrect
4. A Message : Some parameters not set. Check that your spelling is correct and that there are 4 parameters

The 4 parameters are
uid
pw
courierpn
msg

You can test the system by using uid=0 and pw=foxpro. Remember that you DO NOT enclose strings in '' or "" for url's. What you are trying to achieve, is the url below (but in code)
http://www.smartsms.com.au/smsgate.php?uid=0&pw=foxpro&msg=Hello%20World&courierpn=9999999
You will see a response like MSGID:Test, . This is what you will see in loIE.Document.Body.InnerHTML

If you have something more specific to achieve, please email me at pete at catalinatrading dot com dot au
Have a look around at the website at http://www.smartsms.com.au
Peter Easson
26th April 2007
Here is a sample form that you can download and try. http://www.smartsms.com.au/downloads/SmartSMS_FoxDemo.ZIP
( Topic last updated: 2007.04.26 01:59:24 AM )