コード例 #1
0
 private function recaptcha_submit()
 {
     if (App::runningInConsole()) {
         fwrite(STDOUT, "=========================== " . PHP_EOL);
         fwrite(STDOUT, "Captcha:" . PHP_EOL);
         fwrite(STDOUT, "=========================== " . PHP_EOL);
     }
     //
     $recaptcha_pk = '6Lco4fASAAAAAN0vsQR96BOKL3zbqb1eN0-5OhUr';
     $recaptchaUrl = "https://www.google.com/recaptcha/api/challenge?k=" . $recaptcha_pk . "&ajax=1&cachestop=0." . rand(111, 999) . '5810447420609';
     //
     echo PHP_EOL . "URL: " . $recaptchaUrl . PHP_EOL;
     $this->client->request('GET', $recaptchaUrl);
     $data = $this->client->getResponse()->getContent();
     print $data . PHP_EOL;
     preg_match("/challenge\\s*:\\s*'(.+?)'/is", $data, $challenge);
     $challenge = $challenge[1];
     dump($challenge);
     //
     $recaptchaUrl = 'http://www.google.com/recaptcha/api/reload?c=' . $challenge . '&k=' . $recaptcha_pk . '&reason=i&type=image&lang=en-GB&th=';
     //
     echo PHP_EOL . "URL: " . $recaptchaUrl . PHP_EOL;
     $this->client->request('GET', $recaptchaUrl);
     $data = $this->client->getResponse()->getContent();
     print $data . PHP_EOL;
     preg_match("@\\('(.+?)'@is", $data, $reload);
     $reload = $reload[1];
     dump($reload);
     $image_re = 'http://www.google.com/recaptcha/api/image?c=' . $reload . '&th=';
     $this->client->request('GET', $image_re);
     $image = $this->client->getResponse()->getContent();
     if ($this->debug) {
         if (App::runningInConsole()) {
             fwrite(STDOUT, "Captcha Solving" . PHP_EOL);
         }
     }
     $temp_img = 'so_captcha_' . str_slug($this->state->state_name) . '.jpg';
     Storage::put($temp_img, $image);
     $temp_img = storage_path() . '/app/' . $temp_img;
     $decaptcha = new Decaptcha($temp_img);
     $captcha_text = $decaptcha->process();
     dump($captcha_text);
     $this->debug = true;
     if ($this->debug) {
         echo "C: " . $captcha_text . PHP_EOL;
         if (App::runningInConsole()) {
             fwrite(STDOUT, "Captcha Solved" . PHP_EOL);
         }
     }
     $this->debug = false;
     $fields = array();
     $fields['__RequestVerificationToken'] = $this->token;
     $fields['challenge'] = $challenge;
     $fields['response'] = $captcha_text;
     $url = $this->url_base . "VerifyCaptchaJson";
     dump($fields);
     dump($url);
     $this->crawler = $this->client->request('POST', $url, $fields);
     $json = $this->client->getResponse()->getContent();
     $data = json_decode($json);
     dump($data);
     dump($data->success);
     if ($this->debug) {
         var_dump($data);
     }
     dd('-------------');
     unlink($temp_img);
     if (!$data->captchaValid) {
         if (App::runningInConsole()) {
             fwrite(STDOUT, "Captcha Failed : Resubmitting" . PHP_EOL);
         }
         $this->recaptcha_submit();
     }
 }
コード例 #2
0
 private function captcha_submit()
 {
     if (App::runningInConsole()) {
         fwrite(STDOUT, "=========================== " . PHP_EOL);
         fwrite(STDOUT, "Submit Captcha" . PHP_EOL);
         fwrite(STDOUT, "=========================== " . PHP_EOL);
     }
     try {
         $form_captcha = $this->crawler->selectButton('Continue')->form();
     } catch (\InvalidArgumentException $e) {
         if (App::runningInConsole()) {
             fwrite(STDOUT, "Revisit Captcha *" . PHP_EOL);
             fwrite(STDOUT, "=========================== " . PHP_EOL);
         }
         $url = $this->url_base . "Captcha.aspx";
         $this->crawler = $this->client->request('GET', $url);
         $form_captcha = $this->crawler->selectButton('Continue')->form();
     }
     $image = $this->url_base . $this->crawler->filter('#LBD_CaptchaImage img')->attr('src');
     $this->client->request('GET', $image);
     $image = $this->client->getResponse()->getContent();
     if (App::runningInConsole()) {
         fwrite(STDOUT, "Captcha *" . PHP_EOL);
     }
     $temp_img = 'so_captcha_' . str_slug($this->state->state_name) . '_' . uniqid() . '.jpg';
     Storage::put($temp_img, $image);
     $temp_img = storage_path() . '/app/' . $temp_img;
     $decaptcha = new Decaptcha($temp_img);
     $captcha_text = $decaptcha->process();
     if ($this->debug) {
         echo "C: " . $captcha_text . PHP_EOL;
         if (App::runningInConsole()) {
             fwrite(STDOUT, "Captcha Solved" . PHP_EOL);
         }
     }
     unlink($temp_img);
     $this->crawler = $this->client->submit($form_captcha, array('ctl00$ContentPlaceHolder1$CodeTextBox' => $captcha_text));
     if (App::runningInConsole()) {
         fwrite(STDOUT, "Captcha Submitted" . PHP_EOL);
     }
     unset($decaptcha);
     unset($image);
     unset($form_captcha);
     $this->check_uri();
 }