Invio per numero lungo
- Home
- Invio per numero lungo
Inviare SMS tramite un numero lungo
Questa richiesta viene utilizzata per inviare SMS in tempo reale o in ritardo con un numero lungo.
URL
POST http://api.smspartner.fr/v1/vn/send
Impostazioni
Ogni richiesta PLC supporta i seguenti parametri :
apiKey | API key per il tuo account. Lo ottieni nel tuo account Partner SMS. |
---|---|
to | Numeri di telefono del destinatario..
|
from | Vostro numero virtuale in formato internazionale ( 396xxxxxxxxxxxxxxxxxxxx) |
message | Contenuto dell’SMS. 160 caratteri al massimo per SMS (oltre a questo, vi verrà addebitato un ulteriore SMS per 153 caratteri).
Attenzione, alcuni caratteri speciali e caratteri accentati saranno sostituiti durante l’invio :
|
Parametri opzionali | |
isStopSms | 1 per aggiungere STOP alla fine dell’SMS (obbligatorio per gli SMS commerciali) |
urlResponse | URL di ritorno per le Risposte (es: http://www.ilmiourldirisposta) |
urlDlr | Url di restituzione delle Ricevute di ritorno (es: http://www.ilmiourldidlr) |
sandbox | Per testare l’invio di messaggi SMS, è possibile utilizzare l’impostazione sandbox :
Non verrà inviato alcun SMS e non ci sarà alcun addebito sul vostro conto. |
_format | Formato della risposta. È possibile scegliere traJSON o XML . Il formato di risposta predefinito è JSON . |
Richiesta
Interrogazione campione :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php // Prepare data for POST request $fields = array( 'apiKey'=> 'YOUR API KEY', 'to'=> '336xxxxxxxx', 'from' => '336xxxxxxxx', 'message'=> 'This is your message' ); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL,'https://api.smspartner.fr/v1/vn/send'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($fields)); $result = curl_exec($curl); curl_close($curl); // Process your response here echo $result; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
Imports System.IO Imports System.Net Module Module1 Sub Main() Dim base_url As String = "http://api.smspartner.fr/v1/" Dim apiKey As String = "VOTRE_APIKEY" #send sms url = base_url & "vn/send" #note : utiliser une librairie JSON en production, par exemple : #https//www.nuget.org/packages/Newtonsoft.Json/ Dim parameters As String = String.Format( "{{""apiKey"":""{0}"",""to"":""{1}"",""from"":""{2}"",""message"":""{3}""}}", apiKey, "336xxxxxxxx", "336xxxxxxxx", "message de test") Console.Write(parameters) apiRequest("POST", url, parameters) End Sub Function apiRequest(method As String, url As String, parameters As String) As String Dim request As HttpWebRequest request = WebRequest.Create(url) request.Method = method request.Timeout = 10000 # timeout in ms request.ContentType = "application/json; charset=utf-8" request.ContentLength = 0 #set POST data If Not String.IsNullOrEmpty(parameters) Then request.ContentLength = parameters.Length Using reqStream As StreamWriter = New StreamWriter(request.GetRequestStream()) reqStream.Write(parameters) End Using End If #get response Dim returnValue As String = Nothing Using response As HttpWebResponse = request.GetResponse() If response.StatusCode = HttpStatusCode.OK Then Using resStream = response.GetResponseStream() If resStream IsNot Nothing Then Using reader As New StreamReader(resStream) returnValue = reader.ReadToEnd() End Using End If End Using End If End Using apiRequest = returnValue End Function End Module |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# std import logging import json from collections import OrderedDict # 3p import requests API_KEY = "MY API KEY" URL = "https://api.smspartner.fr/v1" class SMSPartner(): def send_sms(self, to, from, msg): print(to) data = OrderedDict([ ("apiKey", API_KEY), ("to", to), ("from",from), ("message", msg) ]) url = URL + "/vn/send" r = requests.post(url, data=json.dumps(data), verify=False) r_json = r.json() if r_json.get("success") == True: print(r_json) status = True else: print("SMS msg {} not delivered to {}".format(msg, to)) status = False return status |
1 |
curl -H "Content-Type: application/json" -X POST -d '{"apiKey":"xxxxx","to":"xxxx","from":"xxx","message":"test"}' https://api.smspartner.fr/v1/vn/send |
Risposte
1 2 3 4 5 6 7 8 |
{ "success":true, "code":200, "message_id":xxx, "nb_sms": 1, "cost": xxx, "currency": "EUR" } |
1 2 3 4 5 6 7 8 9 10 11 |
<?xml version='1.0' encoding='UTF-8'?> <result> <entry>true</entry> <entry>200</entry> <entry>xxx</entry> <entry>1</entry> <entry>xxx</entry> <entry> <![CDATA[EUR]]> </entry> </result> |