Está en la página 1de 5

Const

Const
Const
Const
Const
Const

SMS_TYPE_CLASSIC As String = "classic"


SMS_TYPE_CLASSIC_PLUS As String = "classic_plus"
SMS_TYPE_BASIC As String = "basic"
SMS_TYPE_TEST_CLASSIC As String = "test_classic"
SMS_TYPE_TEST_CLASSIC_PLUS As String = "test_classic_plus"
SMS_TYPE_TEST_BASIC As String = "test_basic"

Function URLEncode(ByVal Text As String) As String


Dim
Dim
Dim
Dim
Dim

i As Integer
acode As Integer
chr As String
hexValue As String
finalString As String

finalString = ""
For i = 1 To Len(Text) Step 1
acode = Asc(Mid$(Text, i, 1))
Select Case acode
Case 48 To 57, 65 To 90, 97 To 122
' don't touch alphanumeric chars
finalString = finalString & Mid$(Text, i, 1)
Case 32
' replace space with "+"
'Mid$(Text, i, 1) = "+"
finalString = finalString & "+"
Case Else
hexValue = Hex$(acode)
Select Case Len(hexValue)
Case 1
hexValue = "0" & hexValue
Case 2
'ok
Case Else
'carattere non valido
'skip
hexValue = ""
End Select
' replace punctuation chars with "%hex"
finalString = finalString & "%" & hexValue
End Select
Next
Return finalString
End Function
Function skebbyGatewaySendSMS(username As String, password As String, recipients
() As String, Text As String, sms_type As String, Optional sender_number As Stri
ng = "", Optional sender_string As String = "", Optional user_reference As Strin
g = "", Optional charset As String = "") As String
Dim sender_error, url, method, parameters, msg As String
Dim xmlhttp As Object
xmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1")

