challenge; // $challenge = explode(";", $resp)[0]; // Then we are ready to make a call to 2captcha API $flag = 0; $error = null; try { $result = $solver->geetest([ 'gt' => 'c4c41e397ee921e9862d259da2a031c4', 'apiServer' => 'api.geetest.com', 'challenge' => $challenge, 'url' => 'https://www.mcbbs.net/plugin.php?id=dc_signin', ]); } catch (\Exception $e) { print_r($e->getMessage()); $error = $e->getMessage(); $flag ++; sleep(10); // 有时错误代码来得太快,循环时会卡在获取challenge的时候 } }while($flag < 10 && $error == "ERROR_CAPTCHA_UNSOLVABLE"); $data = json_decode($result->code,true); return $data; } function getFormHash(string $cookie) { $data = get("https://www.mcbbs.net/home.php?mod=spacecp&inajax=1",$cookie); preg_match("//",$data,$match); if(!isset($match[1])){ return false; } return $match[1]; } function get(string $url,string $cookie,array $header = null){ $c = curl_init(); curl_setopt($c,CURLOPT_URL,$url); curl_setopt($c,CURLOPT_COOKIE,$cookie); curl_setopt($c, CURLOPT_HEADER, 0); curl_setopt($c,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($c,CURLOPT_RETURNTRANSFER,true); curl_setopt($c,CURLOPT_HTTPHEADER, [ "Referer: https://www.mcbbs.net/plugin.php?id=dc_signin", "Connection: closed", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" ]); if(!is_null($header)) { curl_setopt($c,CURLOPT_HTTPHEADER, $header); } $x = curl_exec($c); curl_close($c); return $x; } function post(string $url,string $cookie, array $data,array $header = null) { $c = curl_init(); curl_setopt($c,CURLOPT_URL,$url); curl_setopt($c,CURLOPT_COOKIE,$cookie); curl_setopt($c, CURLOPT_HEADER, 0); curl_setopt($c,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($c,CURLOPT_RETURNTRANSFER,true); curl_setopt($c, CURLOPT_POST, 1); curl_setopt($c,CURLOPT_HTTPHEADER, [ "Referer: https://www.mcbbs.net/plugin.php?id=dc_signin", "Connection: closed", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" ]); if(!is_null($header)) { curl_setopt($c,CURLOPT_HTTPHEADER, $header); } curl_setopt($c, CURLOPT_POSTFIELDS, $data); $x = curl_exec($c); curl_close($c); return $x; } function checkSignIn (string $cookie) { $signUrl = "https://www.mcbbs.net/plugin.php?id=dc_signin:sign&inajax=1"; $check = get($signUrl, $cookie); if(!$check || preg_match("/您今日已经签过到/",$check)) { return true; } return false; } function signIn(string $cookie, string $emote,string $content,array $chal) { $signUrl = "https://www.mcbbs.net/plugin.php?id=dc_signin:sign&inajax=1"; $hash = getFormHash($cookie); if(!$hash){return false;} $result = post($signUrl, $cookie, [ "formhash" => $hash, "signsubmit" => "yes", "handlekey" => "signin", "emotid" => $emote, "referer" => "https://www.mcbbs.net/plugin.php?id=dc_signin", "content" => $content, "geetest_challenge" => $chal['geetest_challenge'], "geetest_validate" => $chal['geetest_validate'], "geetest_seccode" => $chal['geetest_seccode'] ]); if(!preg_match("/签到成功/",$result)){ echo $result.PHP_EOL; $res1[] = false; $res1[] = $result; return $res1; } $res2[] = true; $res2[] = $result; return $res2; } function sc_send( $text , $desp = '' , $key = '[SENDKEY]' ) { $data = array( 'text' => $text, 'desp' => $desp ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://sctapi.ftqq.com/'.$key.'.send'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); $headers = array(); $headers[] = 'Content-type: application/x-www-form-urlencoded'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $resp = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); return $resp; }