前几天做了个大学英语四六级成绩查询系统,一个 phprpc 版本,一个 wap 版本。它们的核心代码都是相同的。下面就是从 etang.cet 获取大学英语四六级成绩的核心代码:
下载: cetquery.php
-
function query($examid, $examtype) {
-
$examid = trim($examid);
-
$examtype = trim($examtype);
-
if (!is_numeric($examid)) {
-
return '准考证号码必须是数字';
-
}
-
if (strlen($examid) != 15) {
-
return '准考证号码不正确';
-
}
-
if ($examtype == '1') {
-
if ((substr($examid, 6, 4) != '0521') &&
-
(substr($examid, 6, 4) != '1052')) {
-
return '准考证号码与考试类型不符';
-
}
-
}
-
if ($examtype == '2') {
-
if ((substr($examid, 6, 4) != '0512') &&
-
(substr($examid, 6, 4) != '0522') &&
-
(substr($examid, 6, 4) != '2052')) {
-
return '准考证号码与考试类型不符';
-
}
-
}
-
$examid1 = substr($examid, 0, 6) . $examtype . '052' . substr($examid, 10, 5);
-
$request = "examtype=$examtype&examid=$examid&image.x=23&image.y=32";
-
$content_len = strlen($request);
-
$handle = @fsockopen('cet.etang.com', 80, $errno, $errstr, 10);
-
$buf = '';
-
$id = base_convert(mt_rand().mt_rand(), 10, 36);
-
if ($handle) {
-
$http_request =
-
"POST /dog/cet HTTP/1.0\r\n" .
-
"Accept: */*\r\n" .
-
"Referer: http://cet.etang.com/cet_girldemand_$id.htm\r\n" .
-
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Alexa Toolbar)\r\n" .
-
"Host: cet.etang.com\r\n" .
-
"Content-Type: application/x-www-form-urlencoded\r\n" .
-
"Content-Length: $content_len\r\n" .
-
"Cache-Control: no-cache\r\n" .
-
"Cookie: zi=A; examid1=$examid; examtype1=$examtype; sex=girl; examid=$examid1; examtype=$examtype\r\n" .
-
"\r\n" .
-
$request;
-
fputs($handle, $http_request, strlen($http_request));
-
while (!feof($handle)) {
-
$buf .= fgets($handle, 128);
-
}
-
fclose($handle);
-
}
-
else {
-
return "查询服务器暂时无法连接";
-
}
-
$buf = explode("\r\n", $buf);
-
$buf = $buf[11];
-
$score = "";
-
if (substr($buf, 0, 18) == 'Set-Cookie: score=') {
-
$score = substr($buf, 18, strpos($buf, ';') - 18);
-
}
-
if (($score != '') and ($score != 'error')) {
-
$score = explode(',', $score);
-
}
-
else {
-
return '你所查询的准考证号码不存在';
-
}
-
return $score;
-
}