示例#1
0
 /**
  * Full proccessing of captcha decoding
  * @return bool
  * @throws Exception\NotFound
  * @throws Exception\TooMuchInputData
  */
 public function solveCaptcha()
 {
     $headers = array(new \SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', $this->_getMethodUrl('PobierzCaptcha'), 1), new \SoapHeader('http://www.w3.org/2005/08/addressing', 'To', $this->_getServiceUrl(), 0));
     $this->__setSoapHeaders($headers);
     $checkCaptcha = false;
     $captchaCheckCounter = 0;
     while (!$checkCaptcha && $captchaCheckCounter < 5) {
         $captchaCheckCounter++;
         $result = parent::PobierzCaptcha()->PobierzCaptchaResult;
         //            $this->debug("PobierzCaptcha: ".print_r($result, true));
         if (empty($result)) {
             $checkCaptcha = true;
             continue;
         }
         if (intval($result) == -1) {
             $this->_solveError();
             continue;
         }
         $decodedText = null;
         $this->debug('Captcha: ' . $result . "\n");
         if ($this->_mode == static::MODE_PRODUCTION) {
             if ($this->dbcClient == null) {
                 $this->dbcClient = new DeathByCaptcha\SocketClient($this->dbcUser, $this->dbcPass);
             }
             if ($captcha = $this->dbcClient->decode('data:image/jpeg;base64,' . $result, 20)) {
                 $decodedText = $captcha['text'];
             }
         } else {
             $decodedText = 'aaaaa';
         }
         if (!empty($decodedText)) {
             $headers = array(new \SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', $this->_getMethodUrl('SprawdzCaptcha'), 1), new \SoapHeader('http://www.w3.org/2005/08/addressing', 'To', $this->_getServiceUrl(), 0));
             $this->__setSoapHeaders($headers);
             $checkCaptcha = parent::SprawdzCaptcha(array('pCaptcha' => $decodedText))->SprawdzCaptchaResult;
             $this->debug('Sprawdz captcha: ' . $checkCaptcha . "\n");
             if ($this->_mode == static::MODE_PRODUCTION && !$checkCaptcha && !empty($captcha)) {
                 $this->dbcClient->report($captcha['captcha']);
             }
         }
     }
     return true;
 }
示例#2
0
 /**
  * @see Client::__construct()
  */
 public function __construct($username, $password)
 {
     if (!extension_loaded('curl')) {
         throw new Exception\RuntimeException('CURL extension not found');
     }
     if (function_exists('json_decode')) {
         $this->_response_type = 'application/json';
         $this->_response_parser = array($this, 'parse_json_response');
     } else {
         $this->_response_type = 'text/plain';
         $this->_response_parser = array($this, 'parse_plain_response');
     }
     parent::__construct($username, $password);
 }
示例#3
0
 /**
  * @see Client::__construct()
  */
 public function __construct($username, $password)
 {
     // PHP for Windows lacks EAGAIN errno constant
     if (!defined('SOCKET_EAGAIN')) {
         define('SOCKET_EAGAIN', 11);
     }
     foreach (array('json') as $k) {
         if (!extension_loaded($k)) {
             throw new Exception\RuntimeException("Required {$k} extension not found, check your PHP configuration");
         }
     }
     foreach (array('json_encode', 'json_decode', 'base64_encode') as $k) {
         if (!function_exists($k)) {
             throw new Exception\RuntimeException("Required {$k}() function not found, check your PHP configuration");
         }
     }
     parent::__construct($username, $password);
 }