Re: SMS To Customer - Upon Order Delivery

Re: SMS To Customer - Upon Order Delivery

Postby RiazKhan » Tue Apr 06, 2021 2:55 pm

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...
Last edited by RiazKhan on Wed Apr 07, 2021 7:15 pm, edited 4 times in total.
FWH 20.04/Harbour3.2/Bcc7.40+/ilink32/Pelles 9.0
EMail: amriazkhan@gmail.com
Pakistan
User avatar
RiazKhan
 
Posts: 99
Joined: Fri Dec 16, 2011 3:30 pm
Location: Pakistan

Re: SMS To Customer - Upon Order Delivery

Postby Antonio Linares » Tue Apr 06, 2021 4:58 pm

Riaz,

Please post your code here.

You may use curl instead
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: SMS To Customer - Upon Order Delivery

Postby RiazKhan » Tue Apr 06, 2021 5:13 pm

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=TestSMS

cURL := "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
FWH 20.04/Harbour3.2/Bcc7.40+/ilink32/Pelles 9.0
EMail: amriazkhan@gmail.com
Pakistan
User avatar
RiazKhan
 
Posts: 99
Joined: Fri Dec 16, 2011 3:30 pm
Location: Pakistan

Re: SMS To Customer - Upon Order Delivery

Postby Antonio Linares » Tue Apr 06, 2021 5:32 pm

Please review this example and use it instead of ShellExecute()

https://github.com/FiveTechSoft/mod_harbour/blob/master/samples/callphp.prg

Code: Select all  Expand view
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: SMS To Customer - Upon Order Delivery

Postby RiazKhan » Tue Apr 06, 2021 7:39 pm

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
FWH 20.04/Harbour3.2/Bcc7.40+/ilink32/Pelles 9.0
EMail: amriazkhan@gmail.com
Pakistan
User avatar
RiazKhan
 
Posts: 99
Joined: Fri Dec 16, 2011 3:30 pm
Location: Pakistan

Re: SMS To Customer - Upon Order Delivery

Postby RiazKhan » Tue Apr 06, 2021 9:03 pm

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..??
FWH 20.04/Harbour3.2/Bcc7.40+/ilink32/Pelles 9.0
EMail: amriazkhan@gmail.com
Pakistan
User avatar
RiazKhan
 
Posts: 99
Joined: Fri Dec 16, 2011 3:30 pm
Location: Pakistan

Re: SMS To Customer - Upon Order Delivery

Postby RAMESHBABU » Wed Apr 07, 2021 3:52 am

Hi Riaz Bhai,

I am using the following code since years to send all my SMS from my applications.

Code: Select all  Expand view

#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
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: SMS To Customer - Upon Order Delivery

Postby Antonio Linares » Wed Apr 07, 2021 7:45 am

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: SMS To Customer - Upon Order Delivery

Postby RiazKhan » Wed Apr 07, 2021 8:14 am

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....
FWH 20.04/Harbour3.2/Bcc7.40+/ilink32/Pelles 9.0
EMail: amriazkhan@gmail.com
Pakistan
User avatar
RiazKhan
 
Posts: 99
Joined: Fri Dec 16, 2011 3:30 pm
Location: Pakistan

Re: SMS To Customer - Upon Order Delivery

Postby RiazKhan » Wed Apr 07, 2021 8:17 am

Dear Antonio,

Okay, I have removed the two calls from the SendSMS function.
FWH 20.04/Harbour3.2/Bcc7.40+/ilink32/Pelles 9.0
EMail: amriazkhan@gmail.com
Pakistan
User avatar
RiazKhan
 
Posts: 99
Joined: Fri Dec 16, 2011 3:30 pm
Location: Pakistan

Re: SMS To Customer - Upon Order Delivery

Postby RAMESHBABU » Wed Apr 07, 2021 8:47 am

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
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: SMS To Customer - Upon Order Delivery (RESOLVED)

Postby RiazKhan » Wed Apr 07, 2021 11:31 am

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
FWH 20.04/Harbour3.2/Bcc7.40+/ilink32/Pelles 9.0
EMail: amriazkhan@gmail.com
Pakistan
User avatar
RiazKhan
 
Posts: 99
Joined: Fri Dec 16, 2011 3:30 pm
Location: Pakistan

Re: SMS To Customer - Upon Order Delivery

Postby RiazKhan » Wed Apr 07, 2021 7:18 pm

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..??
FWH 20.04/Harbour3.2/Bcc7.40+/ilink32/Pelles 9.0
EMail: amriazkhan@gmail.com
Pakistan
User avatar
RiazKhan
 
Posts: 99
Joined: Fri Dec 16, 2011 3:30 pm
Location: Pakistan

Re: SMS To Customer - Upon Order Delivery

Postby RAMESHBABU » Thu Apr 08, 2021 4:30 am

Riaz Khan Sb,

Please use the following function to test any failure calls of "TOleAuto():New("

Code: Select all  Expand view

*****************************************************************************
*** 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
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: SMS To Customer - Upon Order Delivery

Postby RiazKhan » Thu Apr 08, 2021 7:48 am

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.....
FWH 20.04/Harbour3.2/Bcc7.40+/ilink32/Pelles 9.0
EMail: amriazkhan@gmail.com
Pakistan
User avatar
RiazKhan
 
Posts: 99
Joined: Fri Dec 16, 2011 3:30 pm
Location: Pakistan


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 65 guests