關於php使用curl類比登入教務網的問題
該系統用於查詢當中,學生可通過回複學號+密碼查詢自己的成績。
背景:
教務系統:正方的教務系統(http://jwxt.tjtc.edu.cn/)
我找到了一個不用驗證碼的入口:http://jwxt.tjtc.edu.cn/default3.aspx
現在需要通過這個入口類比登入,擷取學產生績。
目前已有如下代碼:
這段代碼基本上能夠類比登入從而擷取學生的成績、課表等等。
但是通過測試 擷取到的內容都是null 請問如何解決?是不是哪裡出問題了?
zfapi.php
function get_td_array($table) {
$table = preg_replace("']*?>'si","",$table);
$table = preg_replace("']*?>'si","",$table);
$table = preg_replace("']*?>'si","",$table);
$table = str_replace("","{tr}",$table);
$table = str_replace("","{td}",$table);
//去掉 HTML 標籤
$table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);
//去掉空白字元
$table = preg_replace("'([rn])[s]+'","",$table);
$table = preg_replace('/ /',"",$table);
$table = str_replace(" ","",$table);
$table = str_replace(" ","",$table);
$table = explode('{tr}', $table);
array_pop($table);
foreach ($table as $key=>$tr) {
$td = explode('{td}', $tr);
array_pop($td);
$td_array[] = $td;
}
return $td_array;
}
class SimulatedLogin {
private $username;//學號
private $password;//密碼
private $name;//姓名
private $operate;//操作
public $message = '';//返回資訊
public $url = 'http://jwxt.tjtc.edu.cn/';//教務網地址
public function __construct($username, $password, $operate) {
$this->username = $username;
$this->password = $password;
$this->operate = $operate;
//首先進行登陸, 方便後面擷取資料(好像在這裡出現問題)
$this->Simulated($this->url.'default3.aspx', TRUE, '__VIEWSTATE=%2FwEPDwUKMTg5NjY5MDM3OWRkSvPPSOtLv5y%2BuNo7W2Yge4y1bPI%3D&TextBox1='.$this->username.'&TextBox2='.$this->password.'&Button1=');
$this->getName();
}
public function returnJson() {
switch ($this->operate) {
case 'xinxi'://個人資訊查詢
$this->prifile();
break;
case 'dengji'://等級考試查詢
$this->getDjks();
break;
case 'chengji'://成績查詢
$this->getchengji();
break;
case 'kebiao'://課表查詢
$this->getKb();
break;
case 'bukao'://補考查詢
$this->getbukao();
break;
}
return $this->message;
}
/**
* 擷取個人資訊
*/
private function prifile() {
$result = $this->Simulated($this->url.'xsgrxx.aspx?xh='.$this->username.'&xm='.$this->name.'&gnmkdm=N121501');
preg_match_all('//', $result, $dataHeader);//1,0
preg_match_all('/(.*)<\/span>/', $result, $dataValue);//2
$dataValue1= array('id'=>strip_tags($dataValue[0][1]),'name'=>strip_tags($dataValue[0][8]),'cid'=>strip_tags($dataValue[0][46]),'xi'=>strip_tags($dataValue[0][54]),'zhuan'=>strip_tags($dataValue[0][64]));
$this->message = $dataValue1;
}
private function getKb() {//課表
$result = $this->Simulated($this->url.'xskbcx.aspx?xh='.$this->username.'&xm='.$this->name.'&gnmkdm=N121603');
preg_match_all('/
]*>([\s\S]*?)<\/table>/',$result,$rs); $arr = get_td_array($rs[0][0]); for ($d=1;$d<=7;$d++){$shuzu[$d][1]=$arr[1][$d];$shuzu[$d][2]=$arr[2][$d+1];$shuzu[$d][3]=$arr[3][$d];$shuzu[$d][4]=$arr[4][$d];$shuzu[$d][5]=$arr[5][$d];$shuzu[$d][6]=$arr[6][$d];$shuzu[$d][7]=$arr[7][$d];$shuzu[$d][8]=$arr[8][$d];$shuzu[$d][9]=$arr[9][$d];$shuzu[$d][10]=$arr[10][$d];$shuzu[$d][11]=$arr[11][$d];