SRCMS·轻响应框架 V1.5正式版

SRCMS是专门为中小企业和互联网产品创业团队打造的应急响应中心网站建站框架
This commit is contained in:
Martin Zhou
2016-01-24 11:54:16 +08:00
parent 6471bb59ed
commit 65e4506677
87 changed files with 2837 additions and 1085 deletions

View File

@@ -0,0 +1,57 @@
<?php
/**
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4>
* @category ORG
* @package ORG
* @subpackage Net
* @author liujing <liujin0506@qq.com>
*/
class Geetestlib {
public function geetest_validate($challenge, $validate, $seccode, $key) {
$apiserver = 'api.geetest.com';
if (strlen($validate) > 0 && $this->check_result_by_private($challenge, $validate, $key)) {
$query = 'seccode='.$seccode;
$servervalidate = $this->http_post($apiserver, '/validate.php', $query);
if (strlen($servervalidate) > 0 && $servervalidate == md5($seccode)) {
return TRUE;
}
}
return FALSE;
}
private function check_result_by_private($origin, $validate, $key) {
return $validate == md5($key.'geetest'.$origin) ? TRUE : FALSE;
}
private function http_post($host, $path, $data, $port = 80) {
// $data = $this->fix_encoding($data);
$http_request = "POST $path HTTP/1.0\r\n";
$http_request .= "Host: $host\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded\r\n";
$http_request .= "Content-Length: " . strlen($data) . "\r\n";
$http_request .= "\r\n";
$http_request .= $data;
$response = '';
if (($fs = @fsockopen($host, $port, $errno, $errstr, 10)) == false) {
die ('Could not open socket! ' . $errstr);
}
fwrite($fs, $http_request);
while (!feof($fs))
$response .= fgets($fs, 1160);
fclose($fs);
$response = explode("\r\n\r\n", $response, 2);
return $response[1];
}
private function fix_encoding($str) {
$curr_encoding = mb_detect_encoding($str) ;
if($curr_encoding == "UTF-8" && mb_check_encoding($str,"UTF-8")) {
return $str;
} else {
return utf8_encode($str);
}
}
}
?>