Enviar SMS con C Sharp
Envíe SMS personalizados con C Sharp usando API SMS
C Sharp : DOCUMENTACIÓN API
- Crear grupo con C Sharp
- Obtener campos de un grupo con C Sharp
- Añadir campo a un grupo con C Sharp
- Elimina campo de un grupo con C Sharp
- Eliminar un grupo de contactos
- Asigna país a un grupo con C Sharp
- Obtener contactos del grupo con C Sharp
- Añadir contacto a grupo con C Sharp
- Modificar contacto del grupo con C Sharp
- Eliminar contacto del grupo con C Sharp
- Obtener listado de canales de chat activos con C Sharp
- Enviar un mensaje por chat con C Sharp
- Enviar un archivo por chat con C Sharp
- Obtener listado de conversaciones de un chat con C Sharp
- Obtener listado de mensajes de un chat con C Sharp
- Obtener listado de mensajes no leídos de un chat con C Sharp
Enviar SMS con C Sharp
Este método le permite enviar SMS a un destinatario utilizando C Sharp. Enviar un SMS con C Sharp es tan sencillo como enviar el origin, destino y el mensaje a enviar a través de una petición a nuestra API.
String afilnet_class="sms";
String afilnet_method="sendsms";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_from="Afilnet";
String afilnet_to="34600000000";
String afilnet_sms="sms+test";
String afilnet_scheduledatetime="";
String afilnet_output="";
// Create an URL request
WebRequest request = WebRequest.Create("https://www.afilnet.com/api/http/?class="+afilnet_class+"&method="+afilnet_method+"&user="+afilnet_user+"&password="+afilnet_password+"&from="+afilnet_from+"&to="+afilnet_to+"&sms="+afilnet_sms+"&scheduledatetime="+afilnet_scheduledatetime+"&output="+afilnet_output);
// Get the response
WebResponse response = request.GetResponse ();
// Get the stream returned by the server
Stream dataStream = response.GetResponseStream();
// Open the stream
StreamReader reader = new StreamReader (dataStream);
// Read the Response
String result = reader.ReadToEnd ();
// Asign vars
var data = new NameValueCollection();
data["class"] = "sms";
data["method"] = "sendsms";
data["user"] = "user";
data["password"] = "password";
data["from"] = "Afilnet";
data["to"] = "34600000000";
data["sms"] = "sms+test";
data["scheduledatetime"] = "";
data["output"] = "";
// Create Web client
var wb = new WebClient();
// Execute POST petition
var response = wb.UploadValues("https://www.afilnet.com/api/http/", "POST", data);
// Get response
string responseString = Encoding.UTF8.GetString(response);
// Asign vars
var data = new NameValueCollection();
data["class"] = "sms";
data["method"] = "sendsms";
data["from"] = "Afilnet";
data["to"] = "34600000000";
data["sms"] = "sms+test";
data["scheduledatetime"] = "";
data["output"] = "";
// Create Web client
var wb = new WebClient { Credentials = new NetworkCredential("user", "password") };
// Execute POST petition
var response = wb.UploadValues("https://www.afilnet.com/api/http/", "POST", data);
// Get response
string responseString = Encoding.UTF8.GetString(response);
String afilnet_class="sms";
String afilnet_method="sendsms";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_from="Afilnet";
String afilnet_to="34600000000";
String afilnet_sms="sms+test";
String afilnet_scheduledatetime="";
String afilnet_output="";
// Allow SSL/TLS config
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// We create the webservice instance (Register Web Service first in project)
var service = new WebService.ApplicationServicesPortTypeClient();
// Call to WebService method
String response = service.call(afilnet_user, afilnet_password, afilnet_class, afilnet_method, "{\"from\":\""+afilnet_from+"\",\"to\":\""+afilnet_to+"\",\"sms\":\""+afilnet_sms+"\",\"scheduledatetime\":\""+afilnet_scheduledatetime+"\",\"output\":\""+afilnet_output+"\"}");
Parámetro | Descripción | Obligatorio / Opcional |
---|---|---|
class=sms | Clase a la que se realiza la petición | Obligatorio |
method=sendsms | Método de la clase al que se realiza la petición | Obligatorio |
user | El usuario / email de su cuenta de Afilnet | Obligatorio |
password | El password de su cuenta de Afilnet | Obligatorio |
from | Remitente | Obligatorio |
to | Número móvil destino | Obligatorio |
sms | Mensaje SMS a enviar | Obligatorio |
scheduledatetime | Fecha y hora de envío en formato yyyy-mm-dd hh:mm:ss | Opcional |
output | Formato de salida del resultado | Opcional |
Al realizar peticiones recibirá los siguientes campos:
- status
-
result (si status=success), recibirá los siguientes valores:
- messageid
- credits
- error (si status=error), aquí recibirá el código de error
Los códigos de error posibles son los siguientes:
Código | Descripción |
---|---|
MISSING_USER | Usuario / email no incluido |
MISSING_PASSWORD | Password no incluido |
MISSING_CLASS | Clase no incluida |
MISSING_METHOD | Método no incluido |
MISSING_COMPULSORY_PARAM | Parámetro obligatorio no incluido |
INCORRECT_USER_PASSWORD | Usuario o clave incorrectos |
INCORRECT_CLASS | Clase incorrecta |
INCORRECT_METHOD | Método incorrecto |
NO_ROUTE_AVAILABLE | No hay rutas disponibles para el destino indicado |
NO_CREDITS | No dispone de saldo suficiente |
Parámetros:
- class : sms
- method : sendsms
- user : user
- password : password
- from : Afilnet
- to : 34600000000
- sms : sms+test
- scheduledatetime :
- output :
Petición:
https://www.afilnet.com/api/http/?class=sms&method=sendsms&user=user&password=password&from=Afilnet&to=34600000000&sms=sms+test&scheduledatetime=&output=