Last active
May 17, 2024 12:13
-
-
Save EdEichman/cee00064fbd3964d5cc56974023030fc to your computer and use it in GitHub Desktop.
La documentación de Correos Express para seguimientoEnvios no tiene documentación para PHP. Este Gist explica como llamar a seguimientoEnvios en PHP.
This file contains hidden or 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 | |
//Correos Express SeguimientoEnvio | |
//necesitaras el documento "DC_SP_apiRestSeguimientoEnviosFechas_03.pdf" - contacta con integraciones de correso express | |
$id_shipment = {CAMPO numShip DE cex_history}; | |
$url = "https://www.correosexpress.com/wpsc/apiRestSeguimientoEnvios/rest/seguimientoEnvios"; | |
$input_xml = "<?xml version='1.0' encoding='UTF-8'?> | |
<SeguimientoEnviosRequest xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' | |
xsi:noNamespaceSchemaLocation='SeguimientoEnviosRequest.xsd'> | |
<Solicitante>{------ Código de cliente - el mismo q utilizas para el modulo -----}</Solicitante> | |
<Dato>$id_shipment</Dato> | |
</SeguimientoEnviosRequest>"; | |
$headers = array( | |
'Content-Type: application/xml', | |
'Cache-Control: no-cache', | |
'Accept: */*', | |
'Accept-Encoding: gzip, deflate, br', | |
'Connection: keep-alive', | |
'Authorization: Basic '. base64_encode("{--- Usuario - el mismo q utilizas para el modulo -----}:{--- Contraseña - el mismo q utilizas para el modulo -----}") | |
); | |
$ch = curl_init(); | |
$result = curl_setopt($ch, CURLOPT_URL, $url); | |
if ($result) $result = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
if ($result) $result = curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
if ($result) $result = curl_setopt($ch, CURLOPT_POST, 1); | |
if ($result) $result = curl_setopt($ch, CURLOPT_POSTFIELDS, $input_xml); | |
if ($result) { | |
$data = curl_exec($ch); | |
} | |
curl_close($ch); | |
//extract the XML | |
$xml_start = strpos($data, '<?xml'); | |
$xml = substr($data, $xml_start); | |
$xml = simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOCDATA); | |
$json = json_encode($xml); | |
$result_array = json_decode($json,TRUE); | |
//Extract the delivery time | |
foreach ($result_array['EstadoEnvios'] as $key=>$value) { | |
if (12 /*ENTREGADO*/ == $value['CodEstado']) { | |
$year = substr($value['FechaEstado'], 4); | |
$month = substr($value['FechaEstado'], 2,2); | |
$day = substr($value['FechaEstado'], 0,2); | |
$hour = substr($value['HoraEstado'], 0,2); | |
$minute = substr($value['HoraEstado'], 2,2); | |
$second = substr($value['HoraEstado'], 4,2); | |
$date_time = date('Y-m-d H:i:s',mktime($hour, $minute, $second, $month, $day, $year)); | |
die($date_time); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Buenas @djboro1988 , este es el código para lo que pides, pasándole un JSON con los datos del envío:
`function grabarEnvio($json) {
//Preproducción
$url = 'https://www.test.cexpr.es/wspsc/apiRestGrabacionEnviok8s/json/grabacionEnvio';
//Producción
$url = 'https://www.cexpr.es/wspsc/apiRestGrabacionEnviok8s/json/grabacionEnvio';
}`