904118851 2 hete
szülő
commit
ab2d4e4b54

+ 67 - 4
DZ_DJ_LIB/select_dj_and_inster.js

@@ -43,7 +43,36 @@ async function processTask(){
 
 }
 
+async function processMFTask(){
+    let connection  = null
+    let curPage = 0
+    try{
+        connection = await mysql.createConnection({
+            ...dbConfig,
+            multipleStatements: true
+        });
+        let books =  await CMD.getDjMFList(curPage)
+        if(books!=null){
+            await CMD.insterData(connection,books)
+        }
+        while (books!=null) {
+            curPage ++
+            books =  await CMD.getDjMFList(curPage)
+            if(books!=null){
+                await CMD.insterData(connection,books)
+            }
+        }
+
+    }catch(e){
+        console.error("processTask error:",e)
+    } finally{
+        // global.setTimeout(processTask, 60000);
+        if(connection!=null){
+            await connection.end();
+        }
+    }
 
+}
 CMD.insterData = async function(connection,books) {
     console.log("insterData:",books)
     try{
@@ -104,14 +133,48 @@ CMD.getDjList = async function(page_num){
     } 
 }
 
+CMD.getDjMFList = async function(page_num){
+    try{
+        let timestamp = helper.getCurrentUnixTimestamp()
+        let cookit = await tools.getDzMfCookit()
+        console.log("cookit:",cookit)
+        let client = tools.getOneNewClinet({   
+            "accept": "application/json, text/javascript, */*; q=0.01",
+            "content-type": "application/json",
+            "x-requested-with": "XMLHttpRequest",
+            "cookie": `${cookit}`
+        })
+        let response = await client.get(`https://admin.wqxsw.com/admin/referral/book/index?sort=idx&order=desc&offset=${page_num*limit}&limit=${limit}&filter={}&op={}&_=${timestamp}`)
+        
+        let keys = Object.keys(response.data.rows)
+        console.log("keys:",keys)
+        if(keys.length<=0){
+            throw "没有数据了"
+        }
 
+        let temp = []
+
+        for (let index = 0; index < keys.length; index++) {
+            const key = keys[index];
+            const element = response.data.rows[key];
+            temp.push(element)
+        }
+        return temp
+
+    }catch(e){
+        console.error("processTask error:",e)
+        return null
+    } 
+}
 CMD.init = async function(){
-    redis_help.connect((results)=>{
+    redis_help.connect(async (results)=>{
         if(results){
-            processTask();
-            const hourlyJob = schedule.scheduleJob('0 * * * *', function() {
+            await processTask();
+            await processMFTask();
+            const hourlyJob = schedule.scheduleJob('0 * * * *', async function() {
                 console.log('整点执行的任务:', new Date().toLocaleString());
-                processTask();
+                await processTask();
+                await processMFTask();
             });
         }
     })

+ 1 - 0
MESSAGE_DISPATCH/MESSAGE_DISPATCH.js

@@ -394,6 +394,7 @@ CMD.updateTimeConfig = function(){
     //     redis_help.setKeyValue("qi_mao_token",headers['n-token'])
     // })
     require('../src/api/dz/dz_login').login()
+    require('../src/api/dz/dz_mf_login').login()
 }
 //定时更新配置
 CMD.updateConfig = function(){

+ 179 - 0
src/api/dz/dz_mf_login.js

@@ -0,0 +1,179 @@
+const axios = require('axios');
+const qs = require('querystring');
+const dns = require('dns').promises;
+const net = require('net');
+const tools = require('../../../tools');
+
+
+
+
+class AdminSession {
+    constructor(options = {}) {
+        this.baseURL = 'https://vip.wqxsw.com';
+        this.dnsServers = options.dnsServers || ['8.8.8.8', '8.8.4.4', '223.5.5.5', '223.6.6.6'];
+        this.maxRetries = options.maxRetries || 3;
+        this.currentRetry = 0;
+
+        this.axiosInstance = axios.create({
+            baseURL: this.baseURL,
+            timeout: options.timeout || 15000,
+            headers: {
+                'accept': 'application/json, text/javascript, */*; q=0.01',
+                'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
+                'x-requested-with': 'XMLHttpRequest'
+            }
+        });
+    }
+
+    async checkDNS() {
+        console.log('开始DNS诊断...');
+        
+        for (const server of this.dnsServers) {
+            try {
+                // 临时设置DNS服务器
+                dns.setServers([server]);
+                console.log(`尝试使用DNS服务器 ${server}...`);
+                
+                const result = await dns.resolve4('admin.wqxsw.com');
+                console.log(`使用DNS ${server} 解析成功:`, result);
+                return result[0]; // 返回第一个IP地址
+            } catch (error) {
+                console.log(`DNS ${server} 解析失败:`, error.message);
+            }
+        }
+        throw new Error('所有DNS服务器解析失败');
+    }
+
+    async tryDirectIP() {
+        // 已知的备用IP地址列表
+        const knownIPs = [
+            '47.94.253.153',   // 示例IP,需要替换为实际的IP
+            '47.94.253.154'    // 备用IP
+        ];
+
+        for (const ip of knownIPs) {
+            try {
+                console.log(`尝试直接使用IP: ${ip}`);
+                const response = await axios.get(`http://${ip}`, {
+                    headers: {
+                        'Host': 'admin.wqxsw.com'
+                    },
+                    timeout: 5000
+                });
+                if (response.status === 200) {
+                    console.log(`IP ${ip} 连接成功`);
+                    return ip;
+                }
+            } catch (error) {
+                console.log(`IP ${ip} 连接失败:`, error.message);
+            }
+        }
+        return null;
+    }
+
+    async login(username = 'zymfvip', password = 'Xuan6963') {
+        try {
+            // 先进行DNS检查
+            let targetHost = this.baseURL;
+            try {
+                const ip = await this.checkDNS();
+                console.log('DNS解析成功,使用解析后的IP:', ip);
+                targetHost = `https://${ip}`;
+            } catch (error) {
+                console.log('DNS解析失败,尝试使用直连IP...');
+                const directIP = await this.tryDirectIP();
+                if (directIP) {
+                    targetHost = `https://${directIP}`;
+                }
+            }
+
+            // 更新axios实例的baseURL
+            this.axiosInstance.defaults.baseURL = targetHost;
+
+            // 添加重要的请求头
+            const headers = {
+                'Host': 'vip.wqxsw.com',
+                'Referer': `${this.baseURL}/admin/index/login`,
+                'Cookie': 'PHPSESSID=entifjq4tviu8pdfch9f457egr'
+            };
+
+            // 发送登录请求
+            const response = await this.axiosInstance.post(
+                '/admin/index/login',
+                qs.stringify({
+                    __token__: 'c83d3c52e2f2c816d64b0e5c37a561b0',
+                    username,
+                    password,
+                    keeplogin: 1
+                }),
+                {
+                    headers,
+                    params: {
+                        url: '/admin/notice/index?ref=addtabs'
+                    }
+                }
+            );
+            return [response.data,response.config.headers.Cookie];
+        } catch (error) {
+            if (this.currentRetry < this.maxRetries) {
+                this.currentRetry++;
+                console.log(`登录失败,第 ${this.currentRetry} 次重试...`);
+                await new Promise(resolve => setTimeout(resolve, 2000));
+                return this.login(username, password);
+            }
+
+            const errorInfo = {
+                message: error.message,
+                code: error.code,
+                config: error.config,
+                timestamp: new Date().toISOString()
+            };
+
+            if (error.response) {
+                errorInfo.status = error.response.status;
+                errorInfo.data = error.response.data;
+            }
+
+            console.error('登录失败:', errorInfo);
+            throw error;
+        }
+    }
+}
+
+// 使用示例
+async function main() {
+    const session = new AdminSession({
+        maxRetries: 3,
+        timeout: 15000
+    });
+
+    try {
+        console.log('开始登录...');
+        const result = await session.login();
+        if(result[0].code==1){
+            await tools.setDzMfCookie(result[1])
+        }
+        console.log('登录结果:', result);
+
+    } catch (error) {
+        console.error('登录失败:', error.message);
+        
+        // 提供解决建议
+        console.log('\n可能的解决方案:');
+        console.log('1. 检查网络连接是否正常');
+        console.log('2. 检查本地hosts文件');
+        console.log('3. 尝试清除DNS缓存:');
+        console.log('   Windows: ipconfig /flushdns');
+        console.log('   Linux: sudo systemctl restart systemd-resolved');
+        console.log('   Mac: sudo killall -HUP mDNSResponder');
+        console.log('4. 尝试使用其他DNS服务器');
+        console.log('5. 检查服务器是否可访问');
+    }
+}
+
+// 运行测试
+
+function login(){
+    main().catch(console.error);
+}
+module.exports = {login};

+ 9 - 0
tools.js

@@ -282,6 +282,15 @@ class tools {
         return null
     }
 
+
+    async setDzMfCookie(cookit){
+        return this.redis_help.setKeyValue("DZ_MF_COOKIT",cookit)
+    }
+
+    async getDzMfCookit(){
+        return this.redis_help.getKeyValue("DZ_MF_COOKIT")
+    }
+
     async setDzCookie(cookit){
         return this.redis_help.setKeyValue("DZ_COOKIT",cookit)
     }