01 14:53:04.785 [info] Copilot Chat: 0.33.3, VS Code: 1.106.3 2025-12-01 14:53:05.158 [info] copilot token chat_enabled: true, sku: free_limited_copilot 2025-12-01 14:53:05.158 [info] [code-referencing] Public code references are enabled. 2025-12-01 14:53:05.417 [info] Fetched model metadata in 260ms f6c7a719-cb6a-4b23-90af-87fe5d5f713a 2025-12-01 14:53:05.428 [info] ccreq:47640e2a.copilotmd | markdown 2025-12-01 14:53:17.834 [info] [fetchCompletions] Request 00f43918-6b71-4d58-8a3d-6a21ed328f07 at finished with 200 status after 213.60380299994722ms 2025-12-01 14:53:17.918 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-12-01 14:53:27.871 [info] [fetchCompletions] Request 18172d79-a8e4-418f-89ca-e2f3367de5fa at finished with 200 status after 252.50163999991491ms 2025-12-01 14:53:27.954 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-12-01 14:58:11.485 [info] [fetchCompletions] Request 032bf1f8-f11a-4849-b10e-dd116990194f at finished with 200 status after 347.52283499995247ms 2025-12-01 14:58:11.956 [info] [fetchCompletions] Request 3c7448ad-9488-4ad9-993c-85997069d0d0 at finished with 200 status after 183.64932999992743ms 2025-12-01 14:58:12.029 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-12-01 14:58:15.082 [info] [fetchCompletions] Request 2dd73d43-5495-4f63-bcd3-84564c12fe61 at finished with 200 status after 144.3325640000403ms 2025-12-01 14:58:15.211 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-12-01 14:58:15.439 [info] [fetchCompletions] Request 3328d42b-01dc-448f-8fc3-e6eb2aeac6e3 at finished with 200 status after 178.73666399996728ms 2025-12-01 14:58:15.658 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-12-01 14:58:16.032 [info] [fetchCompletions] Request dd372cf6-fdb9-4965-854a-3beb42ad017d at finished with 200 status after 151.5608109999448ms 2025-12-01 14:58:16.034 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-12-01 14:58:20.787 [info] [fetchCompletions] Request 93c2ce0b-d6ae-4e7d-910d-ff2b79206852 at finished with 200 status after 182.38706899993122ms 2025-12-01 14:58:20.893 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-12-01 14:58:21.175 [info] [fetchCompletions] Request 7ec29329-98dd-4b0d-9cba-7e4f06acfc21 at finished with 200 status after 204.26704599987715ms 2025-12-01 14:58:21.253 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-12-01 14:58:26.221 [info] [fetchCompletions] Request 40bab066-f5e8-4dc4-875f-b77053b9c229 at finished with 200 status after 238.06854000035673ms 2025-12-01 14:58:26.344 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-12-01 14:58:26.579 [info] [fetchCompletions] Request a99eed96-94c6-498e-9707-b8e70cf06296 at finished with 200 status after 162.79342900030315ms 2025-12-01 14:58:26.734 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-12-01 14:58:27.219 [info] [fetchCompletions] Request ece0a520-d4fc-40c0-8911-7b1bdf5c72e5 at finished with 200 status after 158.6065799999050 "300", "message" => "ERROR - [wsCancelInvoiceSFJ] Parametros incompletos para el Servicio Web, faltan el ID del CFDI a actualizar"); $Resultado = json_encode($j_array); echo $Resultado; return; } if($bDatPAC == "") { $j_array = array('code' => "300", "message" => "ERROR - [wsCancelInvoiceSFJ] Parametros incompletos para el Servicio Web, faltan los Datos del PAC"); $Resultado = json_encode($j_array); echo $Resultado; return; } ### 0. EXTRACCION DE PARAMETROS PARA EL CFDI ###################################################### #== Primero, extraemos el JSON del string en base 64 $bdDatPAC = base64_decode($bDatPAC); #== Segundo, decodificamos el JSON a un arreglo $abdDatPAC = json_decode($bdDatPAC,true); $dirBase = realpath("../"); # Configuración de zona horaria date_default_timezone_set('America/Mexico_City'); // ### DEFINICIÓN DE CONSTANTES ################################################### $SendaPEMS = "archs_pem/"; $SendaCFDI = "archs_cfdi/"; // Datos de acceso del usuario (proporcionados por el PAC). if($abdDatPAC["tipoTim"] == 1){ ## Timbrado en producción $urlPAC = "https://solucionfactible.com/ws/services/Timbrado?wsdl"; } else { ## Timbrado en pruebas $urlPAC = "https://testing.solucionfactible.com/ws/services/Timbrado?wsdl"; } // Datos para la configuracion del SOAP y los resultados. $username = $abdDatPAC["username"]; $password = $abdDatPAC["password"]; $bdUUID = $abdDatPAC["UUID"]; $fact_serie = $abdDatPAC["serie"]; $fact_folio = $abdDatPAC["folio"]; $invoiceNumber = $abdDatPAC["invoice"]; $invoiceID = $abdDatPAC["invoiceID"]; // Datos "constantes" para los archivos CER y KEY del cliente $noCertificado = $abdDatPAC["Certificado_SAT"]; $file_cer = $abdDatPAC["Archivo_CER"]; $file_key = $abdDatPAC["Archivo_KEY"]; $clavePrivada = $abdDatPAC["Clave_Privada"]; $noCertificado = "00001000000719969028"; $file_cer = "00001000000719969028.cer.pem"; $file_key = "00001000000719969028.key.pem"; $clavePrivada = "RZRSELLO25"; $organi_id_ZB = $abdDatPAC["organization_id_ZB"]; $authtoken_ZB = $abdDatPAC["authtoken_ZB"]; $authtoken_ZC = $abdDatPAC["authtoken_ZC"]; // Leemos el archivo CER del cliente $nombre_fichero = $SendaPEMS.$file_cer; $gestor = fopen($nombre_fichero, "r"); $cerFile = fread($gestor, filesize($nombre_fichero)); fclose($gestor); // Leemos el archivo KEY del cliente $nombre_fichero = $SendaPEMS.$file_key; $gestor = fopen($nombre_fichero, "r"); $keyFile = fread($gestor, filesize($nombre_fichero)); fclose($gestor); // Conversion de los archivos CER y KEY leidos a formato Base64 $bCertB64 = base64_encode($cerFile); $bKeyB64 = base64_encode($keyFile); ### PROCESO DE CACELACION ######################################################## $response = ''; if($abdDatPAC["tipoTim"] == 1){ ## Timbrado en producción $urlLocation = 'https://solucionfactible.com/ws/services/Timbrado'; } else { ## Timbrado en pruebas $urlLocation = 'https://testing.solucionfactible.com/ws/services/Timbrado'; } #== Se lleva a cabo cancelacion del CFDI ============================ try { $client = new SoapClient($urlPAC); $client->__setLocation($urlLocation); $params = array('usuario' => $username, 'password' => $password, 'uuids' => $bdUUID, 'derCertCSDBase64' => $bCertB64, 'derKeyCSDBase64' => $bKeyB64, 'contrasenaCSD' => $clavePrivada); $response = $client->__soapCall('cancelarBase64', array('parameters' => $params)); } catch (SoapFault $fault) { $j_array = array('code' => "400", "message" => $fault->faultcode."-".$fault->faultstring); $Resultado = json_encode($j_array); echo $Resultado; return; } $ret = $response->return; if($ret->status != 200) { $j_array = array('code' => "500", "message" => "ERROR EN EL PROCESO DE CANCELACION. ".$ret->status." - ".$ret->mensaje); $Resultado = json_encode($j_array); echo $Resultado; return; } $RespServ = $ret; #== Se asigna la respuesta del servidor a una variable de tipo DOM ==== //$NomArchXML = $invoiceNumber."_CFDI_".$fact_serie.str_pad($fact_folio, 6, "0", STR_PAD_LEFT)."_CC.xml"; $NomArchXML = "CFDI_".$fact_serie.str_pad($fact_folio, 6, "0", STR_PAD_LEFT)."_".$invoiceNumber."_CC.xml"; $xml = new DOMdocument('1.0', 'UTF-8'); $root = $xml->createElement("CFDICancelacion"); $root = $xml->appendChild($root); $root->setAttribute("status",$ret->status); $root->setAttribute("mensaje",$ret->mensaje); $child = $xml->createElement("CFDIResultadoCancelacion"); $child = $root->appendChild($child); $child->setAttribute("status", $ret->resultados->status); $child->setAttribute("mensaje", $ret->resultados->mensaje); $child->setAttribute("statusUUID", $ret->resultados->statusUUID); $child->setAttribute("UUID", $ret->resultados->uuid); $cfdi = $xml->saveXML(); $xml->formatOutput = true; $xml->save($SendaCFDI.$NomArchXML); unset($xml); chmod($SendaCFDI.$NomArchXML, 0777); //print_r($ret); $sUUID = $ret->resultados->uuid; $statusUUID = $ret->resultados->statusUUID; if ($statusUUID == "201") { $mensaje = $ret->resultados->mensaje; $iPosAcuse = mb_strpos($mensaje, "Acuse:"); $sMensaje = substr($mensaje, $iPosAcuse+7, 1000); $iPosDigest = mb_strpos($sMensaje, "Digest:"); $sAcuse = substr($sMensaje, 1, $iPosDigest-3); $sMensaje = substr($sMensaje, $iPosDigest+7, 1000); $iPosCerti = mb_strpos($sMensaje, "Certificado:"); $sDigest = substr($sMensaje, 1, $iPosCerti-3); $sMensaje = substr($sMensaje, $iPosCerti+13, 100); $sCertif = substr($sMensaje, 1, 25); # 13.3 Envio del Archivos a Invoice de Zoho Creator $file_name_with_full_path = '/var/www/html/aptusCFDIRF/archs_cfdi/'.$NomArchXML; $request_url = 'https://creator.zoho.com/api/xml/fileupload/scope=creatorapi'; if (function_exists('curl_file_create')) { // php 5.6+ $cFile = curl_file_create($file_name_with_full_path); } else { $cFile = '@' . realpath($file_name_with_full_path); } $post = array( 'authtoken' => $authtoken_ZC, 'applinkname' => 'cfdi', 'formname' => 'CreacionCFDIv33', 'fieldname' => 'File_CFDI_XML_CANC', 'recordId' => $bRecId, 'filename' => $NomArchXML, 'file'=> $cFile); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $r = curl_exec($ch); curl_close ($ch); # 13.4 Envio del Archivos a Invoice de Zoho Books $file_name_with_full_path = '/var/www/html/aptusCFDIRF/archs_cfdi/'.$NomArchXML; $request_url = 'https://www.zohoapis.com/books/v3/invoices/'.$invoiceID.'/attachment'; if (function_exists('curl_file_create')) { // php 5.6+ $cFile = curl_file_create($file_name_with_full_path); } else { $cFile = '@' . realpath($file_name_with_full_path); } $post = array( 'authtoken' => $authtoken_ZB, 'organization_id' => $organi_id_ZB, 'can_send_in_mail' => 'true', 'attachment'=> $cFile); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $r = curl_exec($ch); curl_close ($ch); $ra = json_decode($r); $resultXML = $ra->code.' - '.$ra->message; $j_array = array('code' => "200", "message" => "Proceso de cancelacion de CFDI fue exitoso", 'acuse' => $sAcuse, 'digest' => $sDigest, 'certificado' => $sCertif, 'uuid' => $sUUID, "statusUUID" => $statusUUID); } else { $mensaje = $ret->resultados->mensaje; $j_array = array('code' => $statusUUID, "message" => $mensaje, "statusUUID" => $statusUUID); } $Resultado = json_encode($j_array); echo $Resultado; return;