Enviar SMS OTP con su propia configuración

Asegúrese de que su mensaje SMS OTP sea exactamente como lo desea. Las opciones de personalización para contraseñas de un solo uso (OTP) permiten a los destinatarios saber quién envió el SMS y establecer los parámetros de seguridad para cada contraseña generada.

  • Establecer el texto del contenido del mensaje OTP con el marcador de posición {{pin}}
  • Plantilla de texto para idiomas locales
  • Elija la longitud del código de 4 a 10 dígitos
  • Establecer el tiempo para que el código caduque entre 60 y 1800 segundos
  • Personalización del ID del remitente como originador de SMS (por ejemplo Verificar)
SMS OTP ejemplo de plantilla de texto

OTP enviado a través de SMS

SMS es conocido por ser confiable porque el 98% de las personas lo abren en 30 segundos. El envío de contraseñas de un solo uso a través de SMS garantiza que llegue a sus usuarios dondequiera que estén. Incluso cuando los usuarios no tienen acceso a Internet, aún pueden usar esta solución OTP.

Código SMS OTP que caducará en 15 minutos

Ejemplos de código para la OTP SMS API

Integre nuestra avanzada OTP SMS API en su aplicación y comience a verificar números de teléfono en minutos.

Póngase en marcha rápidamente con nuestros contenedores de API oficiales y bibliotecas de cliente. Están disponibles con lenguajes populares como Python, PHP, Node.js, Java y otros.

¿No hay una biblioteca de cliente para su idioma? Use una biblioteca HTTP genérica de su elección, es bastante simple.

curl --request POST \
  --url https://api.sms.cx/otp \
  --header 'Authorization: Bearer REPLACE_ACCESS_TOKEN' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "phoneNumber": "+336124241xx",
    "from": "Verify",
    "template": "Your verification code is {{pin}}",
    "template_fr": "Votre code de vérification est {{pin}}",
    "template_de": "Ihr Bestätigungscode lautet {{pin}}",
    "template_es": "Tu código de verificación es {{pin}}",
    "template_it": "Il tuo codice di verifica è {{pin}}",
    "template_bg": "Вашият код за потвърждение е {{pin}}",    
    "ttl": 600,
    "maxAttempts": 6,
    "pinType": "numbers",
    "pinLength": 5,
    "otpCallbackUrl": "https://my-callback/receive-otp-status"
  }'
import requests

url = "https://api.sms.cx/otp"

payload = {
    "phoneNumber": "+336124241xx",
    "from": "Verify",
    "template": "Your verification code is {{pin}}",
    "template_fr": "Votre code de vérification est {{pin}}",
    "template_de": "Ihr Bestätigungscode lautet {{pin}}",
    "template_es": "Tu código de verificación es {{pin}}",
    "template_it": "Il tuo codice di verifica è {{pin}}",
    "template_bg": "Вашият код за потвърждение е {{pin}}",
    "ttl": 300,
    "maxAttempts": 5,
    "pinType": "numbers",
    "pinLength": 5,
    "otpCallbackUrl": "https://my-callback/receive-otp-status"
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer REPLACE_ACCESS_TOKEN"
}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)
require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://api.sms.cx/otp")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request["Authorization"] = 'Bearer REPLACE_ACCESS_TOKEN'
request.body = '{"phoneNumber":"+336124241xx","from":"Verify","template":"Your verification code is {{pin}}","template_fr":"Votre code de vérification est {{pin}}","template_de":"Ihr Bestätigungscode lautet {{pin}}","template_es":"Tu código de verificación es {{pin}}","template_it":"Il tuo codice di verifica è {{pin}}","template_bg":"Вашият код за потвърждение е {{pin}}","ttl":600,"maxAttempts":6,"pinType":"numbers","pinLength":5,"otpCallbackUrl":"https://my-callback/receive-otp-status"}'

response = http.request(request)
puts response.read_body
const data = JSON.stringify({
  "phoneNumber": "+336124241xx",
  "from": "Verify",
  "template": "Your verification code is {{pin}}",
  "template_fr": "Votre code de vérification est {{pin}}",
  "template_de": "Ihr Bestätigungscode lautet {{pin}}",
  "template_es": "Tu código de verificación es {{pin}}",
  "template_it": "Il tuo codice di verifica è {{pin}}",
  "template_bg": "Вашият код за потвърждение е {{pin}}", 
  "ttl": 300,
  "maxAttempts": 5,
  "pinType": "numbers",
  "pinLength": 5,
  "otpCallbackUrl": "https://my-callback/receive-otp-status"
});

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://api.sms.cx/otp");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", "Bearer REPLACE_ACCESS_TOKEN");

xhr.send(data);
const http = require("https");

const options = {
  "method": "POST",
  "hostname": "api.sms.cx",
  "port": null,
  "path": "/otp",
  "headers": {
    "Content-Type": "application/json",
    "Authorization": "Bearer REPLACE_ACCESS_TOKEN"
  }
};

