aardio 文档
aardio 范例: 微信扫码登录
自定义登录界面
//微信扫码登录
import web.rest.iLinkClient.login;
/*
在工作线程里可以用 web.rest.iLinkClient.login 登录比较方便。
自定义登录界面: https://www.aardio.com/zh-cn/docs/examples/Web/REST/iLink/weixin-bot.html
*/
var bot = web.rest.iLinkClient.login()
if(!bot) return;
import console;
console.log("✅ 机器人已上线,正在监听微信消息 ...");
// 消息监听循环
while(true){
var updateRes, err, errCode = bot.getUpdates();
if(updateRes && updateRes.msgs){
for i, fromMsg in updateRes.msgs {
var textContent = fromMsg[["item_list"]][[1]][["text_item"]][["text"]];
if(textContent){
console.log("📩 [" + fromMsg.from_user_id + "]: " + textContent);
//回复内容支持 Markdown 语法,同一个 fromMsg 可以多次回复
var ret, sendErr, sendCode = bot.sendMessage(fromMsg, "🤖 已收到: " + textContent);
if(ret){
console.log("✅ 回复成功 → " + textContent);
}
else {
console.log("❌ 回复失败: " + (sendErr || "") + " (错误码: " + sendCode + ")");
}
}
}
}
elseif(!updateRes){
// errCode < 0 是腾讯业务错误,> 0 是 HTTP 客户端错误
if(errCode && errCode < 0){
console.log("⚠️ 业务错误: " + (err || "") + " (" + errCode + "),3秒后重试...");
if(errCode == -14){
//重新登录
var bot = web.rest.iLinkClient.login()
if(!bot) return;
}
}
elseif(errCode){
console.log("⚠️ 网络错误: " + (err || "") + " (" + errCode + "),3秒后重试...");
}
//没必要等太久,微信轮询默认会阻塞等待
thread.delay(1000);
}
}
Markdown 格式