/** * @return array|bool 获取信息 */ private function getInfo() { $url = 'http://tree.neu.edu.cn/user/user.AccountManagement?operation=info&base_dn=self'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, $this->id . ':' . $this->pass); curl_setopt($ch, CURLOPT_REFERER, 'http://tree.neu.edu.cn/user/user.Account?operation=login'); curl_setopt($ch, CURLOPT_HEADER, 0); $infoPage = curl_exec($ch); curl_close($ch); //获取失败或者账户不活跃 if ($infoPage === false || false === strpos($infoPage, 'active')) { return false; } $html = preg_replace('/ /', '', $infoPage); $html = new DOM($html); $info = array(); list($id, $class) = explode(',', $html->find('font[color=#8b4513]', 0)->innertext); $info['id'] = explode('=', $id)[1]; $info['class'] = explode('=', $class)[1]; $info['balance'] = $html->find('font[color=#8b4513]', 2)->innertext; $info['name'] = $html->find('table tr', 1)->find('td', 1)->innertext; $info['tel'] = $html->find('table tr', 2)->find('td', 3)->innertext; return $info; }
/** * 获取账号数据 */ protected function getInfo() { //获取信息并显示 $mainFrame = "http://202.118.31.197/ACTIONFINDSTUDENTINFO.APPPROCESS"; $infoFrame = "http://202.118.31.197/ACTIONFINDSTUDENTINFO.APPPROCESS?mode=1&showMsg="; //获取基本信息 $ch = curl_init($infoFrame); curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile); curl_setopt($ch, CURLOPT_REFERER, $mainFrame); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); //follow redirects curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 2); $info = curl_exec($ch); curl_close($ch); $html = preg_replace('/ /', '', $info); $dom = new DOM($html); if ($dom === null) { $this->info = false; return; } $info = array(); foreach ($dom->find("table[width=100%] tr") as $tr) { if ($tr->children(2)) { $info[] = $tr->children(2)->innertext; } if ($tr->children(4)) { $info[] = $tr->children(4)->innertext; } } if (count($info) < 28) { $this->info = false; return; } $this->info =& $info; }