Page 1 of 1
Re: SMS To Customer - Upon Order Delivery
Posted: Tue Apr 06, 2021 2:55 pm
by RiazKhan
Recently a customer has asked for an auto-generated and auto-sent SMS to the customer, upon goods delivery of his order. I have purchased a service package from my local SMS service provided. The API provided by the service provider works fine and I am able to send the SMS as a test to my cell number. Each time a dispatch is made an SMS is sent to the customer to his cell number. The problem is, every time an SMS is sent the default explorer is opened on the remote terminal server and an 'OK' message is pasted on the page. This page remains open. If ten SMS are sent, ten explorers are open. The service provider has told me that the explorer page should not open and the sending mechanism is transparent.
Is there a method to send the SMS without the web page opening..??
I am using the following : ShellExecute( oCust:hWnd, "open", cURL )
Any suggestions, Thnx...
Re: SMS To Customer - Upon Order Delivery
Posted: Tue Apr 06, 2021 4:58 pm
by Antonio Linares
Riaz,
Please post your code here.
You may use curl instead
Re: SMS To Customer - Upon Order Delivery
Posted: Tue Apr 06, 2021 5:13 pm
by RiazKhan
There is not much of a code, as a function is called with parameters...as shellexecute is used..
FUNCTION W_122W()
LOCAL SMS_Text,SMS_Cell,SMS_Brnd
SMS_Text := "Your Order Has Been Dispatched" + CHR(13) + ;
"Via Inoice No:R00024 - 04/04/2021" + CHR(13) + ;
"Vehicle: LXR-5172"
SMS_Cell := "923009473247"
SMS_Brnd := "OFoods-So Healthy So Good"
W_122SMS(SMS_Text,SMS_Cell,SMS_Brnd)
Return( Nil )
FUNCTION W_122SMS(SMS_Text,SMS_Cell,SMS_Brnd)
LOCAL cURL
// Suggested API from service provider
//
https://sendpk.com/api/sms.php?api_key= ... ge=TestSMScURL := "https://sendpk.com/api/sms.php?api_key=923343636573-280edb13-b5f6-43e6-8b3c-45420519ce9c" +CHR(13)+ ;
"&sender=" + SMS_Brnd +CHR(13)+ ;
"&mobile=" + SMS_Cell +CHR(13)+ ;
"&message=" + SMS_Text
ShellExecute( oCust:hWnd, "open", cURL )
Return( Nil )
I have not used curl
Re: SMS To Customer - Upon Order Delivery
Posted: Tue Apr 06, 2021 5:32 pm
by Antonio Linares
Please review this example and use it instead of ShellExecute()
https://github.com/FiveTechSoft/mod_harbour/blob/master/samples/callphp.prgCode: Select all | Expand
#include "c:\harbour\contrib\hbcurl\hbcurl.ch"
function sendSMS( cUrl )
local uValue
curl_global_init()
if ! empty( hCurl := curl_easy_init() )
curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )
curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
if curl_easy_perform( hCurl ) == 0
uValue = curl_easy_dl_buff_get( hCurl )
endif
endif
curl_global_cleanup()
return uValue
Re: SMS To Customer - Upon Order Delivery
Posted: Tue Apr 06, 2021 7:39 pm
by RiazKhan
Thnx Antonio,
I have included hbcurl.ch
also, download hbcurl.lib and libcurl.lib and added t my mak file
had to add libcurl.dll to my system folder.
no errors during compilation....
used the function below as test. Yes the SMS does get sent without opening the browser and after sending the application crashes and hangs...
I have hcurl error so made that a local variable ...simple sendSMS function is called without any parameters..I think the return uvalue is the issue..
function sendSMS()
local cUrl
local uValue,hcurl
cUrl := "https://sendpk.com/api/sms.php?api_key=92312354544-280edb13-b5f6-43e6-8b3c-45420519ce9c&sender=BrandName&mobile=9231443673639&message=TestSMS"
curl_global_init()
if ! empty( hCurl := curl_easy_init() )
curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )
curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
if curl_easy_perform( hCurl ) == 0
uValue = curl_easy_dl_buff_get( hCurl )
endif
endif
curl_global_cleanup()
return uValue
Re: SMS To Customer - Upon Order Delivery
Posted: Tue Apr 06, 2021 9:03 pm
by RiazKhan
I have inserted these three lines before curl_global_cleanup(), which now gives no GPF. The SMS is sent transparently and the application is functioning properly.
curl_easy_cleanup( hCurl )
hCurl := Nil
hb_gcAll( .t. )
curl_global_cleanup()
I need to pass three parameters to the sendSMS function. Like SMS_Text , SMS_Cell , SMS_Brnd. these need to be added to the cURL variable. I am unable to send SMS once the parameters are added into the cURL variable.
Any ideas..??
Re: SMS To Customer - Upon Order Delivery
Posted: Wed Apr 07, 2021 3:52 am
by RAMESHBABU
Hi Riaz Bhai,
I am using the following code since years to send all my SMS from my applications.
Code: Select all | Expand
#include "fivewin.ch"
FUNCTION Send_SMS(cURL)
cPageContent := wfReadUrl(cUrl)
RETURN cPageContent
*****************************************************************************
*** FUNCTION wfReadUrl(cUrl) Core Function to Post the cUrl to Internet ***
*****************************************************************************
FUNCTION wfReadUrl(cUrl)
LOCAL cPageContent := "Error: " + cUrl + " not found or timed out."
LOCAL oConn, oHttp
TRY
oHttp := oHttp := TOleAuto():New('WinHttp.WinHttpRequest.5.1')
oHttp:Open("PUT", cUrl, .F.)
oHttp:Send("Post Data")
cPageContent := oHttp:ResponseText
oHttp := nil
IF FILE("http.log")
ERASE http.log
ENDIF
CATCH
TRY
oHttp := TOleAuto():New('Msxml2.XMLHTTP.6.0')
oHttp:Open("GET", cUrl, .F.)
oHttp:Send("Post Data")
cPageContent := oHttp:ResponseText
oHttp := nil
IF FILE("http.log")
ERASE http.log
ENDIF
CATCH
TRY
oHttp := CreateObject("MSXML2.ServerXmlHttp")
IF Hb_IsObject(oHttp)
oHttp:Open("GET",cUrl,.F.)
oHttp:Send()
cPageContent := oHttp:ResponseText
ENDIF
CATCH
cPageContent := "Error opening the Url"
END
END
END
RETURN cPageContent
-Ramesh Babu P
Re: SMS To Customer - Upon Order Delivery
Posted: Wed Apr 07, 2021 7:45 am
by Antonio Linares
Riaz,
Please remove these calls from the function SendSMS():
curl_global_init() and curl_global_cleanup()
curl_global_init() should be called just once at the beginning of the app and curl_global_cleanup() just once upon exit of the app
Re: SMS To Customer - Upon Order Delivery
Posted: Wed Apr 07, 2021 8:14 am
by RiazKhan
Thanx Ramesh Sb.,
I have tried your method and works fine. No errors.
My cURL contains three variables that I pass to the SMS Send function after each invoice is generated. Those are BrandName, Recipient, and TextSMS.
The API code provided by the service provider..
cUrl := "https://sendpk.com/api/sms.php?api_key=923289536375-280edb13-b5f6-43e6-8b3c-45420519ce9c&sender=BrandName&mobile=92365483575&message=TestSMS"
My Example:
cUrl := "https://sendpk.com/api/sms.php?api_key=923289536375-280edb13-b5f6-43e6-8b3c-45420519ce9c&sender=BrandName&mobile=Recipient&message=TextSMS"
Once the parameters are passed to the function, the SMS does not get sent. Probably due to the recipient number. The BrandName and TextSMS are Recipient are all character variables passed as parameters. Whereas I think the number must not be in quotes, I used macros but did not work.
Any other method to make the cURL to fulfill the API
Thnx in advance....
Re: SMS To Customer - Upon Order Delivery
Posted: Wed Apr 07, 2021 8:17 am
by RiazKhan
Dear Antonio,
Okay, I have removed the two calls from the SendSMS function.
Re: SMS To Customer - Upon Order Delivery
Posted: Wed Apr 07, 2021 8:47 am
by RAMESHBABU
My Example:
cUrl := "https://sendpk.com/api/sms.php?api_key=923289536375-280edb13-b5f6-43e6-8b3c-45420519ce9c&sender=BrandName&mobile=Recipient&message=TextSMS"
Once the parameters are passed to the function, the SMS does not get sent. Probably due to the recipient number. The BrandName and TextSMS are Recipient are all character variables passed as parameters. Whereas I think the number must not be in quotes, I used macros but did not work.
Any other method to make the cURL to fulfill the API
Thnx in advance....
All three parameters must be Character Type variables as shown here under:
cUrl := "https://sendpk.com/api/sms.php?api_key=923289536375-280edb13-b5f6-43e6-8b3c-
45420519ce9c&sender=BrandName&mobile="+LTRIM(STR(nMobile_No))+"&message="+cMessage
This is how the cUrl must be prepared and supplied to my "wfReadUrl(cUrl)" Function.
You can even try the cUrl from the web browser directly from its address bar to check the result.
You can write the cUrl to a text file (MEMOWRIT("SMSURL.TXT", cUrl), open it in notepad,
copy the content and paste it in Web Browser's address bar.
-Ramesh Babu P
Re: SMS To Customer - Upon Order Delivery (RESOLVED)
Posted: Wed Apr 07, 2021 11:31 am
by RiazKhan
Thank you all,
Yes, It's working now using Ramesh Sb., source.
Passed three parameters to the function and SMS Sent transparent to the app.
Every time an invoice is generated the function is sent the three parameters and is delivered via SMS to the customer.
Thanks
Re: SMS To Customer - Upon Order Delivery
Posted: Wed Apr 07, 2021 7:18 pm
by RiazKhan
Ramesh Sb.,
After updating a test version on my client's MS Server, the Send SMS did not work and the application hung up GPF.
I updated on a Microsoft Windows Server 2008 R2 Enterprise
Version: 6.1.7601 Service Pack 1 Build 7601
Am I missing anything..??
Re: SMS To Customer - Upon Order Delivery
Posted: Thu Apr 08, 2021 4:30 am
by RAMESHBABU
Riaz Khan Sb,
Please use the following function to test any failure calls of "TOleAuto():New("
Code: Select all | Expand
*****************************************************************************
*** FUNCTION wfReadUrl(cUrl) Core Function to Post the cUrl to Internet ***
*****************************************************************************
FUNCTION wfReadUrl(cUrl)
LOCAL cPageContent := "Error: " + cUrl + " not found or timed out."
LOCAL oConn, oHttp
TRY
oHttp := oHttp := TOleAuto():New('WinHttp.WinHttpRequest.5.1')
oHttp:Open("PUT", cUrl, .F.)
oHttp:Send("Post Data")
cPageContent := oHttp:ResponseText
oHttp := nil
IF FILE("http.log")
ERASE http.log
ENDIF
CATCH
cPageContent := "Failed calling - 'WinHttp.WinHttpRequest.5.1'"
END
TRY
oHttp := TOleAuto():New('Msxml2.XMLHTTP.6.0')
oHttp:Open("GET", cUrl, .F.)
oHttp:Send("Post Data")
cPageContent := oHttp:ResponseText
oHttp := nil
IF FILE("http.log")
ERASE http.log
ENDIF
CATCH
cPageContent := "Failed calling - 'Msxml2.XMLHTTP.6.0'"
END
TRY
oHttp := CreateObject('MSXML2.ServerXmlHttp')
IF Hb_IsObject(oHttp)
oHttp:Open("GET",cUrl,.F.)
oHttp:Send()
cPageContent := oHttp:ResponseText
ENDIF
CATCH
cPageContent := "Failed calling - 'MSXML2.ServerXmlHttp'"
END
MsgInfo(cPageContent)
RETURN cPageContent
Here I never heard any problem with my clients so far.
-Ramesh Babu P
Re: SMS To Customer - Upon Order Delivery
Posted: Thu Apr 08, 2021 7:48 am
by RiazKhan
Thank You Ramesh Sb., for your prompt reply..
I have checked using your function on my local Windows 7 64 Bit Laptop..The SMS is sent and received with this msginfo()
( Failed Calling - 'MSXML2.ServerXmlHttp' )
I have also checked on the clients server ...The SMS does not send providing the same message as above but does not hang the application.
I have also checked Antonio's function using CURL on the local machine and server, the SMS gets sent and received with no error.
Both functions have the same cURL, passing parameters.
cUrl := "https://sendpk.com/api/sms.php?api_key=9232645337563-280edb13-b5f6-43e6-8b3c-45420519ce9c" +;
"&sender=" + ALLTRIM(SMS_Brnd) +;
"&message=" + AllTrim(SMS_Text) +;
"&mobile=" + ALLTRIM(STR(SMS_Cell))
Strange.....