public function actionEdboupdate($id) { $model = Personspeciality::model()->findByPk($id); if (Yii::app()->user->checkAccess("wsAllowEdit")) { try { $link = Yii::app()->user->getEdboSearchUrl() . "request.jsp"; $client = new EHttpClient($link, array('maxredirects' => 30, 'timeout' => 120)); $client->setParameterPost(array("personIdMySql" => $model->PersonID, "personSpeciality" => $id)); $response = $client->request(EHttpClient::POST); if ($response->isSuccessful()) { $obj = (object) CJSON::decode($response->getBody()); //Yii::log(print_r($obj,1)); if ($obj->error) { Yii::app()->user->setFlash("message", $obj->message); } else { Yii::app()->user->setFlash("message", $obj->message); } } else { Yii::app()->user->setFlash("message", "Синхронізація не виконана! Спробуйте пізніше."); } } catch (Exception $e) { Yii::app()->user->setFlash("message", "Синхронізація не виконана! Спробуйте пізніше."); } } else { Yii::app()->user->setFlash("message", WebServices::$MSG_EDBO_EDIT_DENY); } echo CJSON::encode(array("result" => "success", "data" => "")); }
protected function getUserLocation() { if (!empty($this->_userLocation)) { return $this->_userLocation; } $client = new EHttpClient(self::IP_ADDRESS_DATABASE); $client->setParameterGet('ip', $this->getUserHostAddress()); $response = $client->request(); $this->_userLocation = CJSON::decode($response->getBody()); return $this->_userLocation; }
/** * actionEdboupdate - запрос на синхронизацию документов * @param type $personid */ public function actionEdboupdate() { if (Yii::app()->user->checkAccess("wsAllowEdit")) { if (isset($_GET['personid'])) { try { $personid = $_GET['personid']; $link = Yii::app()->user->getEdboSearchUrl() . "persondocumentsaddedbo.jsp"; $client = new EHttpClient($link, array('maxredirects' => 30, 'timeout' => 120)); $client->setParameterPost(array("personIdMySql" => $personid)); $response = $client->request(EHttpClient::POST); if ($response->isSuccessful()) { $obj = (object) CJSON::decode($response->getBody()); if ($obj->error) { Yii::app()->user->setFlash("message", $obj->message); } } else { Yii::app()->user->setFlash("message", "Синхронізація не виконана! Спробуйте пізніше."); } } catch (Exception $e) { Yii::app()->user->setFlash("message", "Синхронізація не виконана! Спробуйте пізніше."); } } else { if (isset($_GET['docid'])) { try { $id = $_GET['docid']; $link = Yii::app()->user->getEdboSearchUrl() . "editdocumentedbo.jsp"; $client = new EHttpClient($link, array('maxredirects' => 30, 'timeout' => 120)); $client->setParameterPost(array("documentIdMySql" => $id)); $response = $client->request(EHttpClient::POST); if ($response->isSuccessful()) { $obj = (object) CJSON::decode($response->getBody()); Yii::log($response->getBody()); // if ($obj->error) { Yii::app()->user->setFlash("message", $obj->message); //} } else { Yii::app()->user->setFlash("message", "Синхронізація не виконана! Спробуйте пізніше."); } } catch (Exception $e) { Yii::app()->user->setFlash("message", "Синхронізація не виконана! Спробуйте пізніше."); } } } } else { Yii::app()->user->setFlash("message", WebServices::$MSG_EDBO_EDIT_DENY); } echo CJSON::encode(array("result" => "success", "data" => "")); }
/** * @desc curl http request * @param type $url * @param type $param(POST parameter) * @param type $header (Request header) * @return string / */ public static function requestCurl($url, $param = array(), $header = array()) { if ($url != '') { try { $client = new EHttpClient($url, array('maxredirects' => 0, 'timeout' => 60000)); $client->setMethod(EHttpClient::POST); if (!empty($header)) { $client->setHeaders($header); } if (!empty($param)) { $client->setParameterPost($param); } //$client->setRawData($tokenJsonStr,'json'); $response = $client->request(); } catch (Exception $e) { $response = new EHttpResponse('Client side exception', array(), "", '1.1', PHP_EOL . 'Exception: ' . $e->getMessage() . PHP_EOL); } //App::pr($response,9); if ($response->getStatus() == '200') { return $response->getBody(); } else { if ($response->getStatus() == '207') { $resp = $response->getBody(); //$resp = App::objtoarray(json_decode($resp)); return $resp; } else { if ($response->getStatus() == '201') { return '1'; ## if status 201, than insertion on db through api is successfull. } else { //App::pr($response,8); return 'error'; } } } } }
/** * Attempt to detect the MIME type of a file using available extensions * * This method will try to detect the MIME type of a file. If the fileinfo * extension is available, it will be used. If not, the mime_magic * extension which is deprected but is still available in many PHP setups * will be tried. * * If neither extension is available, the default application/octet-stream * MIME type will be returned * * @param string $file File path * @return string MIME type */ protected function _detectFileMimeType($file) { $type = null; // First try with fileinfo functions if (function_exists('finfo_open')) { if (self::$_fileInfoDb === null) { self::$_fileInfoDb = @finfo_open(FILEINFO_MIME); } if (self::$_fileInfoDb) { $type = finfo_file(self::$_fileInfoDb, $file); } } elseif (function_exists('mime_content_type')) { $type = mime_content_type($file); } // Fallback to the default application/octet-stream if (!$type) { $type = 'application/octet-stream'; } return $type; }
/** * Send request to the proxy server * * @param string $method * @param EUriHttp $uri * @param string $http_ver * @param array $headers * @param string $body * @return string Request as string */ public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '') { // If no proxy is set, fall back to default Socket adapter if (!$this->config['proxy_host']) { return parent::write($method, $uri, $http_ver, $headers, $body); } // Make sure we're properly connected if (!$this->socket) { throw new EHttpClientException(Yii::t('EHttpClient', "Trying to write but we are not connected")); } $host = $this->config['proxy_host']; $port = $this->config['proxy_port']; if ($this->connected_to[0] != $host || $this->connected_to[1] != $port) { throw new EHttpClientException(Yii::t('EHttpClient', "Trying to write but we are connected to the wrong proxy server")); } // Add Proxy-Authorization header if ($this->config['proxy_user'] && !isset($headers['proxy-authorization'])) { $headers['proxy-authorization'] = EHttpClient::encodeAuthHeader($this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']); } // if we are proxying HTTPS, preform CONNECT handshake with the proxy if ($uri->getScheme() == 'https' && !$this->negotiated) { $this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers); $this->negotiated = true; } // Save request method for later $this->method = $method; // Build request headers $request = "{$method} {$uri->__toString()} HTTP/{$http_ver}\r\n"; // Add all headers to the request string foreach ($headers as $k => $v) { if (is_string($k)) { $v = "{$k}: {$v}"; } $request .= "{$v}\r\n"; } // Add the request body $request .= "\r\n" . $body; // Send the request if (!@fwrite($this->socket, $request)) { throw new EHttpClientException(Yii::t('EHttpClient', "Error writing request to proxy server")); } return $request; }
/** * SendEdboRequest - отправляет запрос на добавление персоны в Edbo * * @return boolean - сигнализирует о возможности сохранения персоны в локальной базе * Если false - рекомендуется откатить транзакцию или удалить созданную персону */ public function SendEdboRequest() { if (!Yii::app()->user->checkAccess("wsAllowEdit")) { Yii::app()->user->setFlash("message", '<h3 style="color: red;">' . WebServices::$MSG_EDBO_EDIT_DENY . '</h3>'); return false; } $params = array("personIdMySql" => $this->idPerson, "entrantDocumentIdMySql" => $this->getEntrantdoc()->idDocuments, "personalDocumentIdMySql" => $this->getPersondoc()->idDocuments); Yii::log("ID = " . $this->idPerson); Yii::log("E = " . $this->getEntrantdoc()->idDocuments); Yii::log("P = " . $this->getPersondoc()->idDocuments); // debug($this->idPerson); // debug($this->entrantdoc->idDocuments); try { $client = new EHttpClient(Yii::app()->user->getEdboSearchUrl() . "personaddedbo.jsp", array('maxredirects' => 30, 'timeout' => 120)); $client->setParameterPost($params); $response = $client->request(EHttpClient::POST); if ($response->isSuccessful()) { //debug($response->getBody()); $obj = (object) CJSON::decode($response->getBody()); if ($obj->backTransaction) { Yii::app()->user->setFlash("message", '<h3 style="color: red;">' . $obj->message . '</h3>'); //debug($obj->message); return false; } else { // $this->edboID = $obj->id; // $this->codeU = $obj->id; Yii::app()->user->setFlash("message", '<h3 style="color: red;">' . $obj->message . '</h3>'); //debug("Cинхронизаниция выполнена"); } } else { Yii::app()->user->setFlash("message", '<h3 style="color: red;">Помилка! Спробуйте пізніше!</h3>'); //debug($response->getRawBody()); } } catch (Exception $e) { Yii::app()->user->setFlash("message", '<h3 style="color: red;">Помилка! Спробуйте пізніше!</h3>'); //debug($e->getMessage()); } return true; }
public static function updatePersonDoc($idPerson) { $script = "edbo_documents_edit.jsp"; //?edboId=" . $edboId . "&base64=".$base64; $srv = Yii::app()->user->getEdboSearchUrl(); try { $client = new EHttpClient($srv . $script, array('maxredirects' => 30, 'timeout' => 120)); $client->setParameterPost(array("idPersonMySql" => $idPerson)); $response = $client->request(EHttpClient::POST); if ($response->isSuccessful()) { $res = $response->getBody(); //Yii::log(print_r($res,1)); //Yii::log($res); } else { throw new Exception(WebServices::$MSG_EDBO_ERROR); } if ($res === false) { throw new Exception(WebServices::$MSG_EDBO_ERROR); } $error = CJSON::decode($res); if (is_array($error) && isset($error['error'])) { throw new Exception($error['error']); } } catch (Exception $ex) { if (defined('YII_DEBUG')) { Yii::log($ex->getMessage(), CLogger::LEVEL_INFO, 'WebServices::updatePersonDoc'); } throw $ex; } return $res; }
$status = '{"status":"-1"}'; echo $status; die; } } } public function doPost($url, $config = NULL, $params = NULL, $localFile = NULL, $fileUploadFormName = NULL, $methodType = "") { try { $client = new EHttpClient($url); if (isset($methodType) && $methodType != "") { $client->setMethod(EHttpClient::POST); } else { $client->setMethod(EHttpClient::GET); } $client->setParameterPost($params); if ($localFile) { // Upload item to database $client->setFileUpload($localFile, $fileUploadFormName); }
public function SendRequestForUpdate($ip) { if (defined('HTTP_REQUEST_TO_POINT')) { $requestData = array("update_need" => true); $requestAddr = 'http://' . $ip . "/sc_upd"; try { $client = new EHttpClient($requestAddr, array('maxredirects' => 3, 'timeout' => 10, 'adapter' => 'EHttpClientAdapterCurl')); $client->setParameterGet($requestData); $response = $client->request(); $body = ""; if ($response->isSuccessful()) { $body = $response->getBody(); } else { $body = $response->getRawBody(); } } catch (Exception $ex) { error_log("http request exception - " . json_encode($ex) . ". " . "IP - " . $requestAddr . ", " . "Post - " . json_encode($requestData)); } } }