This commit is contained in:
杨志
2026-01-21 09:15:50 +08:00
parent a7a6d466d0
commit a562c95b10
2 changed files with 56 additions and 33 deletions

View File

@@ -41,25 +41,33 @@ class Crawler extends BaseController
*/
public function getUserConfig()
{
// 强制返回JSON设置响应头
header('Content-Type: application/json; charset=utf-8');
$username = Session::get('username', '');
if (empty($username)) {
try {
$username = Session::get('username', '');
if (empty($username)) {
return json([
'code' => 0,
'msg' => '未登录',
]);
}
$configService = new UserConfigService();
$config = $configService->getUserConfig($username);
return json([
'code' => 1,
'data' => $config,
'msg' => '获取成功',
]);
} catch (\Exception $e) {
return json([
'code' => 0,
'msg' => '未登录',
'msg' => '获取失败: ' . $e->getMessage(),
]);
}
$configService = new UserConfigService();
$config = $configService->getUserConfig($username);
return json([
'code' => 1,
'data' => $config,
'msg' => '获取成功',
]);
}
/**
@@ -67,30 +75,38 @@ class Crawler extends BaseController
*/
public function saveUserConfig()
{
// 强制返回JSON设置响应头
header('Content-Type: application/json; charset=utf-8');
$username = Session::get('username', '');
if (empty($username)) {
try {
$username = Session::get('username', '');
if (empty($username)) {
return json([
'code' => 0,
'msg' => '未登录',
]);
}
$config = [
'jsessionid1' => $this->request->param('jsessionid1', ''),
'jsessionid2' => $this->request->param('jsessionid2', ''),
'serverid' => $this->request->param('serverid', ''),
'examid' => $this->request->param('examid', ''),
'bmid' => $this->request->param('bmid', ''),
'userid' => $this->request->param('userid', ''),
];
$configService = new UserConfigService();
$result = $configService->saveUserConfig($username, $config);
return json($result);
} catch (\Exception $e) {
return json([
'code' => 0,
'msg' => '未登录',
'msg' => '保存失败: ' . $e->getMessage(),
]);
}
$config = [
'jsessionid1' => $this->request->param('jsessionid1', ''),
'jsessionid2' => $this->request->param('jsessionid2', ''),
'serverid' => $this->request->param('serverid', ''),
'examid' => $this->request->param('examid', ''),
'bmid' => $this->request->param('bmid', ''),
'userid' => $this->request->param('userid', ''),
];
$configService = new UserConfigService();
$result = $configService->saveUserConfig($username, $config);
return json($result);
}
/**