```
//使用前验证
public function get_geetest_status()
{
$GtSdk = new GeetestLib(C('CAPTCHA_ID'),C('PRIVATE_KEY'));
$data = array(
"user_id" => "0",
"client_type" => "web",
"ip_address" => $_SERVER['REMOTE_ADDR']
);
$status = $GtSdk->pre_process($data, 1);
session('gtserver',$status);
session('user_id',$data['user_id']);
echo $GtSdk->get_response_str();
}
protected function check_geetest()
{
$GtSdk = new GeetestLib(C('CAPTCHA_ID'),C('PRIVATE_KEY'));
$data = array(
"user_id" => session('user_id'),
"client_type" => "web",
"ip_address" => $_SERVER['REMOTE_ADDR']
);
if ($_SESSION['gtserver'] == 1) { //服务器正常
$result = $GtSdk->success_validate($_POST['geetest_challenge'], $_POST['geetest_validate'], $_POST['geetest_seccode'], $data);
if ($result) {
return '{"status":"success"}';
} else{
return '{"status":"fail"}';
}
}else{ //服务器宕机,走failback模式
if ($GtSdk->fail_validate($_POST['geetest_challenge'],$_POST['geetest_validate'],$_POST['geetest_seccode'])) {
return '{"status":"success"}';
}else{
return '{"status":"fail"}';
}
}
}
```