Created
January 4, 2018 17:47
-
-
Save alpocr/be942a0641b02d93e5991e7eb680e746 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//------------- PRUEBA DE AUTENTICACION API 4G PAYMENTS ----------------------- | |
//Datos de conexion para el Api 4G | |
$Api_data = array("grant_type" => "client_credentials","client_id" => "[CLEINT_ID]", "client_secret" => "[CLIENT_SECRET]"); | |
$Api_Url = "https://api.payments.4geeks.io/authentication/token/"; | |
//------------------------------- CONEXION ------------------------------------ | |
//Url del servicio Web consultado | |
$Api_curlUri = curl_init($Api_Url); | |
//a true, obtendremos una respuesta de la url, en otro caso, | |
//true si es correcto, false si no lo es | |
curl_setopt($Api_curlUri, CURLOPT_RETURNTRANSFER, true); | |
//Se establece el Verbo POST | |
curl_setopt($Api_curlUri, CURLOPT_CUSTOMREQUEST, "POST"); | |
// onvertir data a JSON | |
$data_string = json_encode($Api_data); | |
//Se envia los datos, unicamente con la data en JSON | |
curl_setopt($Api_curlUri, CURLOPT_POSTFIELDS, $data_string); | |
curl_setopt($Api_curlUri, CURLOPT_HTTPHEADER, array('Content-Type: "application/json; charset=utf-8"', 'Content-Length: ' . strlen($data_string))); | |
//Se obtiene la respuesta, debes enviar $Api_curlUri la variable pasada no existia. | |
$Api_response = json_decode(curl_exec($Api_curlUri)); | |
//Se cierra el recurso CURL y se liberan los recursos del sistema | |
curl_close($Api_curl); | |
if(!$Api_response) { | |
echo "Error :("; | |
}else{ | |
echo "Access Token: " . $Api_response->access_token; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hay un error typo en la linea 33
curl_close($Api_curl); => curl_close($Api_curlUri);