update
This commit is contained in:
@@ -175,6 +175,10 @@ class Crawler extends BaseController
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$dsdm = $this->request->param('dsdm', '');
|
$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', '');
|
$cookiesParam = $this->request->param('cookies', '');
|
||||||
|
|
||||||
if (empty($dsdm)) {
|
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)) {
|
if (empty($cookiesParam)) {
|
||||||
return json([
|
return json([
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
@@ -201,7 +219,7 @@ class Crawler extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$service = new CrawlerService();
|
$service = new CrawlerService();
|
||||||
$treeData = $service->getPositionTree($dsdm, $cookies);
|
$treeData = $service->getPositionTree($dsdm, $examid, $bmid, $userid, (string)$aa, $cookies);
|
||||||
|
|
||||||
// 提取所有CODE作为zwdm
|
// 提取所有CODE作为zwdm
|
||||||
$zwdmList = [];
|
$zwdmList = [];
|
||||||
|
|||||||
@@ -17,15 +17,30 @@ class CrawlerService
|
|||||||
/**
|
/**
|
||||||
* 获取职位树数据
|
* 获取职位树数据
|
||||||
* @param string $dsdm 地区代码
|
* @param string $dsdm 地区代码
|
||||||
|
* @param string $examid 考试ID
|
||||||
|
* @param string $bmid 部门ID
|
||||||
|
* @param string $userid 用户ID
|
||||||
|
* @param string $aa 时间戳(必须与selectPosition页一致)
|
||||||
* @param array $cookies Cookie数据
|
* @param array $cookies Cookie数据
|
||||||
* @return array
|
* @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';
|
$url = $this->baseUrl . '/tree/getPositionTree.htm';
|
||||||
|
|
||||||
$cookieString = $this->buildCookieString($cookies);
|
$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();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
@@ -37,17 +52,18 @@ class CrawlerService
|
|||||||
'Accept: text/plain, */*',
|
'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-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',
|
'Accept-Encoding: gzip, deflate',
|
||||||
|
'Pragma: no-cache',
|
||||||
'Cache-Control: no-cache',
|
'Cache-Control: no-cache',
|
||||||
'Connection: keep-alive',
|
'Connection: keep-alive',
|
||||||
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
|
'Content-Type: application/x-www-form-urlencoded',
|
||||||
'Cookie: ' . $cookieString,
|
'Cookie: ' . $cookieString,
|
||||||
'Origin: http://gzrsks.oumakspt.com:62',
|
'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',
|
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:147.0) Gecko/20100101 Firefox/147.0',
|
||||||
'Referer: http://gzrsks.oumakspt.com:62/tyzpwb/stuchooseexam/selectPosition.htm',
|
'Referer: ' . $refererUrl,
|
||||||
'X-Requested-With: XMLHttpRequest',
|
'X-Requested-With: XMLHttpRequest',
|
||||||
]);
|
]);
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
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_TIMEOUT, 30);
|
||||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||||
|
|
||||||
|
|||||||
@@ -342,12 +342,16 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
// 复用同一个aa,确保selectPosition与getPositionTree的Referer一致
|
||||||
|
let lastAa = '';
|
||||||
|
|
||||||
// 获取地区选项
|
// 获取地区选项
|
||||||
function getDsdmOptions() {
|
function getDsdmOptions() {
|
||||||
const examid = document.getElementById('examid').value.trim();
|
const examid = document.getElementById('examid').value.trim();
|
||||||
const bmid = document.getElementById('bmid').value.trim();
|
const bmid = document.getElementById('bmid').value.trim();
|
||||||
const userid = document.getElementById('userid').value.trim();
|
const userid = document.getElementById('userid').value.trim();
|
||||||
const aa = Date.now().toString();
|
const aa = Date.now().toString();
|
||||||
|
lastAa = aa;
|
||||||
const cookieData = buildCookiesPayload('dsdm-message');
|
const cookieData = buildCookiesPayload('dsdm-message');
|
||||||
|
|
||||||
if (!examid || !bmid || !userid) {
|
if (!examid || !bmid || !userid) {
|
||||||
@@ -394,13 +398,22 @@
|
|||||||
// 获取职位代码列表
|
// 获取职位代码列表
|
||||||
function getZwdmList() {
|
function getZwdmList() {
|
||||||
const dsdm = document.getElementById('dsdm').value;
|
const dsdm = document.getElementById('dsdm').value;
|
||||||
|
const examid = document.getElementById('examid').value.trim();
|
||||||
|
const bmid = document.getElementById('bmid').value.trim();
|
||||||
|
const userid = document.getElementById('userid').value.trim();
|
||||||
const cookieData = buildCookiesPayload('zwdm-message');
|
const cookieData = buildCookiesPayload('zwdm-message');
|
||||||
|
const aa = lastAa || Date.now().toString();
|
||||||
|
|
||||||
if (!dsdm) {
|
if (!dsdm) {
|
||||||
showMessage('zwdm-message', '请先选择地区', 'error');
|
showMessage('zwdm-message', '请先选择地区', 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!examid || !bmid || !userid) {
|
||||||
|
showMessage('zwdm-message', '请先填写examid、bmid和userid', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!cookieData) {
|
if (!cookieData) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -412,7 +425,7 @@
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
},
|
},
|
||||||
body: `dsdm=${encodeURIComponent(dsdm)}&cookies=${encodeURIComponent(JSON.stringify(cookieData))}`
|
body: `dsdm=${encodeURIComponent(dsdm)}&examid=${encodeURIComponent(examid)}&bmid=${encodeURIComponent(bmid)}&userid=${encodeURIComponent(userid)}&aa=${encodeURIComponent(aa)}&cookies=${encodeURIComponent(JSON.stringify(cookieData))}`
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
|||||||
Reference in New Issue
Block a user