创建时间:2024-01-26
autoxjs 发送微信消息
var dayjs = require("dayjs.js");
device.wakeUp();
// 设置屏幕分辨率
setScreenMetrics(1080, 1920);
// var filePath = "/sdcard/Pictures/" + dayjs().valueOf() + ".mp4";
var getWxMsgInfo = http.get("http://www.88an.top/api/other/getWxMsgInfo");
var getWxMsgInfo = getWxMsgInfo.body.json();
var toDay = dayjs().format("YYYYMMDD");
var storage = storages.create("wxMsg");
// storage.clear(); //开发调试用,开始则 用来清除本地缓存
let storageDay = storage.get("date");
// 判断本地储存中是否有数据,如果有则表示今天已经发送过,后面不提示了
// if (storageDay && storageDay === toDay) {
// engines.stopAll(); //停止线程执行
// } else {
alert("开始执行");
sleep(1000);
home(); // 返回主页
text("微信").waitFor();
click(862, 135, 1030, 303);
sleep(1000);
//把发送消息的方法 放在子线程里面运行,方便用来终止脚本
var thread = threads.start(function () {
sendfn();
});
// }
events.observeKey();
//监听音量上键按下
events.onKeyDown("volume_down", function (event) {
thread.interrupt(); //停止线程执行
engines.stopAll(); //结束所有脚本
});
//发送信息的方法封装
function sendfn() {
var list = [
// {
// name: "文件传输助手",
// type: 0,
// },
// {
// name: "会写代码的咸鱼",
// type: 1,
// },
// {
// name: "小学群",
// type: 0,
// },
{
name: "亲情群",
type: 0,
},
{
name: "傻媳妇小灵通",
type: 1,
},
// {
// name: "亲情聊天群",
// type: 0,
// },
// {
// name: "华萼楼济廷公后裔群",
// type: 0,
// },
];
var line = "————————";
list.forEach((v) => {
//获取天气
var tqInfo = null;
var res = http.get(
`https://restapi.amap.com/v3/weather/weatherInfo?city=${
v.type === 1 ? 440309 : 441424
}&key=aee888a7e746f97ad635d554b6a32b28&extensions=all`
);
if (res.statusCode != 200) {
console.log("请求失败: " + res.statusCode + " " + res.statusMessage);
} else {
var weather = res.body.json();
tqInfo = weather.forecasts[0].casts[0];
}
text("微信").waitFor();
click(v.name);
sleep(1000);
var week = ["日", "一", "二", "三", "四", "五", "六"];
var targetDate = [2024, 2, 9];
var yearDay = dayjs(
`${targetDate[0]}-${targetDate[1]}-${targetDate[2]}`
).diff(dayjs(new Date().getTime()), "days");
//输入需要发送消息
//日期信息
var today = getWxMsgInfo.data.today;
var tomorrow = getWxMsgInfo.data.tomorrow;
var dayStr = `今天 ${dayjs().format("YYYY年M月D日")} 星期${
week[dayjs().day()]
}
农历:${today.nongli.yueri} ${today.jieqi.jieqi} 第${
today.jieqi.jieqi_index_cn
}天
宜【${getWxMsgInfo.data.today.yi}】
忌【${getWxMsgInfo.data.today.ji}】
${line}
明天 ${dayjs().add(1, "day").format("M月D日")} ${tomorrow.nongli.yueri}
宜【${getWxMsgInfo.data.tomorrow.yi}】
忌【${getWxMsgInfo.data.tomorrow.ji}】
${line}
[烟花]距离除夕还有${yearDay}天
${line}
`;
var tqStr1 = `深 白天 ${tqInfo.dayweather} ${tqInfo.daytemp}度
圳 晚上 ${tqInfo.nightweather} ${tqInfo.nighttemp}度\n`;
var tqStr2 = `五 白天 ${tqInfo.dayweather} ${tqInfo.daytemp}度
华 晚上 ${tqInfo.nightweather} ${tqInfo.nighttemp}度\n`;
//新闻热搜信息
// var hotInfo = getWxMsgInfo.data.hotInfo;
// var newStr = `${line}
// 今天新闻热搜:
// 1.${hotInfo[0]}
// 2.${hotInfo[1]}
// 3.${hotInfo[2]}`;
if (v.type === 1) {
var xsDay = dayjs().diff(dayjs(`2018-12-02`), "days");
var money = Math.floor(getWxMsgInfo.data.money);
setText(
dayStr +
tqStr1 +
`${line}
今天是我们相识的第${xsDay}天
${line}
${dayjs().format("YYYY年M月")}份已开支${money}元`
);
} else {
setText(dayStr + tqStr2 + line + "\n安之机器人自动发送,仅供参考");
}
sleep(1000);
//选中发送按钮空间,进行点击发送
text("发送").findOne().click();
sleep(1000);
back();
sleep(1000);
});
storage.put("date", toDay);
home(); // 返回主页
}
// var removeRes = files.remove(filePath);
// toast(removeRes ? "删除成功" : "删除失败");上一篇:nodejs批量处理本地文件
下一篇:jsonp跨域请求