修改BUG
This commit is contained in:
@@ -30,6 +30,7 @@ class Crawler extends BaseController
|
||||
$bmid = $this->request->param('bmid', '');
|
||||
$userid = $this->request->param('userid', '');
|
||||
$cookiesParam = $this->request->param('cookies', '');
|
||||
$aa = $this->request->param('aa', (string)round(microtime(true) * 1000));
|
||||
|
||||
if (empty($examid) || empty($bmid) || empty($userid)) {
|
||||
return json([
|
||||
@@ -57,10 +58,10 @@ class Crawler extends BaseController
|
||||
$cookieString = $this->buildCookieString($cookies);
|
||||
|
||||
// 构建URL获取HTML - 使用GET请求
|
||||
$url = "http://gzrsks.oumakspt.com:62/tyzpwb/stuchooseexam/selectPosition.htm?examstupid=1015&userid={$userid}&bmid={$bmid}&examid={$examid}&aa=" . time() . '000';
|
||||
$url = "http://gzrsks.oumakspt.com:62/tyzpwb/stuchooseexam/selectPosition.htm?examstupid=1015&userid={$userid}&bmid={$bmid}&examid={$examid}&aa={$aa}";
|
||||
|
||||
// 构建Referer URL(模拟从createbmpdf.htm页面跳转过来)
|
||||
$refererUrl = "http://gzrsks.oumakspt.com:62/tyzpwb/stubm/createbmpdf.htm?userid={$userid}&bmid={$bmid}&examid={$examid}&jsessionid=&mydepid=&dqssds=";
|
||||
// 构建Referer URL(与浏览器实际访问一致)
|
||||
$refererUrl = "http://gzrsks.oumakspt.com:62/tyzpwb/stuchooseexam/input.htm";
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
@@ -72,12 +73,13 @@ class Crawler extends BaseController
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, ''); // 自动处理gzip编码
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||
'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: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||
'Accept-Language: zh-CN,zh;q=0.9',
|
||||
'Accept-Encoding: gzip, deflate',
|
||||
'Cache-Control: no-cache',
|
||||
'Connection: keep-alive',
|
||||
'Cookie: ' . $cookieString,
|
||||
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:147.0) Gecko/20100101 Firefox/147.0',
|
||||
'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: ' . $refererUrl,
|
||||
'Upgrade-Insecure-Requests: 1',
|
||||
]);
|
||||
@@ -123,17 +125,47 @@ class Crawler extends BaseController
|
||||
* @param array $cookies Cookie数组
|
||||
* @return string
|
||||
*/
|
||||
private function buildCookieString(array $cookies): string
|
||||
private function buildCookieString(array|string $cookies): string
|
||||
{
|
||||
$cookieArray = [];
|
||||
|
||||
$cookieData = $cookies['请求 Cookie'] ?? $cookies;
|
||||
|
||||
foreach ($cookieData as $key => $value) {
|
||||
$cookieArray[] = $key . '=' . $value;
|
||||
// 如果直接传入原始Cookie字符串,优先使用(支持多重同名键)
|
||||
if (is_string($cookies)) {
|
||||
return trim($cookies);
|
||||
}
|
||||
|
||||
return implode('; ', $cookieArray);
|
||||
// 只保留用户填写的Cookie,去重并优先保留后者(防止重复JSESSIONID)
|
||||
$cookieData = $cookies['请求 Cookie'] ?? $cookies;
|
||||
$normalized = []; // 同名键保留多值
|
||||
|
||||
foreach ($cookieData as $key => $value) {
|
||||
$k = trim((string)$key);
|
||||
if ($k === '') {
|
||||
continue;
|
||||
}
|
||||
$vals = is_array($value) ? $value : [$value];
|
||||
foreach ($vals as $v) {
|
||||
$v = trim((string)$v);
|
||||
if ($v === '') {
|
||||
continue;
|
||||
}
|
||||
$normalized[$k][] = $v; // 多值按输入顺序保留
|
||||
}
|
||||
}
|
||||
|
||||
// 将 JSESSIONID 放在最前(如果存在),其余按键名顺序
|
||||
$parts = [];
|
||||
if (isset($normalized['JSESSIONID'])) {
|
||||
foreach ($normalized['JSESSIONID'] as $v) {
|
||||
$parts[] = 'JSESSIONID=' . $v;
|
||||
}
|
||||
unset($normalized['JSESSIONID']);
|
||||
}
|
||||
foreach ($normalized as $k => $vArr) {
|
||||
foreach ($vArr as $v) {
|
||||
$parts[] = $k . '=' . $v;
|
||||
}
|
||||
}
|
||||
|
||||
return implode('; ', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -192,22 +192,47 @@ class CrawlerService
|
||||
* @param array $cookies Cookie数组
|
||||
* @return string
|
||||
*/
|
||||
private function buildCookieString(array $cookies): string
|
||||
private function buildCookieString(array|string $cookies): string
|
||||
{
|
||||
$cookieArray = [];
|
||||
|
||||
// 处理嵌套的Cookie结构
|
||||
if (isset($cookies['请求 Cookie'])) {
|
||||
$cookieData = $cookies['请求 Cookie'];
|
||||
} else {
|
||||
$cookieData = $cookies;
|
||||
// 如果直接传入原始Cookie字符串,优先使用(支持多重同名键)
|
||||
if (is_string($cookies)) {
|
||||
return trim($cookies);
|
||||
}
|
||||
|
||||
|
||||
// 只保留用户填写的Cookie,支持同名键多值
|
||||
$cookieData = $cookies['请求 Cookie'] ?? $cookies;
|
||||
$normalized = [];
|
||||
|
||||
foreach ($cookieData as $key => $value) {
|
||||
$cookieArray[] = $key . '=' . $value;
|
||||
$k = trim((string)$key);
|
||||
if ($k === '') {
|
||||
continue;
|
||||
}
|
||||
$vals = is_array($value) ? $value : [$value];
|
||||
foreach ($vals as $v) {
|
||||
$v = trim((string)$v);
|
||||
if ($v === '') {
|
||||
continue;
|
||||
}
|
||||
$normalized[$k][] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return implode('; ', $cookieArray);
|
||||
|
||||
// 将 JSESSIONID 放在最前(如果存在),其余按键名顺序
|
||||
$parts = [];
|
||||
if (isset($normalized['JSESSIONID'])) {
|
||||
foreach ($normalized['JSESSIONID'] as $v) {
|
||||
$parts[] = 'JSESSIONID=' . $v;
|
||||
}
|
||||
unset($normalized['JSESSIONID']);
|
||||
}
|
||||
foreach ($normalized as $k => $vArr) {
|
||||
foreach ($vArr as $v) {
|
||||
$parts[] = $k . '=' . $v;
|
||||
}
|
||||
}
|
||||
|
||||
return implode('; ', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -254,6 +254,12 @@
|
||||
<input type="text" id="cookie-serverid" placeholder="示例:546762930bd4e5dda968e40edd43fb6a|1768878822|1768878621">
|
||||
<small>从浏览器开发者工具中复制SERVERID的值</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="cookie-raw">整行 Cookie(可选,直接粘贴浏览器抓到的整行 Cookie,会优先使用):</label>
|
||||
<textarea id="cookie-raw" placeholder="JSESSIONID=...; JSESSIONID=...; SERVERID=..."></textarea>
|
||||
<small>如果填写本项,将优先使用整行 Cookie(支持多个JSESSIONID)</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="examid">examid:</label>
|
||||
@@ -341,6 +347,7 @@
|
||||
const examid = document.getElementById('examid').value.trim();
|
||||
const bmid = document.getElementById('bmid').value.trim();
|
||||
const userid = document.getElementById('userid').value.trim();
|
||||
const aa = Date.now().toString();
|
||||
const cookieData = buildCookiesPayload('dsdm-message');
|
||||
|
||||
if (!examid || !bmid || !userid) {
|
||||
@@ -359,7 +366,7 @@
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `examid=${encodeURIComponent(examid)}&bmid=${encodeURIComponent(bmid)}&userid=${encodeURIComponent(userid)}&cookies=${encodeURIComponent(JSON.stringify(cookieData))}`
|
||||
body: `examid=${encodeURIComponent(examid)}&bmid=${encodeURIComponent(bmid)}&userid=${encodeURIComponent(userid)}&aa=${aa}&cookies=${encodeURIComponent(JSON.stringify(cookieData))}`
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
@@ -443,6 +450,11 @@
|
||||
|
||||
// 组装Cookie数据
|
||||
function buildCookiesPayload(messageContainerId) {
|
||||
const rawLine = document.getElementById('cookie-raw').value.trim();
|
||||
if (rawLine) {
|
||||
return rawLine;
|
||||
}
|
||||
|
||||
const jsessionid = document.getElementById('cookie-jsessionid').value.trim();
|
||||
const serverid = document.getElementById('cookie-serverid').value.trim();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user