| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- // Obtener conexión de la base de datos
- require_once 'conexionBD.php';
- // Llamar librería de soap
- require_once("soap/nusoap.php");
-
- // require_once("procesar_formularios.php");
- mysqli_query($conexion, "SET NAMES utf8");
- // Set timezone
- date_default_timezone_set('America/Monterrey');
- ini_set('upload_max_filesize', '10M');
- ini_set('post_max_size', '10M');
- ini_set('max_input_time', 300);
- ini_set('max_execution_time', 300);
- // Consultar las URL existentes en los productos
- $queryConsulta = "SELECT ID, EASYVENTURL FROM ITT_ALP_GLOBAL WHERE EASYVENTURL != ''";
- $resultado = mysqli_query($conexion, $queryConsulta) or die("Algo ha ido mal en la consulta a la base de datos");
- $arrURLEasyVent = array();
- while ($columna = mysqli_fetch_assoc($resultado)) {
- $arrURLEasyVent[] = array(
- "ID" => trim($columna['ID']),
- "URL" => trim($columna['EASYVENTURL']),
- );
- }
- // Los servidores se obtuvieron de la página http://proxydb.net/?country=MX ** Todos son de México
- $arrProxies = array(); // Lista de Proxies para realizar las peticiones
- $arrProxies[0]['proxyAndPuerto'] = '201.159.22.164:46809';
- $arrProxies[0]['tipoProxy'] = CURLPROXY_SOCKS4;
- $arrProxies[1]['proxyAndPuerto'] = '201.144.20.231:5678';
- $arrProxies[1]['tipoProxy'] = CURLPROXY_SOCKS4;
- $arrProxies[2]['proxyAndPuerto'] = '45.167.253.129:999';
- $arrProxies[2]['tipoProxy'] = CURLPROXY_HTTPS;
- // Iteración de las URL de easyvent
- foreach ($arrURLEasyVent as $dataEasyVent) {
- $exito = true;
- $totalProxies = count($arrProxies) - 1;
-
- // Iteración de las proxies guardadas
- for ($i = 0; $i <= $totalProxies; $i++) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $dataEasyVent['URL']); // Dirección URL a capturar
- curl_setopt($ch, CURLOPT_PROXY, $arrProxies[$i]['proxyAndPuerto']); // El proxy HTTP para enviar peticiones a través de tunel.
- curl_setopt($ch, CURLOPT_PROXYTYPE, $arrProxies[$i]['tipoProxy']); // Puede ser CURLPROXY_HTTP (por defecto), CURLPROXY_SOCKS4, CURLPROXY_SOCKS5, CURLPROXY_SOCKS4A o CURLPROXY_SOCKS5_HOSTNAME
- curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Número máximo de segundos permitido para ejectuar funciones cURL
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); // Número de segundos a esperar cuando se está intentado conectar. Use 0 para esperar indefinidamente
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // "true" para seguir cualquier encabezado "Location: " que el servidor envíe como parte del encabezado HTTP (observe la recursividad, PHP seguirá tantos header "Location: " como se envíen, a no ser que la opción CURLOPT_MAXREDIRS esté establecida)
- //curl_setopt($ch, CURLOPT_MAXREDIRS, 10); // Número máximo de redirecciones HTTP a seguir. Use esta opción con CURLOPT_FOLLOWLOCATION
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // "true" para devolver el resultado de la transferencia como string del valor de curl_exec() en lugar de mostrarlo directamente
- $data = curl_exec($ch); // Ejecuta la sesión cURL que se le pasa como parámetro
- $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Obtener información sobre una transferencia específica -> El último código de respuesta. A partir de PHP 5.5.0 y cURL 7.10.8, este es un alias heredado de CURLINFO_RESPONSE_CODE
- curl_close($ch); // Cierra la sesión cURL
-
- // Comprobación si se obtuvo los datos del proxy
- if (($httpcode >= 200) && ($httpcode < 300)) {
- $contenido = $data;
-
- // Identificar si se obtuvo la tabla
- if ( !empty($contenido) ) {
-
- // Contenido de la tabla
- $tablaHTML = "<div class='section section-grey'>";
- $seccionGris = strstr($contenido, "section section-grey");
- $removeFooter = strstr($seccionGris, "section cookie-warning", true);
- $tablaHTML .= ("<div class=\" " . $removeFooter . "\" >");
- $tablaHTML .= "</div>";
- // Cambiar las comillas dobles "" por comillas simples ''
- $tablaHTML = str_replace("'", '"', $tablaHTML);
-
- // Variable de fecha de modificación
- $fechaHoy = date("Y-m-d");
- $FUPD = date("Y-m-d H:i:s");
- // Consultar si existe en la tabla de datos de easyvent
- $queryConsulta = " SELECT IDPROD, FECHAMOD FROM ITT_ASW_EASYVENT WHERE IDPROD = '" . $dataEasyVent['ID'] . "' ";
- $resultado = mysqli_query($conexion, $queryConsulta) or die("Algo ha ido mal en la consulta a la base de datos");
- $arrEasy = array();
- while ($columna = mysqli_fetch_assoc($resultado)) {
- $arrEasy = array(
- "IDPROD" => trim($columna['IDPROD']),
- "FECHAMOD" => trim($columna['FECHAMOD'])
- );
- }
- $dateTimeEasyVent = date("Y-m-d", strtotime($arrEasy['FECHAMOD'] ));
- // Verificar si existe para modificar o ingresar el nuevo dato
- if ( empty($arrEasy) ) {
- $queryInsert = "INSERT INTO ITT_ASW_EASYVENT (IDPROD, DATATABLE, FECHAMOD) VALUES ('" . trim($dataEasyVent['ID']) . "', '" . trim($tablaHTML) . "', '" . trim($FUPD) . "');";
- if (!mysqli_query($conexion, $queryInsert)) {
- $exito = false;
- $errorDescripcion = 'SQL INSERT MEX|' . $dataEasyVent['ID'];
- $respuesta = conectarWebService($errorDescripcion, "sendEtlError");
- }else{
- goto next;
- }
- }else if( !empty($arrEasy) && $fechaHoy > $dateTimeEasyVent) {
- $queryUpdate = "UPDATE ITT_ASW_EASYVENT SET DATATABLE = '" . trim($tablaHTML) . "', FECHAMOD = '" . trim($FUPD) . "' WHERE ( IDPROD = '" . trim($dataEasyVent['ID']) . "' );";
- if (!mysqli_query($conexion, $queryUpdate)) {
- $exito = false;
- $errorDescripcion = 'SQL UPDATE MEX|' . $dataEasyVent['ID'];
- $respuesta = conectarWebService($errorDescripcion, "sendEtlError");
- }else{
- goto next;
- }
- }
- } else {
- $exito = false;
- $errorDescripcion = 'EMPTY TABLE MEX|' . $dataEasyVent['ID'];
- $respuesta = conectarWebService($errorDescripcion, "sendEtlError");
- }
- }else{
- $exito = false;
- $errorDescripcion = 'ERROR PROXY MEX|' . $dataEasyVent['ID'];
- $respuesta = conectarWebService($errorDescripcion, "sendEtlError");
- }
- }
- next:
- }
- fin_extraerTabla:
- if($exito == false){
- $respuesta = conectarWebService($errorDescripcion, "sendEtlError");
- }
-
- function conectarWebService($dataPlain, $function) {
- // URL del webservice
- $wsdl = "https://smart.solerpalau.mx/QA/WS001_ASW.php?wsdl";
- // Verificamos si esta disponible
- $headers = @get_headers($wsdl);
- if (preg_match('/^HTTP\/\d\.\d\s+(200|301|302)/', $headers[0])) {
- // Instanciando un nuevo objeto cliente para consumir el webservice
- $client = new nusoap_client($wsdl, 'wsdl');
-
- $param = array('datos' => $dataPlain);
-
- // Llamando al método y pasándole el array con los parámetros
- $resultado = $client->call($function, $param);
- return $resultado;
- }
- }
-
|