✏️ 正在编辑: Conector.php
路径:
/srv/systems_dir/yuppiecred-bkp/library/Core/Minerador/Conector.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php abstract class Core_Minerador_Conector { protected static function getUrl($resource) { $local = "http://localhost/minerador/public/"; $remote = "https://websocket.sistemayuppie.com.br/scraping/public/"; return (APPLICATION_ENV == 'development' ? $local : $remote) . $resource; } protected static function generateToken() { $usuario = "admin"; $envDev = APPLICATION_ENV == 'development'; $senha = $envDev ? "teste123" : "VVz$6p^fP^Wd6MJU"; return base64_encode($usuario . ":" . $senha); } /** * Estrutura e envia a requisição ao servico * * @param array $fields * @param int $method * @return object * @throws Core_Exception * @throws Zend_Json_Exception */ protected function doRequest($url, array $fields = [], $method = null) { $handler = curl_init(); curl_setopt($handler, CURLOPT_URL, $url); curl_setopt($handler, CURLOPT_HEADER, 1); curl_setopt($handler, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($handler, CURLOPT_TIMEOUT, 900); curl_setopt($handler, CURLOPT_FORBID_REUSE, TRUE); curl_setopt($handler, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($handler, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "Authorization: Basic " . self::generateToken() ]); if ($method){ curl_setopt($handler, $method, TRUE); } if (!empty($fields) && !is_null($method)){ curl_setopt($handler, CURLOPT_POSTFIELDS, json_encode($fields)); } $response = curl_exec($handler); $info = curl_getinfo($handler); $body = substr($response, $info['header_size']); curl_close($handler); return $this->decodeResponse($info['http_code'], $body); } /** * Decodifica e valida as requisições * * @param mixed[int|string] $httpCode * @param string $response * * @return StdClass JsonObject * * @throws Core_Exception * @throws Zend_Json_Exception */ protected function decodeResponse($httpCode, $response) { $result = Zend_Json::decode($response, Zend_Json::TYPE_OBJECT); if (in_array($httpCode, [400, 401, 404, 422, 500])){ Yuppie_Log::write("_decodeResponse: " . print_r($response, true), $this); throw new Core_Exception($result->error, $httpCode); }elseif (!empty($result->error)){ throw new Core_Exception($result->error); } return $result; } }
💾 保存文件
← 返回文件管理器