extraeInfo.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <?php
  2. class AccesoPortal
  3. {
  4. const HOST_ = 'easyvent.solerpalau.com'; //'www.oanda.com/lang/es/currency/classic-converter';
  5. const HEADER_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36';
  6. const HEADER_ACCEPT = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
  7. public static $URL_TC;
  8. public static $p;
  9. private $cookie;
  10. private $sesion;
  11. public function __construct()
  12. {
  13. //https://www.tracepartsonline.net/global/viewer.aspx?Mode=3DWebGL&xmp=-1-59-5SILENT100.xmp&previewCad=5SILENT100&h=30&w=30&version=3&Lang=en&fwsid=SOLER_PALAU_MX&CF=0&PMLOG=0&show2DToolbar=1
  14. self::$URL_TC = 'https://' . self::HOST_ . '/callbacks.aspx?m=UpdateTechnicalData&fanIndex=0&_=1545121360677';
  15. // Ocultar Warnings por errores de HTML
  16. libxml_use_internal_errors(true);
  17. }
  18. /*
  19. * Realiza en inicio de sesión en el Portal de Oanda
  20. */
  21. public function buscarInfo($url)
  22. {
  23. $urlSeccionada = explode('|',$url);
  24. $urlCompleta = $urlSeccionada[0];
  25. $modelo = $urlSeccionada[1];
  26. $headers = array(
  27. 'User-Agent' => self::HEADER_USER_AGENT,
  28. 'Referer' => self::$URL_TC,
  29. );
  30. $respuesta = RespuestaCurl::request('https://' . self::HOST_ . '/'.$urlCompleta, null, $headers);
  31. // https://easyvent.solerpalau.com/fan-info/view/00019/192/594/p/5FUTURE-100/1
  32. $html = $respuesta->getBody();
  33. //echo $html;
  34. //die();
  35. $form = $this->getFormData($respuesta->getBody());
  36. // echo $form['__VIEWSTATE'];
  37. // echo $form['ctl00$ContentPlaceHolder1$AeroChart$aeroSettingsJSON'];
  38. // var_dump($form);
  39. $post = array( '__ASYNCPOST' =>'false',
  40. '__EVENTARGUMENT' => '',
  41. '__EVENTTARGET' => '',
  42. '__VIEWSTATE' => $form['__VIEWSTATE'],
  43. '__LASTFOCUS' => '',
  44. 'ctl00$ContentPlaceHolder1$ScriptManager1'=>'form1'
  45. );
  46. $respuesta = RespuestaCurl::request(self::$URL_TC, $post, $headers);
  47. $html = $respuesta->getBody();
  48. //echo($respuesta);
  49. $array = json_decode($html, true);
  50. // die();
  51. //print($array['dutyPointTechnicalInformations'][0]['technicalData'][1]['Value']);
  52. // $data = $array['chartMiniSourceLarge'];
  53. // list($type, $data) = explode(';', $data);
  54. // list(, $data) = explode(',', $data);
  55. // $data = base64_decode($data);
  56. // file_put_contents('imagen3.png', $data);
  57. // $imagen = "<img src='data:image/png;base64,".base64_encode($data)."' />";
  58. //***********************************************************
  59. $respuesta = RespuestaCurl::request('https://www.tracepartsonline.net/global/viewer.aspx?Mode=3DWebGL&xmp=-1-49-'.$modelo.'.xmp&previewCad='.$modelo.'&h=340&w=360&version=3&Lang=en&fwsid=SOLER_PALAU_MX&CF=0&PMLOG=0&show2DToolbar=1', null, array('User-Agent' => self::HEADER_USER_AGENT, 'Referer' => 'www.tracepartsonline.net'));
  60. $html = $respuesta->getRequestHeader();
  61. $src = string_get_before((string)$html, '/global/viewer.aspx');
  62. $src = string_get_after($src, 'GET ' );
  63. $respuesta = RespuestaCurl::request('https://www.tracepartsonline.net' . $src . '/ws/SOLER_PALAU_MX/reference.aspx?reference='.$modelo.'', null, array('User-Agent' => self::HEADER_USER_AGENT, 'Referer' => 'www.tracepartsonline.net'));
  64. $html = $respuesta->getBody();
  65. //$respuesta = RespuestaCurl::request('https://www.tracepartsonline.net' . $src . '/global/viewer.aspx?Mode=3DWebGL&xmp=-1-59-'.$modelo.'.xmp&previewCad='.$modelo.'&h=340&w=360&version=3&Lang=en&fwsid=SOLER_PALAU_MX&CF=0&PMLOG=0&show2DToolbar=1', null, array('User-Agent' => self::HEADER_USER_AGENT, 'Referer' => 'www.tracepartsonline.net'));
  66. //$html = $respuesta->getBody();
  67. // echo $src . '<br>';
  68. /*
  69. echo '<div class="product3d">
  70. <iframe src="https://www.tracepartsonline.net' . $src . '/global/viewer.aspx?Mode=3DWebGL&xmp=-1-59-'.$modelo.'.xmp&previewCad='.$modelo.'&h=440&w=460&version=3&Lang=en&fwsid=SOLER_PALAU_MX&CF=0&PMLOG=0&show2DToolbar=1" id="view3d" style="border:0;height:440px;width:100%;">
  71. </iframe>
  72. </div>';
  73. */
  74. /*
  75. Imprime en pantalla el modelo 3D según el producto
  76. */
  77. echo '<div class="product3d">
  78. <iframe src="https://www.traceparts.com/els/soler-palau-mx/en/api/viewer/3d?SupplierID=SOLER_PALAU_MX&PartNumber='.$modelo.'" id="view3d" style="border:0;height:440px;width:100%;">
  79. </iframe>
  80. </div>';
  81. //echo '<object type="text/html" data="https://www.tracepartsonline.net' . $src . '/global/viewer.aspx?Mode=3DWebGL&xmp=-1-59-5SILENT100.xmp&previewCad=5SILENT100&h=340&w=360&version=3&Lang=en&fwsid=SOLER_PALAU_MX&CF=0&PMLOG=0&show2DToolbar=1" width="360" height="340"></object><br>';
  82. //echo '<object type="text/html" data="https://easyvent.solerpalau.com/images/products/19-RD04.jpg?w=125" width="125" height="125"></object>';
  83. /*echo $imagen;
  84. echo '<table id="tblAccessories" class="table table-striped">' .
  85. '<tr>' .
  86. '<td class="accessoryImage"><img src="https://easyvent.solerpalau.com/images/products/19-RD04.jpg?w=125" /></td><td class="accessoryLabel">ACC REGULADOR VEL. DESLIZABLE - Utilizable en aplicaciones de gama hábitat, debido a su agradable presentación y fácil manejo. Monofasico 127V AC 60 Hz. Fabricados en plástico y certificados con normativa UL de seguridad. Color blanco.</td>' .
  87. '</tr><tr>' .
  88. '<td class="accessoryImage"><img src="https://easyvent.solerpalau.com/images/products/19-IE0noimagen.jpg?w=125" /></td><td class="accessoryLabel">ACC INTERRUPTOR ELECTRONICO - Utilizable en aplicaciones de gama hábitat, debido a su agradable presentación y fácil manejo. Monofasico 127V AC 60 Hz. Fabricados en plástico y certificados con normativa UL de seguridad. Cuenta con 4 diferentes rangos de tiempo delimitables por el usuario. Rango de carga para el temporizador de 20A/1HP. Color blanco.</td>' .
  89. '</tr><tr>' .
  90. '<td class="accessoryImage"><img src="https://easyvent.solerpalau.com/images/products/19-CS03.jpg?w=125" /></td><td class="accessoryLabel">ACC CONTROL SIMULTANEO VENT - Permite regular la operación del ventilador de acuerdo con el porcentaje de humedad indicado, garantizando las condiciones internas deseadas.<br><strong>Características:</strong><br><li>Ideal para su colocación en baños, cocinas o lavanderías.</li><li>Precaución: La humedad del aire fuera del recinto, debe ser menor que la humedad dentro del recinto, para que el sensor funcione correctamente.</li><li>Aumenta el control del flujo dependiendo de las necesidades del usuario</li></td>' .
  91. '</tr><tr>' .
  92. '<td class="accessoryImage"><img src="https://easyvent.solerpalau.com/images/products/19-DFA.jpg?w=125" /></td><td class="accessoryLabel">FL0425 DUCTO FLEX.DE ALUM.4X2 5 2 DEFLE - Aplicable a los extractores de cocina, baños y la serie TD, y en general en cualquier sistema de ventilación.</td>' .
  93. '</tr><tr>' .
  94. '<td class="accessoryImage"><img src="https://easyvent.solerpalau.com/images/products/19-HSnW.jpg?w=125" /></td><td class="accessoryLabel">HS4W PERSIANA 3 ALETAS 4 (DEF LE) - Persianas de sobrepresión construidas en material termoplástico estabilizado contra los rayos UV.</td>' .
  95. '</tr>' ,
  96. '</table>';*/
  97. }
  98. public function getArrayDatos()
  99. {
  100. $headers = array(
  101. 'User-Agent' => self::HEADER_USER_AGENT,
  102. 'Referer' => self::$URL_TC,
  103. );
  104. $respuesta = RespuestaCurl::request('https://' . self::HOST_ . '/fan-info/view/00019/192/595/p/5SILENT100/1/', null, $headers);
  105. $form = $this->getFormData($respuesta->getBody());
  106. //echo $form['__VIEWSTATE'];
  107. //print_r($form);
  108. $post = array( '__ASYNCPOST' =>'false',
  109. '__EVENTARGUMENT' => '',
  110. '__EVENTTARGET' => '',
  111. '__VIEWSTATE' => $form['__VIEWSTATE'],
  112. '__LASTFOCUS' => '',
  113. 'ctl00$ContentPlaceHolder1$ScriptManager1'=>'form1'
  114. );
  115. $respuesta = RespuestaCurl::request(self::$URL_TC, $post, $headers);
  116. $html = $respuesta->getBody();
  117. $array = json_decode($html, true);
  118. //print_r($array);
  119. print($array['dutyPointTechnicalInformations'][0]['technicalData'][1]['Value']);
  120. die();
  121. $data = $array['chartSource'];
  122. list($type, $data) = explode(';', $data);
  123. list(, $data) = explode(',', $data);
  124. $data = base64_decode($data);
  125. file_put_contents('imagen.png', $data);
  126. echo $html;
  127. die();
  128. }
  129. public function compara($modelo,$numero,$serie,$categoria)
  130. {
  131. $headers = array(
  132. 'User-Agent' => self::HEADER_USER_AGENT,
  133. 'Referer' => self::$URL_TC,
  134. );
  135. $respuesta = RespuestaCurl::request('https://' . self::HOST_ . '/series-info/'.$serie.'/'.$categoria, null, $headers);
  136. $html = $respuesta->getBody();
  137. $form = $this->getFormData($respuesta->getBody());
  138. $respuesta = RespuestaCurl::request('https://easyvent.solerpalau.com/callbacks.aspx?m=CloneFan&datarow='.$numero.'&model='.$modelo.'&series='.$serie.'&cat='.$categoria.'&sku=p&_='.time(), null, array('User-Agent' => self::HEADER_USER_AGENT, 'Referer' => 'easyvent.solerpalau.com'));
  139. // ultima llamada para generar la imagen(no mover)
  140. $respuesta = RespuestaCurl::request('https://easyvent.solerpalau.com/chartimage.aspx?m=1&s='.$serie.'&w=400&h=400&d=1552326936376', null, array('User-Agent' => self::HEADER_USER_AGENT, 'Referer' => 'easyvent.solerpalau.com'));
  141. $data = $respuesta->getBody();
  142. $imagen = "<img src='data:image/png;base64,".base64_encode($data)."' />";
  143. return $imagen;
  144. }
  145. public function getTablaSoler($url)
  146. {
  147. $headers = array(
  148. 'User-Agent' => self::HEADER_USER_AGENT,
  149. 'Referer' => self::$URL_TC,
  150. );
  151. // $respuesta = RespuestaCurl::request('https://' . self::HOST_ . '/series-info/595/192', null, $headers);
  152. $respuesta = RespuestaCurl::request($url, null, $headers);
  153. $body = $respuesta->getBody();
  154. $body = str_replace("../../", "https://easyvent.solerpalau.com/", $body);
  155. $tablaHTML = "<div class='section section-grey'>";
  156. $seccionGris = strstr($body, "section section-grey");
  157. $removeFooter = strstr($seccionGris, "section cookie-warning",true);
  158. $tablaHTML .= ("<div class=\" ".$removeFooter."\" >");
  159. $tablaHTML .= "</div>";
  160. echo $tablaHTML;
  161. }
  162. /**
  163. * Devuelve el XML del CFDI como string
  164. */
  165. public function obtenerXml($url)
  166. {}
  167. public function headerPortalCfdi($referer, $ajax){}
  168. /**
  169. * Guarda el XML del CFDI en la ruta especificada
  170. */
  171. public function guardarXml($url, $nombre)
  172. {}
  173. public function guardarAcuse($url, $dir, $nombre)
  174. {}
  175. public function obtenerSesion()
  176. {
  177. return base64_encode(
  178. json_encode(RespuestaCurl::getCookie())
  179. );
  180. }
  181. public function restaurarSesion($sesion)
  182. {}
  183. private function getPostResponse($url, $post = null, $encabezados = null)
  184. {
  185. $response = RespuestaCurl::request($url, $post, $encabezados, true);
  186. return $response;
  187. }
  188. private function getGetResponse($url, $encabezados = null)
  189. {
  190. $response = RespuestaCurl::request($url, null, $encabezados);
  191. return $response;
  192. }
  193. private function getTableObjects($html)
  194. {}
  195. private function getFormData($html_source)
  196. {
  197. $document = new DOMDocument();
  198. $document->loadHTML($html_source);
  199. if ($document) {
  200. $post = array();
  201. // Configuración anterior.
  202. // $form = $document->getElementsByTagName('form')->item(2);
  203. $form = $document->getElementsByTagName('form')->item(0);
  204. foreach (array('input', 'span') as $element) {
  205. foreach ($form->getElementsByTagName($element) as $val) {
  206. $name = $val->getAttribute('name');
  207. $id = false;
  208. if(empty($name))
  209. {
  210. $name = $val->getAttribute('id');
  211. $id = true;
  212. }
  213. if (!empty($name)) {
  214. $checked = $val->getAttribute('checked');
  215. $value = NULL;
  216. if ($val->nodeName == 'select') {
  217. $opcion_seleccionada = $val->getElementsByTagName('option')->item(0)->getAttribute('selected');
  218. if (!empty($opcion_seleccionada)) {
  219. $value = $val->getElementsByTagName('option')->item(0)->nodeValue;
  220. }
  221. }
  222. if (!empty($checked)) {
  223. $post[$name] = utf8_decode($val->getAttribute('checked'));
  224. } else if (!empty($value)) {
  225. $post[$name] = $value;
  226. } else if ($id) {
  227. $post[$name] = $val->nodeValue;
  228. } else {
  229. $post[$name] = utf8_decode($val->getAttribute('value'));
  230. }
  231. }
  232. }
  233. }
  234. return $post;
  235. }
  236. return null;
  237. }
  238. private function getFormResult($html_source)
  239. {
  240. $document = new DOMDocument();
  241. $document->loadHTML($html_source);
  242. if ($document) {
  243. $classname = "result_msg";
  244. $finder = new DomXPath($document);
  245. $form = $finder->query("//*[contains(@class, '$classname')]");
  246. $post = array();
  247. foreach ($form as $node) {
  248. foreach ($node->childNodes as $child) {
  249. $post[] = array($child->nodeName => utf8_decode($child->nodeValue));
  250. }
  251. }
  252. return $post;
  253. }
  254. return null;
  255. }
  256. private function obtenerArchivoString($url)
  257. {}
  258. }
  259. function string_get_before($string, $before)
  260. {
  261. return substr($string, 0, strpos($string, $before));
  262. }
  263. function string_get_after($string, $after)
  264. {
  265. $pos = strpos($string, $after) + strlen($after);
  266. return substr($string, $pos, strlen($string) - $pos);
  267. }
  268. class filaInfo
  269. {
  270. public $rfc;
  271. public $nombre;
  272. public $correo;
  273. public $servicio;
  274. public $ultimoMovimiento;
  275. public $siguientePaso;
  276. public $linkEmisor;
  277. public $linkSaldo;
  278. }
  279. class RespuestaCurl
  280. {
  281. private $respuesta;
  282. private static $cookie = array();
  283. public function __construct($respuesta)
  284. {
  285. $this->respuesta = $respuesta;
  286. }
  287. public static function setCookie($cookie)
  288. {
  289. self::$cookie = $cookie;
  290. return true;
  291. }
  292. public static function request($url, $post = null, $headers = null, $useCookies = true)
  293. {
  294. $options = array(
  295. CURLOPT_URL => $url,
  296. CURLOPT_RETURNTRANSFER => true,
  297. CURLOPT_HEADER => true,
  298. CURLOPT_FOLLOWLOCATION => true,
  299. CURLOPT_ENCODING => "UTF-8",
  300. CURLOPT_AUTOREFERER => true,
  301. CURLOPT_CONNECTTIMEOUT => 120,
  302. CURLOPT_TIMEOUT => 120,
  303. CURLOPT_MAXREDIRS => 10,
  304. CURLINFO_HEADER_OUT => true,
  305. CURLOPT_SSL_VERIFYPEER => false,
  306. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1
  307. );
  308. if ($useCookies) {
  309. if ($cookie = self::getCookieString()) {
  310. $options[CURLOPT_COOKIE] = $cookie;
  311. }
  312. }
  313. if ($post) {
  314. if (empty($headers)) {
  315. $headers = array();
  316. }
  317. $options[CURLOPT_POST] = 1;
  318. $options[CURLOPT_POSTFIELDS] = http_build_query($post);
  319. } else {
  320. $options[CURLOPT_CUSTOMREQUEST] = 'GET';
  321. }
  322. if ($headers) {
  323. $postStr = array();
  324. foreach ($headers as $key => $value) {
  325. $postStr[] = $key . ': ' . $value;
  326. }
  327. $options[CURLOPT_HTTPHEADER] = $postStr;
  328. }
  329. $ch = curl_init();
  330. curl_setopt_array($ch, $options);
  331. $rough_content = curl_exec($ch);
  332. $err = curl_errno($ch);
  333. $errmsg = curl_error($ch);
  334. $header = curl_getinfo($ch);
  335. $multi = curl_multi_getcontent($ch);
  336. curl_close($ch);
  337. $header_content = substr($rough_content, 0, $header['header_size']);
  338. $body_content = trim(str_replace($header_content, '', $rough_content));
  339. preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $header_content, $matches);
  340. $cookies = array();
  341. foreach ($matches[1] as $item) {
  342. $pos = strpos($item, '=');
  343. $cookies[substr($item, 0, $pos)] = substr($item, $pos + 1);
  344. }
  345. self::$cookie = array_merge(self::$cookie, $cookies);
  346. $header['errno'] = $err;
  347. $header['errmsg'] = $errmsg;
  348. $header['headers'] = $header_content;
  349. $header['content'] = $body_content;
  350. $header['cookies'] = $cookies;
  351. $res = new self($header);
  352. return $res;
  353. }
  354. public static function getCookie()
  355. {
  356. return self::$cookie;
  357. }
  358. public function getStatusCode()
  359. {
  360. return $this->respuesta['http_code'];
  361. }
  362. public function getBody()
  363. {
  364. return $this->respuesta['content'];
  365. }
  366. public function getRequestHeader()
  367. {
  368. return $this->respuesta['request_header'];
  369. }
  370. private static function getCookieString()
  371. {
  372. if (!empty(self::$cookie)) {
  373. $str = '';
  374. foreach (self::$cookie as $key => $value) {
  375. $str .= $key . '=' . $value . '; ';
  376. }
  377. $str = rtrim($str, '; ');
  378. return $str;
  379. }
  380. return '';
  381. }
  382. }
  383. // $url ="https://easyvent.solerpalau.com/series-info/594/192";
  384. // $accesoPortal = new AccesoPortal();
  385. // echo $accesoPortal-> buscarInfo();