function satxmlsv32_genera_xml($arr, $edidata, $dir, $nodo, $addenda) { global $xml, $ret; $xml = new DOMdocument("1.0", "UTF-8"); satxmlsv32_generales($arr, $edidata, $dir, $nodo, $addenda); satxmlsv32_emisor($arr, $edidata, $dir, $nodo, $addenda); satxmlsv32_receptor($arr, $edidata, $dir, $nodo, $addenda); satxmlsv32_conceptos($arr, $edidata, $dir, $nodo, $addenda); satxmlsv32_impuestos($arr, $edidata, $dir, $nodo, $addenda); satxmlsv32_complemento($arr, $edidata, $dir, $nodo, $addenda); $ok = satxmlsv32_valida(); if (!$ok) { display_xml_errors(); die("Error al validar XSD\n"); } satxmlsv32_addenda($arr, $edidata, $dir, $nodo, $addenda); }
setlocale(LC_MONETARY, 'es_MX'); require './include/fpdf.php'; require_once './include/qrcode.class.php'; require_once './include/xml2array.php'; require_once './include/makepdf.php'; require_once './include/funciones.php'; $texto = file_get_contents("./F3970190-D5AD-49B4-A5BC-E38258926183.xml"); // FACTURA QUE SE MANDARA AL PDF ///////////////////////////////////////////////////////////////////////////// libxml_use_internal_errors(true); // Gracias a Salim Giacoman $xml = new DOMDocument(); $ok = $xml->loadXML($texto); if (!$ok) { display_xml_errors(); die; } if (strpos($texto, "cfdi:Comprobante") !== FALSE) { $tipo = "cfdi"; } elseif (strpos($texto, "<Comprobante") !== FALSE) { $tipo = "cfd"; } elseif (strpos($texto, "retenciones:Retenciones") !== FALSE) { $tipo = "retenciones"; } else { die("Tipo de XML no identificado ...."); } //////////////////////////////////////////////////////////////////////////// // Con XPath obtenemos el valor de los atributos del XML $xp = new DOMXpath($xml); $data['tipo'] = $tipo;
function valida_xsd() { /* * Todos los archivos que se requieren para hacer la validacion * fueron descargados del portal del SAT pero los tengo localmente * almacenados en mi maquina para que las validaciones sean mas rapidas. * Ademas el archivo prinicpal cfdv32.xsd esta 'un poco' modifcado para * que importe los complementos * * */ global $data, $xml, $texto; libxml_use_internal_errors(true); // Gracias a Salim Giacoman if ($data['tipo'] == "retenciones") { switch ($data['version']) { case "1.0": echo "Version 1.0 Retenciones<br>"; $ok = $xml->schemaValidate("xsd/retencionpagov1.xsd"); break; default: $ok = false; echo "Version invalida {$tipo} " . $data['version'] . "<br>"; } } else { switch ($data['version']) { case "2.0": echo "Version 2.0 CFD<br>"; $ok = $xml->schemaValidate("xsd/cfdv2complemento.xsd"); break; case "2.2": echo "Version 2.2 CFD<br>"; $ok = $xml->schemaValidate("xsd/cfdv22complemento.xsd"); break; case "3.0": echo "Version 3.0 (CFDI)<br>"; $ok = $xml->schemaValidate("xsd/cfdv3complemento.xsd"); break; case "3.2": echo "Version 3.2 CFDI<br>"; $ok = $xml->schemaValidate("xsd/cfdv32.xsd"); break; default: $ok = false; echo "Version invalida {$tipo} " . $data['version'] . "<br>"; } } if ($ok) { echo "<h3>Esquema valido</h3>"; } else { echo "<h3>Estructura contra esquema incorrecta</h3>"; display_xml_errors(); } echo "<hr>"; }
/** * Edit certificate to add devices * * Add the device udid to the provisioning profile, return * true if the device was added without error, else false. * * @param string $provisioning_profile_id * @param string $device_number * @return boolean $result */ public static function editProvisioningProfile($provisioning_profile_id, $device_number) { /** * NOTE: This is the only function we needed without having * WebServices, so we have to parse the site. * * Step 1 connection to Apple Website * 1.1 get connetion urlfrom login page * 1.2 execute first part of login to get temp cookies * 1.3 execute last part to have a valid connetion cookie * * Step 2 parse form (get inputs and selects data to modify profile) * * Step 3 execute form action with data */ $login_url = 'https://daw.apple.com/cgi-bin/WebObjects/DSAuthWeb.woa/wa/login?' . 'appIdKey=D635F5C417E087A3B9864DAC5D25920C4E9442C9339FA9277951628F0291F620&' . 'path=%2F%2Fdevcenter%2Fios%2Findex.action'; $dom = new DOMDocument(); libxml_use_internal_errors(true); if ($dom->loadHTMLFile($login_url)) { $xpath = new DOMXPath($dom); $form = $xpath->query('//form[@name="appleConnectForm"]')->item(0); $login_post_url = $form->getAttribute('action'); } else { $errors = libxml_get_errors(); echo display_xml_errors($errors, $login_url); libxml_clear_errors(); return FALSE; } $login_post_url = 'https://daw.apple.com' . $login_post_url; $contents = 'theAccountName=' . self::$user . '&theAccountPW=' . self::$passwod; $ch = curl_init(); // Set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $login_post_url); curl_setopt($ch, CURLOPT_POSTFIELDS, $contents); curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0 Firefox/4.0', 'Accept: */*', 'Accept-Language: en-us', 'Connection: keep-alive')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); curl_setopt($ch, CURLOPT_HEADER, true); // Execute and close cURL $data = curl_exec($ch); curl_close($ch); foreach (preg_split("/(\r?\n)/", $data) as $line) { if (preg_match('/^Set-Cookie: (.*?)$/mi', $line, $matches)) { $cookies[] = $matches[1]; } } $url = 'https://developer.apple.com/devcenter/ios/index.action'; $ch = curl_init(); // Set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); foreach ($cookies as $cookie) { $values = split(';', $cookie); curl_setopt($ch, CURLOPT_COOKIE, $values[0]); } curl_setopt($ch, CURLOPT_HEADER, true); // Execute and close cURL $data = curl_exec($ch); curl_close($ch); foreach (preg_split("/(\r?\n)/", $data) as $line) { if (preg_match('/^Set-Cookie: (.*?)$/mi', $line, $matches)) { $cookies[] = $matches[1]; } } $edit_url = 'https://developer.apple.com/ios/manage/provisioningprofiles/edit.action?provDisplayId=' . $provisioning_profile_id; $ch = curl_init(); // Set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $edit_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); $totalCookie = ""; foreach ($cookies as $cookie) { $values = split(';', $cookie); $totalCookie .= $values[0] . "; "; } curl_setopt($ch, CURLOPT_COOKIE, $totalCookie); curl_setopt($ch, CURLOPT_HEADER, true); // Execute and close cURL $data = curl_exec($ch); curl_close($ch); //TODO: parse only inputs and select in the form named "save" // Load dom the page $dom = new DOMDocument(); libxml_use_internal_errors(true); if ($dom->loadHTML($data)) { $xpath = new DOMXPath($dom); $selects = $xpath->query('//select'); // Parse all select and retrieve selected value $keysValuesArray = NULL; foreach ($selects as $select) { $select_dom = new DOMDocument('1.0', 'utf-8'); $select_dom->loadHTML('<html></html>'); $select_dom->documentElement->appendChild($select_dom->importNode($select, true)); $xpath_select = new DOMXPath($select_dom); $option_selected = $xpath_select->query('//option[@selected="selected"]')->item(0); $key_value = $select->getAttribute('name') . '=' . $option_selected->getAttribute('value'); $keysValuesArray[$key_value] = $key_value; } // Parse all input and retrieve values (and add the UDID we want for this profile) $inputs = $xpath->query('//input'); foreach ($inputs as $input) { if ($input->getAttribute('type') == 'checkbox') { if ($input->getAttribute('checked') == 'checked' || $input->getAttribute('value') == $device_number) { $key_value = $input->getAttribute('name') . '=' . $input->getAttribute('value'); $keysValuesArray[$key_value] = $key_value; } } else { if ($input->getAttribute('type') != 'submit' && $input->getAttribute('type') != 'image') { $key_value = $input->getAttribute('name') . '=' . $input->getAttribute('value'); $keysValuesArray[$key_value] = $key_value; } } } $keysValuesArray[] = 'submit.x=0'; $keysValuesArray[] = 'submit.y=0'; //TODO: work in progress... (tmp: display url, data,...) $form = $xpath->query('//form[@name="save"]')->item(0); $edit_post_url = 'https://developer.apple.com' . $form->getAttribute('action'); $contents = ""; foreach ($keysValuesArray as $keyValue) { $contents .= '&' . str_replace(' ', '+', $keyValue); } } else { $errors = libxml_get_errors(); echo display_xml_errors($errors, $login_url); libxml_clear_errors(); return FALSE; } $ch = curl_init(); // Set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $edit_post_url); curl_setopt($ch, CURLOPT_POSTFIELDS, $contents); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); $totalCookie = ""; foreach ($cookies as $cookie) { $values = split(';', $cookie); $totalCookie .= $values[0] . "; "; } curl_setopt($ch, CURLOPT_COOKIE, $totalCookie); curl_setopt($ch, CURLOPT_HEADER, true); // Execute and close cURL $data = curl_exec($ch); curl_close($ch); $response = preg_split("/(\r?\n)/", $data); if ($response[0] == 'HTTP/1.1 100 Continue') { return TRUE; } else { return FALSE; } }
function valida_xsd() { /* * Todos los archivos que se requieren para hacer la validacion * fueron descargados del portal del SAT pero los tengo localmente * almacenados en mi maquina para que las validaciones sean mas rapidas. * Ademas el archivo prinicpal cfdv32.xsd esta 'un poco' modifcado para * que importe los complementos * * La version de mi maquina los pueden obtener de la misma URL * * http://www.lacorona.com.mx/fortiz/sat/cfdv32.xsd * http://www.lacorona.com.mx/fortiz/sat/ecc.xsd * http://www.lacorona.com.mx/fortiz/sat/... * * [dev@www sat]$ ls *xsd * Divisas.xsd cfdv3.xsd implocal.xsd * TimbreFiscalDigital.xsd cfdv32.xsd leyendasFisc.xsd * TuristaPasajeroExtranjero.xsd cfdv32complemento.xsd nomina.xsd * cfdiregistrofiscal.xsd cfdv3complemento.xsd nomina11.xsd * cfdv2.xsd cfdv3tfd.xsd pfic.xsd * cfdv22.xsd detallista.xsd spei.xsd * cfdv22complemento.xsd donat11.xsd terceros11.xsd * cfdv2complemento.xsd ecc.xsd ventavehiculos.xsd * cfdv2psgecfd.xsd iedu.xsd * * */ global $data, $xml, $texto; libxml_use_internal_errors(true); // Gracias a Salim Giacoman if ($data['tipo'] == "retenciones") { switch ($data['version']) { case "1.0": echo "Version 1.0 Retenciones<br>"; $ok = $xml->schemaValidate("retencionpagov1.xsd"); break; default: $ok = false; echo "Version invalida {$tipo} " . $data['version'] . "<br>"; } } else { switch ($data['version']) { case "2.0": echo "Version 2.0 CFD<br>"; $ok = $xml->schemaValidate("cfdv2complemento.xsd"); break; case "2.2": echo "Version 2.2 CFD<br>"; $ok = $xml->schemaValidate("cfdv22complemento.xsd"); break; case "3.0": echo "Version 3.0 (CFDI)<br>"; $ok = $xml->schemaValidate("cfdv3complemento.xsd"); break; case "3.2": echo "Version 3.2 CFDI<br>"; $ok = $xml->schemaValidate("cfdv32.xsd"); break; default: $ok = false; echo "Version invalida {$tipo} " . $data['version'] . "<br>"; } } if ($ok) { echo "<h3>Esquema valido</h3>"; } else { echo "<h3>Estructura contra esquema incorrecta</h3>"; display_xml_errors(); } echo "<hr>"; }
function valida_xsd($texto, $xsd, $xslt, $nodo) { libxml_use_internal_errors(true); $xml = new DOMDocument(); $ok = $xml->loadXML($texto); if (!$ok) { display_xml_errors(); die; } $ok = $xml->schemaValidate($xsd); if ($ok) { echo "<h3>Esquema valido</h3>"; checa_sello($texto, $xslt, $nodo); } else { echo "<h3>Estructura contra esquema incorrecta</h3>"; display_xml_errors(); $xml = false; } echo "<hr>"; return $xml; }