使用aj实现 chatgpt自动回复wx群聊消息

大家好,今天我想给大家介绍一下如何使用aj+chatgpt实现实时自动回复wx群聊消息(并非api接口方式,而是纯模拟手动的方式,99%不会异常)。 首先我先给展示一下我封装的三个常用的方法 画一个弹窗打印console输出

js 复制代码
var showUi = function (){
    Device.keepScreenOn() //保持常亮
    ##画一个弹窗
    Console.setBg('#ecf4fa')
    Console.setMode(3)
    Console.show()
    Console.log("此助手为微信小助手,接入chatgpt4.0.仅供娱乐。")

    SetInterval(()=>{
        try{
            getMessage() //定时任务
        }catch(e){
            Console.log(e)
        }
    },12000)
}

var rest = Console.requestFloating()
rest.onResolve((v)=>{
Thread(()=>{
showUi()
}) //开启一个线程并执行
}).onReject((v)=>{
Toast.show('拒绝授权')
})

1.自动点击指定文本的节点

js 复制代码
var click = function (text) {
    var find = false;
    var hd = Node().textReg(text).find()
    if (hd.size() > 0) {
    find = true;
    hd[0].click()
    }
    var hd2 = Node().desc(text).find()
    if (hd2.size() > 0) {
    find = true;
    hd2[0].click()
    }
    var hd3 = Node().className(text).find()
    if (hd3.size() > 0) {
    find = true;
    hd3[0].click()
    }
    if (find) {
    Console.log("找到节点并且点击=" + text)
    } else {
    Console.log("没找到节点=" + text)
    }
    return find
}

2.输入文本
找到text模糊匹配 or 完全匹配 or classname 为text的输入框,如果找到则输入text2文本

js 复制代码
var inputFunction = function (text, text2) {
    var find = false;
    var hd = Node().textReg(text).find()
    if (hd.size() > 0) {
    find = true;
    hd[0].input(text2)
    }
    var hd2 = Node().desc(text).find()
    if (hd2.size() > 0) {
    find = true;
    hd2[0].input(text2)
    }
    var hd3 = Node().className(text).find()
    if (hd3.size() > 0) {
    find = true;
    hd3[0].input(text2)
    }
    if (find) {
    Console.log("找到节点并且输入=" + text2)
    } else {
    Console.log("没找到输入节点=" + text)
    }
    return find
}

3.输入文本

找到节点为text的节点如果找到的话则返回node

js 复制代码
var nodeIsExit = function (text) {
    var find = false;
    var hd = Node().textReg(text).find()
    if (hd.size() > 0) {
    find = true;
    }
    var hd2 = Node().desc(text).find()
    if (hd2.size() > 0) {
    find = true;
    }
    var hd3 = Node().className(text).find()
    if (hd3.size() > 0) {
    find = true;
    }
    if (find) {
    Console.log("找到节点=" + text)
    } else {
    Console.log("没找到节点=" + text)
    }
    return find
}

首先要发送消息就要找到发送消息的每一个模块的 发送者信息和发送人的名称和发送内容

经过规律解析发现 每一个RelativeLayout为一个模块 我们可以规定 机器人只识别 @ + '想要发送的内容' 则逻辑就为

获取到gpt回复后接下来是发送文本消息 大概逻辑就是找到输入框,然后输入文本,然后点击发送,当然也会检测敏感词语

js 复制代码
var sendMessage = function (message,name) {
    if (nodeIsExit('android.widget.EditText')) {
    click('android.widget.EditText')
    Sleep(1000)
    var result = getGptText(message)
    if (result == '11'){
    Node().className('android.widget.EditText').find().input("哎呀抱歉"+name+"。您的问题涉及敏感词语,请换个问题再试试")
    }
    else if (result) {
    Node().className('android.widget.EditText').find().input("@"+name+" "+result)
    }else{
    Node().className('android.widget.EditText').find().input("哎呀抱歉"+name+"。"+machineName+"出错啦!请换个问"+machineName+"一下")
    }
    Sleep(1000)
    if (nodeIsExit('发送')) {
    click('发送')
    }
    }
}

以上就是核心代码,另外需要全部源码和对接gpt接口可以联系小编

aj教程官网:www.ajfz.mobi/

aj交流群: 934451569

相关推荐
脑袋大大的3 小时前
JavaScript 性能优化实战:减少 DOM 操作引发的重排与重绘
开发语言·javascript·性能优化
速易达网络4 小时前
RuoYi、Vue CLI 和 uni-app 结合构建跨端全家桶方案
javascript·vue.js·低代码
耶啵奶膘4 小时前
uniapp+firstUI——上传视频组件fui-upload-video
前端·javascript·uni-app
JoJo_Way4 小时前
LeetCode三数之和-js题解
javascript·算法·leetcode
视频砖家5 小时前
移动端Html5播放器按钮变小的问题解决方法
前端·javascript·viewport功能
GISer_Jing7 小时前
Monorepo+Pnpm+Turborepo
前端·javascript·ecmascript
天涯学馆7 小时前
前端开发也能用 WebAssembly?这些场景超实用!
前端·javascript·面试
我在北京coding9 小时前
TypeError: Cannot read properties of undefined (reading ‘queryComponents‘)
前端·javascript·vue.js
海天胜景9 小时前
vue3 获取选中的el-table行数据
javascript·vue.js·elementui