const req = http.request(options, function (res) {
  const chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    const body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(JSON.stringify({
  phoneNumber: '+336124241xx',
  from: 'Verify',
  template: 'Your verification code is {{pin}}',
  template_fr: 'Votre code de vérification est {{pin}}"',
  template_de: 'Ihr Bestätigungscode lautet {{pin}}',
  template_es: 'Tu código de verificación es {{pin}}',
  template_it: 'Il tuo codice di verifica è {{pin}}',
  template_bg: 'Вашият код за потвърждение е {{pin}}',   
  ttl: 300,
  maxAttempts: 5,
  pinType: 'numbers',
  pinLength: 5,
  otpCallbackUrl: 'https://my-callback/receive-otp-status'
}));
req.end();
<?php

$curl = curl_init();

$payload = [
    "phoneNumber" => "+336124241xx",
    "from" => "Verify",
    "template" => "Your verification code is {{pin}}",
    "template_fr" => "Votre code de vérification est {{pin}}",
    "template_de" => "Ihr Bestätigungscode lautet {{pin}}",
    "template_es" => "Tu código de verificación es {{pin}}",
    "template_it" => "Il tuo codice di verifica è {{pin}}",
    "template_bg" => "Вашият код за потвърждение е {{pin}}",    
    "ttl" => 600,
    "maxAttempts" => 6,
    "pinType" => "numbers",
    "pinLength" => 5,
    "otpCallbackUrl" => "https://my-callback/receive-otp-status",
];

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.sms.cx/otp",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode($payload),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer REPLACE_ACCESS_TOKEN",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"phoneNumber\":\"+336124241xx\",\"from\":\"Verify\",\"template\":\"Your verification code is {{pin}}\",\"template_fr\":\"Votre code de v\u00E9rification est {{pin}}\",\"template_de\":\"Ihr Best\u00E4tigungscode lautet {{pin}}\",\"template_es\":\"Tu c\u00F3digo de verificaci\u00F3n es {{pin}}\",\"template_it\":\"Il tuo codice di verifica \u00E8 {{pin}}\",\"template_bg\":\"\u0412\u0430\u0448\u0438\u044F\u0442 \u043A\u043E\u0434 \u0437\u0430 \u043F\u043E\u0442\u0432\u044A\u0440\u0436\u0434\u0435\u043D\u0438\u0435 \u0435 {{pin}}\",\"ttl\":600,\"maxAttempts\":6,\"pinType\":\"numbers\",\"pinLength\":5,\"otpCallbackUrl\":\"https:\/\/my-callback\/receive-otp-status\"}");
Request request = new Request.Builder()
  .url("https://api.sms.cx/otp")
  .post(body)
  .addHeader("Content-Type", "application/json")
  .addHeader("Authorization", "Bearer REPLACE_ACCESS_TOKEN")
  .build();

Response response = client.newCall(request).execute();
var client = new RestClient("https://api.sms.cx/otp");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Bearer REPLACE_ACCESS_TOKEN");
request.AddParameter("application/json", "{\"phoneNumber\":\"+336124241xx\",\"from\":\"Verify\",\"template\":\"Your verification code is {{pin}}\",\"template_fr\":\"Votre code de v\u00E9rification est {{pin}}\",\"template_de\":\"Ihr Best\u00E4tigungscode lautet {{pin}}\",\"template_es\":\"Tu c\u00F3digo de verificaci\u00F3n es {{pin}}\",\"template_it\":\"Il tuo codice di verifica \u00E8 {{pin}}\",\"template_bg\":\"\u0412\u0430\u0448\u0438\u044F\u0442 \u043A\u043E\u0434 \u0437\u0430 \u043F\u043E\u0442\u0432\u044A\u0440\u0436\u0434\u0435\u043D\u0438\u0435 \u0435 {{pin}}\",\"ttl\":600,\"maxAttempts\":6,\"pinType\":\"numbers\",\"pinLength\":5,\"otpCallbackUrl\":\"https:\/\/my-callback\/receive-otp-status\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://api.sms.cx/otp"

	payload := strings.NewReader("{\"phoneNumber\":\"+336124241xx\",\"from\":\"Verify\",\"template\":\"Your verification code is {{pin}}\",\"template_fr\":\"Votre code de v\u00E9rification est {{pin}}\",\"template_de\":\"Ihr Best\u00E4tigungscode lautet {{pin}}\",\"template_es\":\"Tu c\u00F3digo de verificaci\u00F3n es {{pin}}\",\"template_it\":\"Il tuo codice di verifica \u00E8 {{pin}}\",\"template_bg\":\"\u0412\u0430\u0448\u0438\u044F\u0442 \u043A\u043E\u0434 \u0437\u0430 \u043F\u043E\u0442\u0432\u044A\u0440\u0436\u0434\u0435\u043D\u0438\u0435 \u0435 {{pin}}\",\"ttl\":600,\"maxAttempts\":6,\"pinType\":\"numbers\",\"pinLength\":5,\"otpCallbackUrl\":\"https:\/\/my-callback\/receive-otp-status\"}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Authorization", "Bearer REPLACE_ACCESS_TOKEN")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}