文件已上传:https://www.pan38.com/share.php?code=XHUZM 提取码:8888
AutoJS的贴吧私信工具实现方案。这个工具包含多个功能模块,可以实现自动登录、发送私信、消息管理等完整功能。贴吧私信工具,包含登录、发送私信、查看收件箱和发件箱等功能。使用时需要先修改CONFIG中的用户名和密码,然后运行脚本即可。
// 百度贴吧私信工具 v1.0
// 主要功能:自动登录、发送私信、消息管理
// 常量定义
const CONFIG = {
USERNAME: "your_username",
PASSWORD: "your_password",
MAX_RETRY: 3,
DELAY: 2000,
VERSION: "1.0.0"
};
// 主界面UI
function createUI() {
ui.layout(
);
ui.loginBtn.on("click", () => {
threads.start(function() {
login();
});
});
ui.sendBtn.on("click", () => {
dialogs.build({
title: "发送私信",
positive: "发送",
negative: "取消",
inputPrefill: "请输入私信内容"
}).on("input", (content) => {
threads.start(function() {
sendPrivateMessage(content);
});
}).show();
});
ui.inboxBtn.on("click", () => {
threads.start(function() {
checkInbox();
});
});
ui.outboxBtn.on("click", () => {
threads.start(function() {
checkOutbox();
});
});
ui.settingsBtn.on("click", () => {
showSettings();
});
ui.exitBtn.on("click", () => {
exit();
});
}
// 登录功能
function login() {
ui.run(() => {
ui.progress.visibility = "visible";
ui.status.text = "正在登录...";
});
try {
// 打开百度首页
app.startActivity({
action: "VIEW",
data: "https://www.baidu.com"
});
sleep(CONFIG.DELAY);
// 点击登录按钮
let loginBtn = id("com.baidu.searchbox:id/baidu_home_login").findOne(CONFIG.DELAY);
if (loginBtn) {
loginBtn.click();
sleep(CONFIG.DELAY);
}
// 输入用户名密码
let usernameInput = id("com.baidu.searchbox:id/login_username").findOne(CONFIG.DELAY);
let passwordInput = id("com.baidu.searchbox:id/login_password").findOne(CONFIG.DELAY);
let submitBtn = id("com.baidu.searchbox:id/login_submit").findOne(CONFIG.DELAY);
if (usernameInput && passwordInput && submitBtn) {
usernameInput.setText(CONFIG.USERNAME);
passwordInput.setText(CONFIG.PASSWORD);
submitBtn.click();
sleep(CONFIG.DELAY * 2);
}
// 验证登录成功
let avatar = id("com.baidu.searchbox:id/baidu_home_avatar").findOne(CONFIG.DELAY);
if (avatar) {
ui.run(() => {
ui.status.text = "登录成功";
toast("登录成功");
});
} else {
throw new Error("登录失败");
}
} catch (e) {
ui.run(() => {
ui.status.text = "登录失败: " + e.message;
toast("登录失败");
});
} finally {
ui.run(() => {
ui.progress.visibility = "gone";
});
}
}
// 发送私信功能
function sendPrivateMessage(content) {
ui.run(() => {
ui.progress.visibility = "visible";
ui.status.text = "正在发送私信...";
});
try {
// 打开贴吧私信页面
app.startActivity({
action: "VIEW",
data: "https://tieba.baidu.com/i/i/msg"
});
sleep(CONFIG.DELAY * 2);
// 点击写私信按钮
let writeBtn = text("写私信").findOne(CONFIG.DELAY);
if (writeBtn) {
writeBtn.click();
sleep(CONFIG.DELAY);
}
// 输入收件人
let receiverInput = className("EditText").findOne(CONFIG.DELAY);
if (receiverInput) {
receiverInput.setText("目标用户名");
sleep(CONFIG.DELAY);
}
// 输入内容
let contentInput = className("EditText").index(1).findOne(CONFIG.DELAY);
if (contentInput) {
contentInput.setText(content);
sleep(CONFIG.DELAY);
}
// 点击发送按钮
let sendBtn = text("发送").findOne(CONFIG.DELAY);
if (sendBtn) {
sendBtn.click();
sleep(CONFIG.DELAY * 2);
}
// 验证发送成功
let successToast = text("发送成功").findOne(CONFIG.DELAY);
if (successToast) {
ui.run(() => {
ui.status.text = "私信发送成功";
toast("私信发送成功");
});
} else {
throw new Error("发送失败");
}
} catch (e) {
ui.run(() => {
ui.status.text = "发送失败: " + e.message;
toast("发送失败");
});
} finally {
ui.run(() => {
ui.progress.visibility = "gone";
});
}
}
// 收件箱功能
function checkInbox() {
ui.run(() => {
ui.progress.visibility = "visible";
ui.status.text = "正在加载收件箱...";
});
try {
// 打开贴吧私信页面
app.startActivity({
action: "VIEW",
data: "https://tieba.baidu.com/i/i/msg"
});
sleep(CONFIG.DELAY * 2);
// 切换到收件箱
let inboxTab = text("收件箱").findOne(CONFIG.DELAY);
if (inboxTab) {
inboxTab.click();
sleep(CONFIG.DELAY);
}
// 获取消息列表
let messages = className("ListView").findOne(CONFIG.DELAY);
if (messages) {
let count = messages.childCount();
ui.run(() => {
ui.status.text = "共收到 " + count + " 条私信";
toast("加载完成");
});
} else {
ui.run(() => {
ui.status.text = "没有收到私信";
toast("没有私信");
});
}
} catch (e) {
ui.run(() => {
ui.status.text = "加载失败: " + e.message;
toast("加载失败");
});
} finally {
ui.run(() => {
ui.progress.visibility = "gone";
});
}
}
// 发件箱功能
function checkOutbox() {
ui.run(() => {
ui.progress.visibility = "visible";
ui.status.text = "正在加载发件箱...";
});
try {
// 打开贴吧私信页面
app.startActivity({
action: "VIEW",
data: "https://tieba.baidu.com/i/i/msg"
});
sleep(CONFIG.DELAY * 2);
// 切换到发件箱
let outboxTab = text("发件箱").findOne(CONFIG.DELAY);
if (outboxTab) {
outboxTab.click();
sleep(CONFIG.DELAY);
}
// 获取消息列表
let messages = className("ListView").findOne(CONFIG.DELAY);
if (messages) {
let count = messages.childCount();
ui.run(() => {
ui.status.text = "共发送 " + count + " 条私信";
toast("加载完成");
});
} else {
ui.run(() => {
ui.status.text = "没有发送过私信";
toast("没有记录");
});
}
} catch (e) {
ui.run(() => {
ui.status.text = "加载失败: " + e.message;
toast("加载失败");
});
} finally {
ui.run(() => {
ui.progress.visibility = "gone";
});
}
}
// 设置功能
function showSettings() {
dialogs.build({
title: "设置",
items: ["修改账号", "修改密码", "关于"],
positive: "确定",
negative: "取消"
}).on("item_select", (index, item) => {
switch (index) {
case 0:
dialogs.build({
title: "修改账号",
inputPrefill: CONFIG.USERNAME,
positive: "保存",
negative: "取消"
}).on("input", (text) => {
CONFIG.USERNAME = text;
toast("账号已更新");
}).show();
break;
case 1:
dialogs.build({
title: "修改密码",
inputPrefill: CONFIG.PASSWORD,
positive: "保存",
negative: "取消"
}).on("input", (text) => {
CONFIG.PASSWORD = text;
toast("密码已更新");
}).show();
break;
case 2:
dialogs.alert("百度贴吧私信工具\n版本: " + CONFIG.VERSION + "\n作者: AutoJS");
break;
}
}).show();
}
// 主程序入口
function main() {
createUI();
toast("贴吧私信工具已启动");
}
// 启动主程序
main();