Commit 635a2235 authored by Kevin Puertas Ruiz's avatar Kevin Puertas Ruiz

Test JSON API check

parent 84cb21dc
...@@ -39,7 +39,6 @@ function DATABASE_CONN($ID_C,$URL){ ...@@ -39,7 +39,6 @@ function DATABASE_CONN($ID_C,$URL){
} }
} }
//WIP, doesnt compare right!
function JSON_API($ID_C,$URL,$params,$exceptedRes){ function JSON_API($ID_C,$URL,$params,$exceptedRes){
$type = explode('|',$params)[0]; $type = explode('|',$params)[0];
$JSONParams = explode('|',$params)[1]; $JSONParams = explode('|',$params)[1];
...@@ -48,10 +47,10 @@ function JSON_API($ID_C,$URL,$params,$exceptedRes){ ...@@ -48,10 +47,10 @@ function JSON_API($ID_C,$URL,$params,$exceptedRes){
if ($type == 'GET'){ if ($type == 'GET'){
curl_setopt($ch, CURLOPT_URL, $URL . $JSONParams); curl_setopt($ch, CURLOPT_URL, $URL . $JSONParams);
}else if ($type == 'POST'){ }else if ($type == 'POST'){
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $JSONParams); curl_setopt($ch, CURLOPT_POSTFIELDS, $JSONParams);
} }
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 4); //timeout in seconds curl_setopt($ch, CURLOPT_TIMEOUT, 4); //timeout in seconds
...@@ -60,9 +59,7 @@ function JSON_API($ID_C,$URL,$params,$exceptedRes){ ...@@ -60,9 +59,7 @@ function JSON_API($ID_C,$URL,$params,$exceptedRes){
$json_ret = json_decode($body,true); $json_ret = json_decode($body,true);
$json_param = json_decode($exceptedRes,true); $json_param = json_decode($exceptedRes,true);
$comp_ret =serialize($json_ret); if ($json_ret == $json_param){
$comp_param =serialize($json_param);
if ($comp_ret == $comp_param){
return 0; return 0;
}else{ }else{
return 1; return 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment