<?php
//FUNCION PARA ENCRIPTAR LA INFORMACION
function SignData($text, $privateKeyFile)
{
$private_cert = $privateKeyFile;
$f = fopen($private_cert,"r+");
if($f)
$private_key = fread( $f, filesize($private_cert) );
else
return "";
fclose($f);
$private_key = openssl_get_privatekey($private_key);
if(openssl_private_encrypt(md5($text), $crypt_text, $private_key))
{
return base64_url_encode($crypt_text);
}
return "";
}
function base64_url_encode($input) {
return strtr(base64_encode($input), '+/=', '-_,');
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_,', '+/='));
}
//FIN DE FUNCION PARA ENCRIPTAR LA INFORMACION
//INFORMACION PARA LA CONFIRMACION
$cl_servicio = 76;
$cl_folio = 10078;
$t_concepto = 1;
$cl_referencia = "18882 PAGO DE COLEGIATURA MARZO";
$dl_monto = "0.01";
$dt_fechaPago = "20180227";
$nl_tipoPago = "01";
$nl_status = "01";
//CONCATENAR
$cadenaDatos = $cl_folio."|".$t_concepto."|".$cl_referencia."|".$dl_monto."|".$dt_fechaPago."|".$nl_tipoPago."|".$nl_status."|";
//echo $cadenaDatos;
//GENERAR EL HASH
$vHash_sys = SignData($cadenaDatos, "./Private_key.pem");
$vHash = $vHash_sys;
function post_request($url, $data, $referer='') {
// Convert the data array into URL Parameters like a=b&foo=bar etc.
$data = http_build_query($data);
// parse the given URL
$url = parse_url($url);
if ($url['scheme'] != 'http') {
die('Error: Only HTTP request are supported !');
}
// extract host and path:
$host = $url['host'];
$path = $url['path'];
// open a socket connection on port 80 - timeout: 30 sec
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if ($fp){
// send the request headers:
fputs($fp, "POST $path HTTP/1.0\r\n");
fputs($fp, "Host: $host\r\n");
if ($referer != '')
fputs($fp, "Referer: $referer\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ". strlen($data) ."\r\n");
fputs($fp,"Cache-Control: no-cache\r\n");
fputs($fp, "\n");
fputs($fp, $data."\n");
/*fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);*/
$result = '';
while(!feof($fp)) {
// receive the results of the request
$result .= fgets($fp, 2048);
}
}
else {
return array(
'status' => 'err',
'error' => "$errstr ($errno)"
);
}
// close the socket connection:
fclose($fp);
// split the result header from the content
$result = explode("\r\n\r\n", $result, 2);
$header = isset($result[0]) ? $result[0] : '';
$content = isset($result[1]) ? $result[1] : '';
// return as structured array:
return array(
'status' => 'ok',
'header' => $header,
'content' => $content
);
}
// Submit those variables to the server
$post_data = array(
'cl_folio' => $cl_folio,
't_concepto=' => $t_concepto,
'cl_referencia' => $cl_referencia,
'dl_monto' => $dl_monto,
'dt_fechaPago' => $dt_fechaPago,
'nl_tipoPago' => $nl_tipoPago,
'nl_status' => $nl_status,
'hash' => $vHash
);
// Send a request to example.com
$result = post_request('http://misitio2.com/and/confirmar.php', $post_data);
if ($result['status'] == 'ok'){
// Print headers
echo $result['header'];
echo '<hr />';
// print the result of the whole request:
echo $result['content'];
echo '<hr />';
echo http_build_query($post_data);
//echo "<script type=\"text/javascript\">window.location='http://misitio.net/ws/index.php/?".$pro.";</script>";
}
else {
echo 'A error occured: ' . $result['error'];
}
?>