<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function API_V($s){
	$s=str_replace("'"," ",$s);
	return $s;
}
function DNI_GET_DATA($DNI){
	$curl = curl_init();
	curl_setopt_array($curl, [
	  CURLOPT_URL => "https://api.factiliza.com/v1/dni/info/".$DNI,
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => "",
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 30,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => "GET",
	  CURLOPT_HTTPHEADER => [
		"Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIzNzc1MiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6ImNvbnN1bHRvciJ9.K-Dv5ljqGyL6x5zPkwVANvdwaDbWKIzP4jCR0pdwWpU"
	  ],
	]);
	/*
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
	*/
	$response = curl_exec($curl);
	$err = curl_error($curl);
	curl_close($curl);
	if ($err) {
	  //echo "cURL Error #:" . $err;
	  return "|MS|Error|";
	} else {
	  $OBJ=json_decode($response);
		$STATUS=$OBJ->status;
		$NOM="";
		$APP="";
		$APM="";
		if($STATUS==200){
			$NOM=API_V($OBJ->data->nombres);
			$APP=API_V($OBJ->data->apellido_paterno);
			$APM=API_V($OBJ->data->apellido_materno);
			$DIR=API_V($OBJ->data->direccion_completa);
			$DEP=API_V($OBJ->data->departamento);
			$PRV=API_V($OBJ->data->provincia);
			$DIS=API_V($OBJ->data->distrito);
			//
			$FUL=$NOM." ".$APP." ".$APM;
			return  "|OK|".$DNI."|".$FUL."|".$DIR."|".$DEP."|".$PRV."|".$DIS."|";
		}else{
			return "|MS|Incoherencia de datos|";
		}
	}	
}
function RUC_GET_DATA($RUC){
	//CURLOPT_URL => "https://api.factiliza.com/v1/ruc/info/{ruc}"
	$curl = curl_init();
	curl_setopt_array($curl, [
	  CURLOPT_URL => "https://api.factiliza.com/v1/ruc/info/".$RUC,
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => "",
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 30,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => "GET",
	  CURLOPT_HTTPHEADER => [
		"Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIzNzc1MiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6ImNvbnN1bHRvciJ9.K-Dv5ljqGyL6x5zPkwVANvdwaDbWKIzP4jCR0pdwWpU"
	  ],
	]);
	/*
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
	*/
	$response = curl_exec($curl);
	$err = curl_error($curl);
	curl_close($curl);
	if($err){
	  //echo "cURL Error #:" . $err;
	  return "|MS|Error|";
	}else{
	  $OBJ=json_decode($response);
		$STATUS=$OBJ->status;
		$NOM="";
		if($STATUS==200){
			$NOM=$OBJ->data->nombre_o_razon_social;
			return  "|OK|".$RUC."|".$NOM."|";
		}else{
			return "|MS|Incoherencia de datos|";
		}
	}	
}
echo DNI_GET_DATA("41229173");
?>