$lot_number, "captcha_output" => $captcha_output, "pass_token" => $pass_token, "gen_time" => $gen_time, "sign_token" => $sign_token ); $url = sprintf($api_server . "/validate" . "?captcha_id=%s", $captcha_id); $res = self::post_request($url,$query); $obj = json_decode($res,true); return $obj; } // 注意处理接口异常情况,当请求极验二次验证接口异常时做出相应异常处理 // pay attention to interface exceptions, and make corresponding exception handling when requesting GeeTest secondary verification interface exceptions or response status is not 200 // 保证不会因为接口请求超时或服务未响应而阻碍业务流程 // website's business will not be interrupted due to interface request timeout or server not-responding public static function post_request($url, $postdata) { $data = http_build_query($postdata); $options = array( 'http' => array( 'method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded", 'content' => $data, 'timeout' => 5 ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); if($http_response_header[0] != 'HTTP/1.1 200 OK'){ $result = array( "result" => "success", "reason" => "request geetest api fail" ); return json_encode($result); }else{ return $result; } } }