当前位置: 首页> 娱乐> 明星 > 共有5部手机,如果通过服务器让1号手机执行打开 “闲鱼.js“ 脚本

共有5部手机,如果通过服务器让1号手机执行打开 “闲鱼.js“ 脚本

时间:2025/7/19 1:56:15来源:https://blog.csdn.net/qq_29820687/article/details/140086113 浏览次数:0次
1.手机端Auto.js脚本:

每部手机需要在连接时发送一个唯一的标识符(如设备ID),并接收服务器发送的指令以执行指定的脚本。

// Auto.js脚本连接WebSocket服务器并发送设备ID
var WebSocket = require('ws');
var ws = new WebSocket('ws://your_computer_ip:8080');
var deviceID = "phone1"; // 设备唯一标识符// 当与服务器建立连接时,发送设备ID
ws.on('open', function() {console.log('Connected to server');ws.send(JSON.stringify({ type: 'register', id: deviceID }));
});// 处理从服务器接收的消息
ws.on('message', function(data) {var message = JSON.parse(data);if (message.type == 'command') {executeCommand(message.command);}
});// 根据指令执行操作
function executeCommand(command) {if (command.action == 'run_script') {var scriptName = command.scriptName;if (files.exists(scriptName)) {engines.execScriptFile(scriptName);} else {console.log('Script not found: ' + scriptName);}}// 添加更多操作
}// 当与服务器断开连接时,记录日志
ws.on('close', function() {console.log('Disconnected from server');
});
2.电脑端Node.js WebSocket服务器:

在服务器中,维护一个客户端连接列表,并根据设备ID发送指令。

// Node.js WebSocket服务器
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });let clients = {};// 当有新的客户端连接时
wss.on('connection', function(ws) {ws.on('message', function(message) {let msg = JSON.parse(message);if (msg.type == 'register') {// 记录客户端的设备ID和连接对象clients[msg.id] = ws;console.log(`Device ${msg.id} connected`);}});// 当客户端断开连接时ws.on('close', function() {for (let id in clients) {if (clients[id] === ws) {delete clients[id];console.log(`Device ${id} disconnected`);break;}}});
});// 发送指令到特定设备
function sendCommand(deviceID, command) {if (clients[deviceID] && clients[deviceID].readyState === WebSocket.OPEN) {clients[deviceID].send(JSON.stringify({ type: 'command', command: command }));} else {console.log(`Device ${deviceID} is not connected`);}
}// 示例:向手机1发送执行脚本的指令
sendCommand('phone1', { action: 'run_script', scriptName: '闲鱼.js' });
3.运行服务器和测试:

确保每部手机上的Auto.js脚本正常运行并能连接到服务器。在电脑上运行Node.js服务器。使用sendCommand函数向特定设备发送指令,测试是否手机1能接收到并执行闲鱼.js脚本。

通过这种方式,你可以实现对特定设备的精确控制,并根据需求扩展其他命令和功能。
关键字:共有5部手机,如果通过服务器让1号手机执行打开 “闲鱼.js“ 脚本

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: