/** * 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; }