下载地址:https://www.pan38.com/share.php?code=JCnzE 提取码:8888 【仅供学习】
完整的订单监控系统,包含配置管理、订单解析、条件判断、自动抢单等功能模块。系统会持续监控订单列表,当发现符合价格和距离条件的新订单时自动点击抢单按钮。
/**
- AutoJS订单监控脚本
- 功能:实时监控订单列表,自动匹配价格和距离条件并抢单
*/
// ============== 配置区域 ==============
const config = {
// 价格筛选条件(单位:元)
minPrice: 30,
maxPrice: 100,
// 距离筛选条件(单位:公里)
maxDistance: 5,
// 刷新间隔(毫秒)
refreshInterval: 800,
// 订单列表控件特征
orderListSelector: {
className: "android.widget.ListView",
scrollable: true
},
// 单个订单项控件特征
orderItemSelector: {
className: "android.widget.LinearLayout",
depth: 10
},
// 价格控件特征
priceSelector: {
textMatches: /¥\s*\d+/,
depth: 15
},
// 距离控件特征
distanceSelector: {
textMatches: /距您\s*\d+\.?\d*\s*公里/,
depth: 15
},
// 抢单按钮特征
grabButtonSelector: {
text: "立即抢单",
clickable: true
},
// 调试模式
debugMode: true
};
// ============== 工具函数 ==============
function logDebug(message) {
if (config.debugMode) {
console.log("[DEBUG] " + message);
}
}
function parsePrice(text) {
const match = text.match(/¥\s(\d+.?\d)/);
return match ? parseFloat(match[1]) : 0;
}
function parseDistance(text) {
const match = text.match(/距您\s(\d+.?\d)\s*公里/);
return match ? parseFloat(match[1]) : 0;
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// ============== 核心监控类 ==============
class OrderMonitor {
constructor() {
this.lastOrderCount = 0;
this.successCount = 0;
this.failCount = 0;
this.running = false;
}
async start() {
this.running = true;
logDebug("订单监控服务启动");
while (this.running) {
try {
await this.checkNewOrders();
} catch (e) {
console.error("监控出错:" + e);
}
await sleep(config.refreshInterval);
}
}
stop() {
this.running = false;
logDebug("订单监控服务停止");
}
async checkNewOrders() {
const orderList = this.findOrderList();
if (!orderList) {
logDebug("未找到订单列表");
return;
}
const currentOrderCount = orderList.childCount();
if (currentOrderCount === this.lastOrderCount) {
return;
}
logDebug("发现新订单,数量:" + (currentOrderCount - this.lastOrderCount));
this.lastOrderCount = currentOrderCount;
for (let i = 0; i < currentOrderCount; i++) {
const orderItem = orderList.child(i);
await this.processOrderItem(orderItem);
}
}
findOrderList() {
return className(config.orderListSelector.className)
.scrollable(config.orderListSelector.scrollable)
.findOne(1000);
}
async processOrderItem(orderItem) {
try {
const priceText = this.findPriceText(orderItem);
const distanceText = this.findDistanceText(orderItem);
if (!priceText || !distanceText) {
logDebug("订单信息不完整");
return;
}
const price = parsePrice(priceText);
const distance = parseDistance(distanceText);
logDebug(`解析订单:价格=${price}元,距离=${distance}公里`);
if (this.isOrderQualified(price, distance)) {
logDebug("订单符合条件,尝试抢单");
await this.grabOrder(orderItem);
}
} catch (e) {
console.error("处理订单出错:" + e);
}
}
findPriceText(orderItem) {
const priceObj = orderItem.findOne(
textMatches(config.priceSelector.textMatches)
.depth(config.priceSelector.depth)
);
return priceObj ? priceObj.text() : null;
}
findDistanceText(orderItem) {
const distanceObj = orderItem.findOne(
textMatches(config.distanceSelector.textMatches)
.depth(config.priceSelector.depth)
);
return distanceObj ? distanceObj.text() : null;
}
isOrderQualified(price, distance) {
return price >= config.minPrice &&
price <= config.maxPrice &&
distance <= config.maxDistance;
}
async grabOrder(orderItem) {
const grabButton = orderItem.findOne(
text(config.grabButtonSelector.text)
.clickable(config.grabButtonSelector.clickable)
);
if (grabButton) {
const clicked = grabButton.click();
if (clicked) {
this.successCount++;
logDebug("抢单成功!累计成功:" + this.successCount);
// 抢单成功后暂停一会儿
await sleep(2000);
// 处理可能的弹窗
await this.handlePopup();
} else {
this.failCount++;
logDebug("抢单点击失败");
}
} else {
logDebug("未找到抢单按钮");
}
}
async handlePopup() {
// 处理常见的确认弹窗
const confirmButton = textMatches(/(确定|确认|知道了)/)
.clickable(true)
.findOne(500);
if (confirmButton) {
confirmButton.click();
await sleep(500);
}
}
}
// ============== 主程序 ==============
function main() {
// 检查无障碍服务
if (!auto.service) {
toast("请先开启无障碍服务");
return;
}
// 创建监控实例
const monitor = new OrderMonitor();
// 注册退出事件
events.on("exit", () => {
monitor.stop();
});
// 启动监控
monitor.start();
// 显示悬浮窗控制按钮
showFloatWindow();
}
function showFloatWindow() {
const window = floaty.window(
);
window.stopBtn.click(() => {
monitor.stop();
toast("监控已停止");
});
window.exitBtn.click(() => {
monitor.stop();
exit();
});
}
// 启动主程序
main();