Created
May 8, 2014 09:28
-
-
Save chiliec/e167296155fc11ddab04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$token = ''; // access_token | |
$antigate_key = ''; // http://antigate.com/panel.php?action=showkey | |
$online = api('account.setOnline', 'access_token='.$token); // Продлеваем online на 15 минут | |
if(isset($online["error"]["captcha_img"])) { | |
$img_captcha = $online["error"]["captcha_img"]; | |
$captcha_sid = $online["error"]["captcha_sid"]; | |
$antigate_response = antigate($antigate_key, $img_captcha); | |
//var_dump($antigate_response); | |
$online = api('status.set', 'access_token='.$token.'&captcha_sid='.$captcha_sid.'&captcha_key='.$antigate_response); | |
//var_dump($online); | |
} | |
function api($method, $param) { | |
$getApi = file_get_contents('https://api.vk.com/method/'.$method.'?'.$param); | |
return json_decode($getApi, true); | |
} | |
function antigate($key, $captcha) { | |
$captcha_path = 'captcha.jpg'; | |
file_put_contents($captcha_path, file_get_contents( $captcha ) ); | |
$postdata = array( | |
'method' => 'post', | |
'is_russian' => '1', | |
'key' => $key, | |
'file' => '@captcha.jpg', | |
); | |
while( true ) { | |
$getId = curler('http://antigate.com/in.php', null, $postdata); | |
if( strstr($getId, 'ERROR') ) { | |
$res = false; | |
break; | |
} else { | |
$captchaId = str_replace('OK|', '', $getId); | |
sleep(2); | |
while(true) { | |
$getText = curler('http://antigate.com/res.php?key='.$key.'&action=get&id='.$captchaId); | |
if( strstr('CAPCHA_NOT_READY', $getText) ) { | |
continue; | |
} elseif( $res = str_replace('OK|', '', $getText) ) { | |
break; | |
} | |
} | |
break; | |
} | |
} | |
unlink($captcha_path); | |
return $res; | |
} | |
function curler($url, $cookie = null, $post = null){ | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
if(isset($cookie)){ | |
curl_setopt($ch, CURLOPT_COOKIE, $cookie); | |
} | |
if(isset($post)){ | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); | |
} | |
$response = curl_exec($ch); | |
curl_close($ch); | |
return $response; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment