下载地址:https://www.pan38.com/share.php?code=JCnzE 提取码:8888 【仅供学习】
完整的滴滴订单监控系统,包含订单解析、条件判断、历史记录管理和语音提醒等功能模块。系统会持续扫描订单列表,当发现符合价格、距离、评分等条件的优质订单时,
/**
- 滴滴司机端订单监控脚本
- 功能:实时监控订单信息,符合条件时语音提醒司机
*/
// ============== 全局配置 ==============
const CONFIG = {
// 订单筛选条件
FILTER: {
MIN_PRICE: 30, // 最低价格(元)
MAX_DISTANCE: 10, // 最大接驾距离(公里)
MIN_RATING: 4.5, // 乘客最低评分
PREFER_AREA: ["中关村", "国贸", "望京"] // 优先区域
},
// 控件识别配置
UI: {
ORDER_LIST: "android.widget.ListView",
ORDER_ITEM: "android.widget.RelativeLayout",
PRICE: /预估.*¥(\d+)/,
DISTANCE: /距离.*?(\d+\.?\d*)公里/,
RATING: /评分.*?(\d+\.?\d*)/,
DESTINATION: "目的地.*?(.*?)(?=\\n|$)",
GRAB_BTN: "接单"
},
// 系统配置
SYSTEM: {
SCAN_INTERVAL: 1500, // 扫描间隔(ms)
VOICE_VOLUME: 10, // 语音音量
MAX_HISTORY: 50 // 最大历史记录数
}
};
// ============== 工具模块 ==============
class Utils {
static sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
static parseNumber(text, regex) {
const match = text.match(regex);
return match ? parseFloat(match[1]) : 0;
}
static parseText(text, regex) {
const match = text.match(regex);
return match ? match[1].trim() : "";
}
static speak(text) {
engines.execScript(
`media.playSound('/sdcard/notification.mp3');
media.ttsSpeak('${text}', {volume: ${CONFIG.SYSTEM.VOICE_VOLUME}});`
);
}
}
// ============== 订单历史模块 ==============
class OrderHistory {
constructor() {
this.history = [];
this.maxSize = CONFIG.SYSTEM.MAX_HISTORY;
}
add(order) {
if (this.history.length >= this.maxSize) {
this.history.shift();
}
this.history.push(order);
}
exists(order) {
return this.history.some(item =>
item.price === order.price &&
item.distance === order.distance &&
item.destination === order.destination
);
}
}
// ============== 订单解析模块 ==============
class OrderParser {
static parse(orderItem) {
try {
const text = orderItem.text();
if (!text) return null;
return {
price: Utils.parseNumber(text, CONFIG.UI.PRICE),
distance: Utils.parseNumber(text, CONFIG.UI.DISTANCE),
rating: Utils.parseNumber(text, CONFIG.UI.RATING),
destination: Utils.parseText(text, CONFIG.UI.DESTINATION),
rawText: text,
timestamp: new Date().toLocaleString()
};
} catch (e) {
console.error("订单解析失败: " + e);
return null;
}
}
}
// ============== 条件判断模块 ==============
class ConditionChecker {
static isQualified(order) {
if (!order) return false;
// 基础条件检查
const basicCheck =
order.price >= CONFIG.FILTER.MIN_PRICE &&
order.distance <= CONFIG.FILTER.MAX_DISTANCE &&
order.rating >= CONFIG.FILTER.MIN_RATING;
if (!basicCheck) return false;
// 优先区域检查
const areaCheck = CONFIG.FILTER.PREFER_AREA.some(
area => order.destination.includes(area)
);
return basicCheck || areaCheck;
}
}
// ============== 监控服务模块 ==============
class MonitorService {
constructor() {
this.history = new OrderHistory();
this.isRunning = false;
this.currentOrders = [];
}
async start() {
this.isRunning = true;
console.show();
console.log("滴滴订单监控服务启动 - " + new Date().toLocaleString());
while (this.isRunning) {
await this.scanOrders();
await Utils.sleep(CONFIG.SYSTEM.SCAN_INTERVAL);
}
}
stop() {
this.isRunning = false;
console.log("服务已停止");
}
async scanOrders() {
try {
const orderList = this.findOrderList();
if (!orderList) return;
const newOrders = this.getNewOrders(orderList);
this.processOrders(newOrders);
} catch (e) {
console.error("扫描出错: " + e);
}
}
findOrderList() {
return className(CONFIG.UI.ORDER_LIST).findOne(1000);
}
getNewOrders(orderList) {
const currentItems = orderList.children();
const newOrders = [];
for (let i = 0; i < currentItems.length; i++) {
const order = OrderParser.parse(currentItems[i]);
if (order && !this.history.exists(order)) {
newOrders.push(order);
this.history.add(order);
}
}
return newOrders;
}
processOrders(orders) {
orders.forEach(order => {
console.log("发现新订单: " + JSON.stringify(order));
if (ConditionChecker.isQualified(order)) {
this.alertDriver(order);
}
});
}
alertDriver(order) {
const message = `优质订单!价格${order.price}元,距离${order.distance}公里,目的地${order.destination}`;
console.log("符合条件: " + message);
Utils.speak(message);
}
}
// ============== 主程序 ==============
function main() {
// 检查无障碍服务
if (!auto.service) {
toast("请先开启无障碍服务");
return;
}
// 创建监控服务
const monitor = new MonitorService();
// 创建悬浮控制窗口
const window = floaty.window(
<frame gravity="center">
<vertical>
<text text="滴滴订单监控" textSize="16sp" />
<button id="startBtn" text="开始监控" />
<button id="stopBtn" text="停止监控" />
<button id="exitBtn" text="退出脚本" />
</vertical>
</frame>
);
window.startBtn.click(() => {
threads.start(() => monitor.start());
});
window.stopBtn.click(() => {
monitor.stop();
});
window.exitBtn.click(() => {
monitor.stop();
exit();
});
// 自动开始监控
threads.start(() => monitor.start());
}
// 启动程序
main();