url = "http://gateway.skebby.it/api/send/smseasy/advanced/http.php"
sender_error = "Puoi specificare solo un tipo di mittente, numerico o al
fanumerico"
method = "send_sms_classic"
Select Case sms_type
Case SMS_TYPE_CLASSIC
method = "send_sms_classic"
Case SMS_TYPE_CLASSIC_PLUS
method = "send_sms_classic_report"
Case SMS_TYPE_BASIC
method = "send_sms_basic"
Case SMS_TYPE_TEST_CLASSIC
method = "test_send_sms_classic"
Case SMS_TYPE_TEST_CLASSIC_PLUS
method = "test_send_sms_classic_report"
Case SMS_TYPE_TEST_BASIC
method = "test_send_sms_basic"
Case Else
method = "send_sms_classic"
End Select
parameters = "method=" & method & "&" _
& "username=" & URLEncode(username) & "&" _
& "password=" & URLEncode(password) & "&" _
& "text=" & URLEncode(Text) & "&" _
& "recipients[]=" & Join(recipients, "&recipien
ts[]=")
If sender_number <> "" And sender_string <> "" Then
skebbyGatewaySendSMS = "status=failed&message=" & sender_error
Exit Function
End If
If sender_number <> "" Then parameters = parameters & "&sender_number="
& URLEncode(sender_number)
If sender_string <> "" Then parameters = parameters & "&sender_string="
& URLEncode(sender_string)
If user_reference <> "" Then parameters = parameters & "&user_reference=
" & URLEncode(user_reference)
Select Case charset
Case "UTF-8"
parameters = parameters & "&charset=UTF-8"
Case Else
End Select

xmlhttp.open("POST", url, False)


xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlenco
ded")
xmlhttp.setRequestHeader("Content-Length", Len(parameters))
xmlhttp.Send(parameters)
If xmlhttp.Status >= 400 And xmlhttp.Status <= 599 Then
skebbyGatewaySendSMS = "status=failed&message=" & xmlhttp.Status
& " - " & xmlhttp.statusText
Exit Function

End If
' -----------------------------------------------------------------' Controlla la documentazione completa all'indirizzo http:#www.skebby.it
/business/index/send-docs/
' -----------------------------------------------------------------' Per i possibili errori si veda http:#www.skebby.it/business/index/send
-docs/#errorCodesSection
' ATTENZIONE: in caso di errore Non si deve riprovare l'invio, trattando
si di errori bloccanti
' -----------------------------------------------------------------msg = xmlhttp.responseText
xmlhttp = Nothing
skebbyGatewaySendSMS = msg
End Function
Function skebbyGatewayGetCredit(username As String, password As String, Optional
charset As String = "") As String
Dim url, method, parameters, msg As String
Dim xmlhttp As Object
xmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
url = "http://gateway.skebby.it/api/send/smseasy/advanced/http.php"
method = "get_credit"
parameters = "method=" & method & "&" _
& "username=" & URLEncode(username) & "&" _
& "password=" & URLEncode(password)
Select Case charset
Case "UTF-8"
parameters = parameters & "&charset=UTF-8"
Case Else
End Select

xmlhttp.open("POST", url, False)


xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlenco
ded")
xmlhttp.setRequestHeader("Content-Length", Len(parameters))
xmlhttp.Send(parameters)
If xmlhttp.Status >= 400 And xmlhttp.Status <= 599 Then
skebbyGatewayGetCredit = "status=failed&message=" & xmlhttp.Stat
us & " - " & xmlhttp.statusText
Exit Function
End If
msg = xmlhttp.responseText
xmlhttp = Nothing
skebbyGatewayGetCredit = msg
End Function

Private Sub Form_Load()


Dim recipients(0) As String
Dim i As Integer
' Invio singolo
recipients(0) = "393471234567"
' Per invio multiplo
' recipients(0) = "393471234567"
' recipients(1) = "393497654321"
' ------------ Invio SMS Classic -------------' Invio SMS CLASSIC con mittente personalizzato di tipo alfanumerico
Dim result As String
result = skebbyGatewaySendSMS("username","password",recipients,"Hi Mike,
how are you?", SMS_TYPE_CLASSIC,"","John")
' Invio SMS CLASSIC con mittente personalizzato di tipo numerico
' result = skebbyGatewaySendSMS("username","password",recipients,"Hi Mik
e, how are you?", SMS_TYPE_CLASSIC,"393471234567")
' ------------- Invio SMS Basic ---------------' result = skebbyGatewaySendSMS("username","password",recipients,"Hi Mik
e, how are you? By John", SMS_TYPE_BASIC)
' ------------ Invio SMS Classic Plus ----------' Invio SMS CLASSIC PLUS(con notifica) con mittente personalizzato di ti
po alfanumerico
' result = skebbyGatewaySendSMS("username","password",recipients,"Hi Mik
e, how are you?", SMS_TYPE_CLASSIC_PLUS,"","John")
' Invio SMS CLASSIC PLUS(con notifica) con mittente personalizzato di ti
po numerico
' result = skebbyGatewaySendSMS("username","password",recipients,"Hi Mik
e, how are you?", SMS_TYPE_CLASSIC_PLUS,"393471234567")
' Invio SMS CLASSIC PLUS(con notifica) con mittente personalizzato di ti
po numerico e stringa di riferimento personalizzabile
' result = skebbyGatewaySendSMS("username","password",recipients,"Hi Mik
e, how are you?", SMS_TYPE_CLASSIC_PLUS,"393471234567","","riferimento")

'
'
'
I SKEBBY
'

-----------------------------------------------------------------ATTENZIONE I TIPI DI SMS SMS_TYPE_TEST* NON FANNO PARTIRE ALCUN SMS


SERVONO SOLO PER VERIFICARE LA POSSIBILITA' DI RAGGIUNGERE IL SERVER D
------------------------------------------------------------------

' ------------- Testing invio SMS Classic--------' TEST di invio SMS CLASSIC con mittente personalizzato di tipo alfanume
rico
' result = skebbyGatewaySendSMS("username","password",recipients,"Hi Mik
e, how are you?", SMS_TYPE_TEST_CLASSIC,"","John")

' TEST di invio SMS CLASSIC con mittente personalizzato di tipo numerico
' result = skebbyGatewaySendSMS("username","password",recipients,"Hi Mik
e, how are you?", SMS_TYPE_TEST_CLASSIC,"393471234567")
' ------------- Testing invio SMS Classic Plus--------' TEST di invio SMS CLASSIC PLUS(con notifica) con mittente personalizza
to di tipo alfanumerico
' result = skebbyGatewaySendSMS("username","password",recipients,"Hi Mik
e, how are you?", SMS_TYPE_TEST_CLASSIC_PLUS,"","John")
' TEST di invio SMS CLASSIC PLUS(con notifica) con mittente personalizza
to di tipo numerico
' result = skebbyGatewaySendSMS("username","password",recipients,"Hi Mik
e, how are you?", SMS_TYPE_TEST_CLASSIC_PLUS,"393471234567")
' ------------- Testing invio SMS Basic--------------' result = skebbyGatewaySendSMS("username","password",recipients,"Hi Mik
e, how are you? By John", SMS_TYPE_TEST_BASIC)
'
'
'
I SKEBBY
'

-----------------------------------------------------------------ATTENZIONE I TIPI DI SMS SMS_TYPE_TEST* NON FANNO PARTIRE ALCUN SMS


SERVONO SOLO PER VERIFICARE LA POSSIBILITA' DI RAGGIUNGERE IL SERVER D
------------------------------------------------------------------

' ------------ Controllo del CREDITO RESIDUO ------------' result = skebbyGatewayGetCredit("username", "password")
Dim responses As String()
responses = Split(result, "&")
Dim Response As String = ""
For Each Item In responses
Response = Response & Item & vbCrLf
Next
MsgBox(Response, vbOKOnly + vbInformation, "Result")
End Sub

También podría gustarte