<?php
//Funcion q ejecuta una solicitud http GET
function curlGet($urlAPI, $headers) {
//Iniciar solicitud curl: POST
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $urlAPI);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//Respuesta en formato JSON
$curl_response = curl_exec($curl);
//Finaliza solicitud curl: POST
curl_close($curl);
return json_decode($curl_response);
}
/*## Preparar informacion del usuario Payphone ##*/
$phoneNumber = "0984111333";//ID Payphone Personal.
$countryCode = "593";//Código de país.
$token="your_token_API";
$url="https://pay.payphonetodoesposible.com/api/Users/check/".$phoneNumber."/region/".$countryCode;
//Preparar cabecera para la solicitud
$headers[] = 'Authorization: Bearer '.$token ;//CREDENCIALES DE CONFIGURACION
$headers[] = 'Content-Type: application/json' ;//TIPO DE APLICACION
//realizar solicitud http GET
$result=curlGet($url, $headers);
//Mostrar Resultado en Pantalla
echo "<h1>Usuario Registrado</h1>";
echo "<a>Usuario Payphone:<strong>".$phoneNumber."<strong></a><br>";
echo "Respuesta : <pre>".json_encode($result,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT )."</pre>";
?>
<html lang="es">
<head>
<meta charset="utf-8">
<title>Usuario Registrado</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<h1>Usuario Registrado</h1>
<a>Usuario Payphone: <strong id="phoneNumber"></strong></a><br>
<div id="resultado"></div>
<script>
/*## Preparar credenciales como variables para la solicitud ##*/
const token="your_token_API";
/*## Preparar informacion del usuario Payphone ##*/
const phoneNumber="0984111333"; //ID Payphone Personal.
const countryCode="593"; //Codigo Pais
$(document).ready(function() {
$.ajax({
url: "https://pay.payphonetodoesposible.com/api/Users/check/"+phoneNumber+"/region/"+countryCode,
type: "GET",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer "+token
},
success: function(response) {
$("#resultado").html(
"Respuesta : <pre>" + JSON.stringify(response, null, 2) + "</pre>"
);
},
error: function(error) {
$("#resultado").html(
"Error en la solicitud : <pre>" + JSON.stringify(error, null, 2) + "</pre>"
);
}
});
});
// Mostrar en pantalla datos relevantes
document.getElementById("phoneNumber").innerHTML=phoneNumber;
</script>
</body>
</html>
<html lang="es">
<head>
<meta charset="utf-8">
<title>Usuario Registrado</title>
</head>
<body>
<h1>Usuario Registrado</h1>
<a>Usuario Payphone: <strong id="phoneNumber"></strong></a><br>
<a>Respuesta: </a><br>
<script>
/*## Preparar credenciales como variables para la solicitud ##*/
const token="your_token_API";
const headers = {
"Content-Type": "application/json",
"Authorization": "Bearer "+token
};
/*## Preparar informacion del usuario Payphone ##*/
const phoneNumber="0984111333"; //ID Payphone Personal.
const countryCode="593"; //Codigo Pais
/*## Preparar informacion para la solicitud GET ##*/
//URL del servicio payphone
const url = "https://pay.payphonetodoesposible.com/api/Users/check/"+phoneNumber+"/region/"+countryCode;
fetch(url, {
method: "GET",
headers: headers
})
.then((res) => res.json())
.catch((error) => {
// Creamos las etiquetas <a>
const jsonResult = document.createElement("pre");
jsonResult.textContent = JSON.stringify(error, null, 2);
// Mostrar los enlaces en el documento con un salto de línea entre ellos
const container = document.createElement("div");
container.appendChild(jsonResult);
// Agregar los enlaces al body del documento o a un contenedor específico
document.body.appendChild(container);
})
.then((data) => {
// Creamos las etiquetas <a>
const jsonResult = document.createElement("pre");
jsonResult.textContent = JSON.stringify(data, null, 2);
// Mostrar los enlaces en el documento con un salto de línea entre ellos
const container = document.createElement("div");
container.appendChild(jsonResult);
// Agregar los enlaces al body del documento o a un contenedor específico
document.body.appendChild(container);
});
// Mostrar en pantalla datos relevantes
document.getElementById("phoneNumber").innerHTML=phoneNumber;
</script>
</body>
</html>