Le piattaforme Messaggi SMS possono essere collegate tramite interfacce API ai più comuni sistemi già in uso presso il cliente. Semplici API SMS ti consentono di integrare il nostro sistema di SMS con la tua applicazione o server web in modo facile ed immediato.
Di seguito ti illustreremo come inviare SMS usando diversi linguaggi di programmazione.
$sms = new SMS($username,$api_key); // username e apiKey forniti dal Gateway sms $sms -> User(); // getter username $sms -> Mittente($mittente); // setter mittente (max 10 caratteri, 13 se numero in formato internazionale) // usabile come getter (senza parametro) $sms -> AddDestinataro($destinatario); // aggiunge destinatario $sms -> AddStringaDestinatari($destinatari); // aggiunge elenco destinatari separati da virgola $sms -> Destinatari(); // getter array destinatari $sms -> Messaggio($messaggio); // se eccede i 160 caratteri viene automaticamente splittato in più messaggi // usabile come getter (senza parametro) $sms -> Send(optional $answer_type); // ritorna un array con la struttura seguente: // ( // [success] => true|false (esito invio) // [message] => Array // ( // [0] => Messaggio 1 // [1] => Messaggio 2... (array messaggi/eventuali errori) // ) // // ) // l'array è in formato json di default, fornire parametro // $answer_type valorizzare opportunamente per ottenere la risposta in // formato differente. Attualmente sono supportati i seguenti formati: // - "json" (default) // - "array" (array php)
Imports MessaggiSMSApi Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Private Sub btnInvia_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInvia.Click Dim sms As New SMS(Trim(txtUser.Text), Trim(txtApiKey.Text)) sms.Mittente = Trim(txtMittente.Text) Dim listaDestinatari As List(Of String) = Trim(txtDestinatario.Text).Split(",").ToList For Each destinatario As String In listaDestinatari sms.AddDestinatario(Trim(destinatario)) Next sms.Messaggio = Trim(txtMessaggio.Text) Dim result = sms.SendSMS() ltrRisposta.Text = result End Sub End Class
Function sendSMS(username,apiKey,recipient,text,sender) url ="http://www.messaggisms.com/ws/" Data = "action=send&username="+username+"&apiKey="+apiKey+"&to="+recipient+"&text="+text+"&from="+sender Response.Write Data Dim xhr : Set xhr = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0") xhr.open "POST", url, false xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" xhr.send Data If (xhr.Status = 200) then postFormData = xhr.ResponseText Else Err.Raise 1001, "postFormData", "Post to " & url & " failed with " & xhr.Status End If sendSMS = postFormData End Function 'Impostare indirizzo email indicato durante la registrazione' username = "account@email.com" 'impostare apiKey che si ottiente nella sezione "configurazioni" ' 'del software http://www.messaggisms.com/gestione/ ' apiKey = "1427d841d1a160499a1084093c309f1a" 'impostare il destinatario' recipient = "3931111111" 'impostare il corpo del messaggio' text = "this is a test" 'impostare il mittente del messaggio' sender = "John" 'Inviare e stampare la risposta a video' Response.Write(sendSMS(username,apiKey,recipient,text,sender))