修复BUG
This commit is contained in:
@@ -29,6 +29,7 @@ class Crawler extends BaseController
|
||||
$examid = $this->request->param('examid', '');
|
||||
$bmid = $this->request->param('bmid', '');
|
||||
$userid = $this->request->param('userid', '');
|
||||
$cookiesParam = $this->request->param('cookies', '');
|
||||
|
||||
if (empty($examid) || empty($bmid) || empty($userid)) {
|
||||
return json([
|
||||
@@ -36,6 +37,24 @@ class Crawler extends BaseController
|
||||
'msg' => '请先填写examid、bmid和userid',
|
||||
]);
|
||||
}
|
||||
|
||||
if (empty($cookiesParam)) {
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '请填写Cookie数据',
|
||||
]);
|
||||
}
|
||||
|
||||
// 解析JSON格式的cookies
|
||||
$cookies = is_string($cookiesParam) ? json_decode($cookiesParam, true) : $cookiesParam;
|
||||
if (json_last_error() !== JSON_ERROR_NONE || empty($cookies)) {
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => 'Cookie数据格式错误,请检查JSON格式',
|
||||
]);
|
||||
}
|
||||
|
||||
$cookieString = $this->buildCookieString($cookies);
|
||||
|
||||
// 构建URL获取HTML
|
||||
$url = "http://gzrsks.oumakspt.com:62/tyzpwb/stuchooseexam/selectPosition.htm?examstupid=1015&userid={$userid}&bmid={$bmid}&examid={$examid}&aa=" . time() . '000';
|
||||
@@ -45,6 +64,11 @@ class Crawler extends BaseController
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Cookie: ' . $cookieString,
|
||||
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
|
||||
'Referer: http://gzrsks.oumakspt.com:62/tyzpwb/',
|
||||
]);
|
||||
|
||||
$html = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
@@ -82,6 +106,24 @@ class Crawler extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建Cookie字符串
|
||||
* @param array $cookies Cookie数组
|
||||
* @return string
|
||||
*/
|
||||
private function buildCookieString(array $cookies): string
|
||||
{
|
||||
$cookieArray = [];
|
||||
|
||||
$cookieData = $cookies['请求 Cookie'] ?? $cookies;
|
||||
|
||||
foreach ($cookieData as $key => $value) {
|
||||
$cookieArray[] = $key . '=' . $value;
|
||||
}
|
||||
|
||||
return implode('; ', $cookieArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取职位代码列表
|
||||
*/
|
||||
|
||||
@@ -243,10 +243,22 @@
|
||||
<div class="form-section">
|
||||
<h2>第一步:填写基础信息</h2>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="cookie-jsessionid">JSESSIONID:</label>
|
||||
<input type="text" id="cookie-jsessionid" placeholder="示例:9E592C9CC752F8552F0D746D91958475">
|
||||
<small>推荐直接填写,避免粘贴JSON出错</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="cookie-serverid">SERVERID:</label>
|
||||
<input type="text" id="cookie-serverid" placeholder="示例:546762930bd4e5dda968e40edd43fb6a|1768878822|1768878621">
|
||||
<small>推荐直接填写,避免粘贴JSON出错</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="cookies">Cookie数据(JSON格式):</label>
|
||||
<textarea id="cookies" placeholder='{"请求 Cookie": {"JSESSIONID": "xxx", "SERVERID": "xxx"}}'></textarea>
|
||||
<small>请填写完整的Cookie数据,格式为JSON</small>
|
||||
<small>可选:若上面已填写两个字段,此处可留空;否则请按JSON格式填写完整Cookie</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@@ -335,11 +347,16 @@
|
||||
const examid = document.getElementById('examid').value.trim();
|
||||
const bmid = document.getElementById('bmid').value.trim();
|
||||
const userid = document.getElementById('userid').value.trim();
|
||||
const cookieData = buildCookiesPayload('dsdm-message');
|
||||
|
||||
if (!examid || !bmid || !userid) {
|
||||
showMessage('dsdm-message', '请先填写examid、bmid和userid', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cookieData) {
|
||||
return;
|
||||
}
|
||||
|
||||
showMessage('dsdm-message', '正在获取地区选项...', 'info');
|
||||
|
||||
@@ -348,7 +365,7 @@
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `examid=${encodeURIComponent(examid)}&bmid=${encodeURIComponent(bmid)}&userid=${encodeURIComponent(userid)}`
|
||||
body: `examid=${encodeURIComponent(examid)}&bmid=${encodeURIComponent(bmid)}&userid=${encodeURIComponent(userid)}&cookies=${encodeURIComponent(JSON.stringify(cookieData))}`
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
@@ -376,23 +393,14 @@
|
||||
// 获取职位代码列表
|
||||
function getZwdmList() {
|
||||
const dsdm = document.getElementById('dsdm').value;
|
||||
const cookies = document.getElementById('cookies').value.trim();
|
||||
const cookieData = buildCookiesPayload('zwdm-message');
|
||||
|
||||
if (!dsdm) {
|
||||
showMessage('zwdm-message', '请先选择地区', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cookies) {
|
||||
showMessage('zwdm-message', '请先填写Cookie数据', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
let cookieData;
|
||||
try {
|
||||
cookieData = JSON.parse(cookies);
|
||||
} catch (e) {
|
||||
showMessage('zwdm-message', 'Cookie数据格式错误,请检查JSON格式', 'error');
|
||||
if (!cookieData) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -439,6 +447,44 @@
|
||||
});
|
||||
}
|
||||
|
||||
// 组装Cookie数据(支持单独填写和JSON)
|
||||
function buildCookiesPayload(messageContainerId) {
|
||||
const raw = document.getElementById('cookies').value.trim();
|
||||
const jsessionid = document.getElementById('cookie-jsessionid').value.trim();
|
||||
const serverid = document.getElementById('cookie-serverid').value.trim();
|
||||
|
||||
let cookies = { "请求 Cookie": {} };
|
||||
|
||||
if (raw) {
|
||||
try {
|
||||
const parsed = JSON.parse(raw);
|
||||
cookies = parsed;
|
||||
} catch (e) {
|
||||
showMessage(messageContainerId, 'Cookie数据格式错误,请检查JSON格式', 'error');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 确保存在“请求 Cookie”层级
|
||||
if (!cookies['请求 Cookie'] || typeof cookies['请求 Cookie'] !== 'object') {
|
||||
cookies['请求 Cookie'] = {};
|
||||
}
|
||||
|
||||
if (jsessionid) {
|
||||
cookies['请求 Cookie']['JSESSIONID'] = jsessionid;
|
||||
}
|
||||
if (serverid) {
|
||||
cookies['请求 Cookie']['SERVERID'] = serverid;
|
||||
}
|
||||
|
||||
if (Object.keys(cookies['请求 Cookie']).length === 0) {
|
||||
showMessage(messageContainerId, '请填写Cookie数据', 'error');
|
||||
return null;
|
||||
}
|
||||
|
||||
return cookies;
|
||||
}
|
||||
|
||||
// 全选/取消全选
|
||||
function toggleAllZwdm() {
|
||||
const selectAll = document.getElementById('select-all-zwdm').checked;
|
||||
@@ -451,23 +497,14 @@
|
||||
// 批量获取职位信息
|
||||
function batchGetPositionInfo() {
|
||||
const examid = document.getElementById('examid').value.trim();
|
||||
const cookies = document.getElementById('cookies').value.trim();
|
||||
const cookieData = buildCookiesPayload('result-message');
|
||||
|
||||
if (!examid) {
|
||||
showMessage('result-message', '请先填写examid', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cookies) {
|
||||
showMessage('result-message', '请先填写Cookie数据', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
let cookieData;
|
||||
try {
|
||||
cookieData = JSON.parse(cookies);
|
||||
} catch (e) {
|
||||
showMessage('result-message', 'Cookie数据格式错误,请检查JSON格式', 'error');
|
||||
if (!cookieData) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user