From 06f29a75a6d7bf044253b6c69b687a6de5e16d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=BF=97?= Date: Tue, 20 Jan 2026 17:09:27 +0800 Subject: [PATCH] update --- app/controller/Crawler.php | 20 +++++++++++++++++++- app/service/CrawlerService.php | 26 +++++++++++++++++++++----- view/crawler/index.html | 15 ++++++++++++++- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/app/controller/Crawler.php b/app/controller/Crawler.php index faeba02..76d09eb 100644 --- a/app/controller/Crawler.php +++ b/app/controller/Crawler.php @@ -175,6 +175,10 @@ class Crawler extends BaseController { try { $dsdm = $this->request->param('dsdm', ''); + $examid = $this->request->param('examid', ''); + $bmid = $this->request->param('bmid', ''); + $userid = $this->request->param('userid', ''); + $aa = $this->request->param('aa', ''); $cookiesParam = $this->request->param('cookies', ''); if (empty($dsdm)) { @@ -184,6 +188,20 @@ class Crawler extends BaseController ]); } + if (empty($examid) || empty($bmid) || empty($userid)) { + return json([ + 'code' => 0, + 'msg' => '请填写examid、bmid和userid', + ]); + } + + if (empty($aa)) { + return json([ + 'code' => 0, + 'msg' => '缺少aa参数,请先获取地区选项再获取职位代码', + ]); + } + if (empty($cookiesParam)) { return json([ 'code' => 0, @@ -201,7 +219,7 @@ class Crawler extends BaseController } $service = new CrawlerService(); - $treeData = $service->getPositionTree($dsdm, $cookies); + $treeData = $service->getPositionTree($dsdm, $examid, $bmid, $userid, (string)$aa, $cookies); // 提取所有CODE作为zwdm $zwdmList = []; diff --git a/app/service/CrawlerService.php b/app/service/CrawlerService.php index 8b4c70c..71462dc 100644 --- a/app/service/CrawlerService.php +++ b/app/service/CrawlerService.php @@ -17,15 +17,30 @@ class CrawlerService /** * 获取职位树数据 * @param string $dsdm 地区代码 + * @param string $examid 考试ID + * @param string $bmid 部门ID + * @param string $userid 用户ID + * @param string $aa 时间戳(必须与selectPosition页一致) * @param array $cookies Cookie数据 * @return array */ - public function getPositionTree(string $dsdm, array $cookies): array + public function getPositionTree(string $dsdm, string $examid, string $bmid, string $userid, string $aa, array $cookies): array { $url = $this->baseUrl . '/tree/getPositionTree.htm'; $cookieString = $this->buildCookieString($cookies); + // 构建Referer URL(包含完整参数) + $refererUrl = "http://gzrsks.oumakspt.com:62/tyzpwb/stuchooseexam/selectPosition.htm?examstupid=1015&userid={$userid}&bmid={$bmid}&examid={$examid}&aa={$aa}"; + + // 构建POST参数 + $postData = [ + 'examid' => $examid, + 'bmid' => $bmid, + 'userid' => $userid, + 'dsdm' => $dsdm + ]; + $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -37,17 +52,18 @@ class CrawlerService 'Accept: text/plain, */*', 'Accept-Language: zh-CN,zh;q=0.9,zh-TW;q=0.8,zh-HK;q=0.7,en-US;q=0.6,en;q=0.5', 'Accept-Encoding: gzip, deflate', + 'Pragma: no-cache', 'Cache-Control: no-cache', 'Connection: keep-alive', - 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8', + 'Content-Type: application/x-www-form-urlencoded', 'Cookie: ' . $cookieString, 'Origin: http://gzrsks.oumakspt.com:62', - 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36', - 'Referer: http://gzrsks.oumakspt.com:62/tyzpwb/stuchooseexam/selectPosition.htm', + 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:147.0) Gecko/20100101 Firefox/147.0', + 'Referer: ' . $refererUrl, 'X-Requested-With: XMLHttpRequest', ]); curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['dsdm' => $dsdm])); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); diff --git a/view/crawler/index.html b/view/crawler/index.html index 2529f96..8071a7b 100644 --- a/view/crawler/index.html +++ b/view/crawler/index.html @@ -342,12 +342,16 @@