回答
以下是打开微信的 Hamibot 脚本:
// 文档地址 https://docs.hamibot.com/
auto();
auto.waitFor();
// 方式1:通过应用名称
if (launchApp("微信")) {
toastLog("微信已打开");
} else {
// 方式2:通过包名
if (launch("com.tencent.mm")) {
toastLog("微信已打开(包名方式)");
} else {
toastLog("打开微信失败");
}
}
sleep(3000);
进阶:打开微信并进入指定聊天
// 文档地址 https://docs.hamibot.com/
auto();
auto.waitFor();
var contactName = "文件传输助手"; // 要打开的联系人
// 打开微信
launchApp("微信");
sleep(3000);
// 查找并点击联系人
var contact = text(contactName).findOne(5000);
if (contact) {
contact.click();
toastLog("已进入聊天: " + contactName);
} else {
// 尝试搜索
click(device.width - 100, 100); // 点击搜索按钮(大概位置)
sleep(1000);
setText(contactName);
sleep(1000);
text(contactName).findOne().click();
}
sleep(2000);
有具体需求可以告诉我。
ℹ️ 内容由 AI 生成,可能不准确,请注意核实
以下是打开微信并进入"火影情报社"小程序的脚本:
// 文档地址 https://docs.hamibot.com/
auto();
auto.waitFor();
function main() {
// 打开微信
toastLog("正在打开微信...");
if (!launchApp("微信")) {
toastLog("打开微信失败");
exit();
}
sleep(4000);
// 下拉打开小程序列表
toastLog("下拉打开小程序...");
var startX = device.width / 2;
var startY = device.height * 0.3;
var endY = device.height * 0.6;
swipe(startX, startY, startX, endY, 500);
sleep(2000);
// 查找"火影情报社"小程序
toastLog("查找小程序...");
var target = text("火影情报社").findOne(3000) ||
desc("火影情报社").findOne(3000) ||
textContains("火影").findOne(3000);
if (target) {
target.click();
toastLog("已打开火影情报社");
} else {
// 如果没找到,尝试搜索
toastLog("未找到,尝试搜索...");
var searchBtn = text("搜索小程序").findOne(2000) ||
desc("搜索").findOne(2000);
if (searchBtn) {
searchBtn.click();
sleep(1000);
setText("火影情报社");
sleep(1000);
text("火影情报社").findOne().click();
} else {
toastLog("未找到小程序入口");
}
}
sleep(3000);
toastLog("脚本执行完成");
}
main();
备选方案:通过最近使用
// 文档地址 https://docs.hamibot.com/
auto();
auto.waitFor();
// 打开微信
launchApp("微信");
sleep(4000);
// 点击"发现" tab
var discover = text("发现").findOne(3000);
if (discover) {
discover.click();
sleep(1000);
// 点击"小程序"
var miniProgram = text("小程序").findOne(2000);
if (miniProgram) {
miniProgram.click();
sleep(2000);
// 查找或搜索"火影情报社"
var target = text("火影情报社").findOne(3000);
if (target) {
target.click();
} else {
// 点击搜索
click(device.width / 2, 200);
sleep(1000);
setText("火影情报社");
sleep(1000);
text("火影情报社").findOne().click();
}
}
}
sleep(3000);
如果界面布局特殊,可以先用布局分析工具查看具体元素信息。
ℹ️ 内容由 AI 生成,可能不准确,请注意核实