日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java开发QQ机器人

發布時間:2024/8/1 java 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java开发QQ机器人 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

很早之前就想過開發一個qq機器人,不過之前一直在想怎么抓包,模擬,最近我朋友給我說了個github的開源項目,再次開工

推薦關閉QQ的設備鎖,否則模擬QQ登錄可能需要驗證,雖然官方有解決方案,不過開發階段還是太麻煩

項目地址

https://github.com/mamoe/mirai

依賴

https://docs.mirai.mamoe.net/ConfiguringProjects.html
這是我開發使用的版本

<dependency><groupId>net.mamoe</groupId><artifactId>mirai-core-jvm</artifactId><version>2.9.1</version> </dependency>

核心API文檔

https://docs.mirai.mamoe.net/CoreAPI.html

簡單使用(幾乎包含了常用操作)

public static void main(String[] args) {// 配置登錄信息BotConfiguration configuration=new BotConfiguration();configuration.setProtocol(BotConfiguration.MiraiProtocol.ANDROID_PHONE);//configuration可不填都有默認值configuration.setWorkingDir(new File("E:\\IDEA\\MyTest6\\src\\main\\resources"));// configuration.setCacheDir();// 設置 工作與緩存目錄configuration.fileBasedDeviceInfo("qq.json");//設置設備信息 防止重復驗證設備信息// 日志相關 可以自己處理 或關閉日志configuration.noBotLog();// qq操作相關日志configuration.noNetworkLog();// 網絡相關日志Bot bot = BotFactory.INSTANCE.newBot(qq, "password",configuration);bot.login();//登錄JavaMain.afterLogin(bot); } public static void afterLogin(Bot bot) {long yourQQNumber = qq;// subscribe 自定義監聽結束時間 subscribeAlways一直監聽 subscribeOnce只處理一次bot.getEventChannel().subscribeAlways(FriendMessageEvent.class, (event) -> {if (event.getSender().getId() == yourQQNumber) {event.getSubject().sendMessage(new MessageChainBuilder().append(new QuoteReply(event.getMessage())).append("Hi, you just said: '").append(event.getMessage()).append("'").build());}});// 獲取基本信息ContactList<Friend> friends = bot.getFriends();System.out.println(friends);ContactList<Group> groups = bot.getGroups();System.out.println(groups);Friend friend = bot.getFriend(yourQQNumber);// 上傳圖片Image image = ExternalResource.uploadAsImage(new File("E:\\IDEA\\MyTest6\\src\\main\\resources\\bbs.png"), friend);// 構建發送的消息MessageChain chain = new MessageChainBuilder().append(new PlainText("string")).append("string") // 會被構造成 PlainText 再添加, 相當于上一行.append(AtAll.INSTANCE).append(image).build();friend.sendMessage(chain); }

茉莉聊天機器人(可以用于輔助)

https://mly.app/profile/index.html

項目演示

https://www.bilibili.com/video/BV1694y1Z7pz/

項目地址

https://gitee.com/shaokang123/qq-cmd
注意測試需要修改對應的配置文件

總結

因為直接用的開源項目,整體沒什么難度,不過注意,不要為了圖省事讓機器人對所有人都應答,否則很快茉莉云api調用次數就干完了

總結

以上是生活随笔為你收集整理的Java开发QQ机器人的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。