/** * returns the URL of the script given in param if it exists, false otherwise * * @param string $script * @return string */ public function getUrl($script) { if (!array_key_exists($script, $this->url)) { $msg = "L'url pour le script {$script} n'existe pas ou n'est pas chargée. Vérifiez le paramétrage."; insertLogKwixo(__METHOD__ . ' : ' . __LINE__, $msg); return false; } return $this->url[$script]; }
/** * connects to a server, reaches the path and returns the response if connexion succeed, false otherwise * * @param string $header request header * @return mixed */ function connect($header) { //connects with SSL protocol if secure connection asked, HTTP protocol otherwise if ($this->is_ssl) { $socket = fsockopen('ssl://' . $this->host, $this->port, $this->errno, $this->errstr, KwixoSocket::TIMEOUT); } else { $socket = fsockopen($this->host, $this->port); } //if connection established if ($socket !== false) { $res = ''; //sends header and reads response if (@fputs($socket, $header)) { while (!feof($socket)) { $res .= fgets($socket, 128); } } else { insertLogKwixo(__METHOD__ . ' : ' . __LINE__, "Envoi des données impossible sur : " . $host); $res = false; } //closes the connexion fclose($socket); } else { //if connection failed, log insertLogKwixo(__METHOD__ . ' : ' . __LINE__, "Connexion socket impossible sur l'hôte {$host}. Erreur " . $this->errno . " : " . $this->errstr); $res = false; } //return the response return $res; }
* @return string * KO: Kwixo is not available * KC: Kwixo credit is not available * OK: each payment option is available */ protected function getServiceStatus($mobile = false) { if ($mobile) { $statusvar = 'mstatus'; } else { $statusvar = 'status'; } //connects and get the response of the ws Availabe $con = new KwixoSocket($this->getUrlavailable()); $res = $con->send(); //return 'KO' if the connexion failed if ($res === false || !isXMLstringKwixo($res)) { return 'KO'; } //builds an KwixoXMLElement to parse the server response $dom_response = new DOMDocument(); $dom_response->loadXML($res); $element_online = $dom_response->getElementsByTagName('online')->item(0); //returns the attribute containing the server status return $element_online->getAttribute($statusvar);