liuq 4 mesiacov pred
rodič
commit
9ce4fb6c56
3 zmenil súbory, kde vykonal 143 pridanie a 0 odobranie
  1. 23 0
      auto-login-config.json
  2. 110 0
      server.js
  3. 10 0
      src/data/navigation.json

+ 23 - 0
auto-login-config.json

@@ -36,6 +36,29 @@
       "envUsername": "HOME_ASSISTANT_USERNAME",
       "envPassword": "HOME_ASSISTANT_PASSWORD"
     }
+  },
+  "oa-system": {
+    "name": "OA系统",
+    "targetHost": "api.hnyunzhu.com:2443",
+    "targetDomain": "api.hnyunzhu.com",
+    "targetBaseUrl": "https://api.hnyunzhu.com:2443",
+    "loginMethod": "get-query-login",
+    "loginUrl": "/ynet/LoginSA.do",
+    "successRedirectUrl": "/ynet/toMTMain.do?loginLevel=1",
+    "loginMethodConfig": {
+      "usernameParam": "user",
+      "passwordParam": "pass",
+      "entCode": "yz",
+      "saveCookie": "save",
+      "isOnly": "0",
+      "successResponse": "ok"
+    },
+    "credentials": {
+      "username": "huangr",
+      "password": "888888",
+      "envUsername": "OA_SYSTEM_USERNAME",
+      "envPassword": "OA_SYSTEM_PASSWORD"
+    }
   }
 }
 

+ 110 - 0
server.js

@@ -651,6 +651,97 @@ async function handleHomeAssistantLogin(config, credentials) {
   }
 }
 
+// 处理 GET 查询参数登录(OA系统等)
+async function handleGetQueryLogin(config, credentials) {
+  const { targetBaseUrl, loginUrl, loginMethodConfig, successRedirectUrl } = config;
+  const { usernameParam, passwordParam, entCode, saveCookie, isOnly, successResponse } = loginMethodConfig;
+  
+  console.log('=== GET 查询参数登录 ===');
+  console.log(`目标URL: ${targetBaseUrl}${loginUrl}`);
+  console.log(`用户名: ${credentials.username}`);
+  console.log(`密码: ${'*'.repeat(credentials.password.length)}`);
+  console.log(`企业代码: ${entCode}`);
+  
+  // 构建查询参数
+  const params = new URLSearchParams({
+    [usernameParam]: credentials.username,
+    [passwordParam]: credentials.password,
+    ent_code: entCode,
+    code: 'undefined',
+    mySel: 'undefined',
+    saveCookie: saveCookie,
+    isOnly: isOnly,
+    _: Date.now().toString() // 时间戳,防止缓存
+  });
+  
+  const loginUrlWithParams = `${targetBaseUrl}${loginUrl}?${params.toString()}`;
+  
+  console.log(`发送登录请求到: ${loginUrlWithParams}`);
+  
+  try {
+    const loginResponse = await axios.get(loginUrlWithParams, {
+      headers: {
+        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
+        'Accept': '*/*',
+        'Referer': `${targetBaseUrl}/`
+      },
+      withCredentials: true,
+      maxRedirects: 0,
+      validateStatus: function (status) {
+        return status >= 200 && status < 400;
+      }
+    });
+    
+    console.log(`登录响应状态码: ${loginResponse.status}`);
+    console.log(`响应数据: ${loginResponse.data}`);
+    
+    // 检查登录是否成功(响应内容为 "ok")
+    const responseText = loginResponse.data?.toString().trim() || '';
+    const isSuccess = responseText.toLowerCase() === successResponse.toLowerCase();
+    
+    console.log(`响应内容: "${responseText}"`);
+    console.log(`成功标识: ${successResponse}, 匹配结果: ${isSuccess}`);
+    
+    if (isSuccess) {
+      const cookies = loginResponse.headers['set-cookie'] || [];
+      console.log(`登录成功!获取到 ${cookies.length} 个 Cookie`);
+      cookies.forEach((cookie, index) => {
+        console.log(`Cookie ${index + 1}: ${cookie.substring(0, 100)}...`);
+      });
+      
+      return {
+        success: true,
+        cookies: cookies,
+        redirectUrl: successRedirectUrl ? `${targetBaseUrl}${successRedirectUrl}` : null,
+        response: loginResponse.data
+      };
+    } else {
+      console.error(`登录失败!响应内容: "${responseText}"`);
+      return {
+        success: false,
+        message: `登录失败,响应: ${responseText}`,
+        response: loginResponse.data
+      };
+    }
+  } catch (error) {
+    console.error('登录请求异常:', error.message);
+    if (error.response) {
+      console.error('响应状态:', error.response.status);
+      console.error('响应数据:', error.response.data);
+      return {
+        success: false,
+        message: `登录失败: ${error.response.status} - ${error.response.data}`,
+        response: error.response.data
+      };
+    }
+    return {
+      success: false,
+      message: `登录失败: ${error.message}`,
+      response: null
+    };
+  }
+}
+
 // 处理普通表单登录(未加密)
 async function handlePlainFormLogin(config, credentials) {
   const { targetBaseUrl, loginUrl, loginMethodConfig } = config;
@@ -802,6 +893,9 @@ app.get('/api/auto-login/:siteId', async (req, res) => {
       case 'home-assistant':
         loginResult = await handleHomeAssistantLogin(config, credentials);
         break;
+      case 'get-query-login':
+        loginResult = await handleGetQueryLogin(config, credentials);
+        break;
       default:
         console.error(`[${requestId}] 错误: 不支持的登录方法: ${config.loginMethod}`);
         return res.status(400).json({
@@ -1205,6 +1299,22 @@ app.get('/api/auto-login/:siteId', async (req, res) => {
       return res.send(intermediateHtml);
     }
     
+    // 对于 GET 查询登录,如果有 redirectUrl,直接重定向
+    if (config.loginMethod === 'get-query-login' && loginResult.redirectUrl) {
+      console.log(`[${requestId}] GET 查询登录成功,重定向到: ${loginResult.redirectUrl}`);
+      console.log(`[${requestId}] 总耗时: ${Date.now() - startTime}ms`);
+      console.log('='.repeat(80) + '\n');
+      
+      // 设置 Cookie 后重定向
+      loginResult.cookies.forEach((cookie, index) => {
+        let modifiedCookie = cookie.replace(/Domain=[^;]+/i, `Domain=${config.targetDomain}`);
+        res.setHeader('Set-Cookie', modifiedCookie);
+        console.log(`[${requestId}]   设置 Cookie ${index + 1}: ${modifiedCookie.substring(0, 80)}...`);
+      });
+      
+      return res.redirect(loginResult.redirectUrl);
+    }
+    
     // 解析 Cookie
     const cookieData = parseCookies(loginResult.cookies);
     console.log(`[${requestId}] 解析到 ${cookieData.length} 个 Cookie:`);

+ 10 - 0
src/data/navigation.json

@@ -25,6 +25,16 @@
           "background": "",
           "description": "智能自动化平台"
         },
+        {
+          "name": "OA系统",
+          "url": "api.hnyunzhu.com:2443",
+          "sort": 3,
+          "icon": "",
+          "background": "",
+          "description": "企业OA办公系统",
+          "autoLogin": true,
+          "autoLoginEndpoint": "/api/auto-login/oa-system"
+        },
         {
           "name": "实验室系统",
           "url": "https://lab.example.com",