您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“怎么用酷Q+java實現(xiàn)qq機器人”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
背景:因公司當(dāng)前業(yè)務(wù)需求 很多業(yè)務(wù)到量都是通過運營線下qq通知渠道,業(yè)務(wù)量大時,運營人員需要花大量時間來發(fā)QQ信息通知渠道。所以在網(wǎng)上搜索到了大牛分享的酷q部署實現(xiàn)qq機器人 ,成功解決問題。
請確保coolq環(huán)境搭建完畢 部署coolq環(huán)境教程
點我下載需要的文件
[root@iz2ze6ezkrxf8bsldl6cn3z app]# cd /data/coolq-data/app/ [root@iz2ze6ezkrxf8bsldl6cn3z app]# ll total 1560 -rw-r--r-- 1 admin admin 345637 Aug 11 10:43 com.coxxs.music.cpk -rw-r--r-- 1 admin admin 378541 Aug 11 10:43 com.coxxs.start.cpk -rw-r--r-- 1 admin admin 17797 Aug 11 10:43 com.coxxs.status.cpk -rw-r--r-- 1 admin admin 401717 Aug 11 10:43 com.coxxs.tuling123.cpk -rw-r--r-- 1 root root 440445 Jan 27 2017 org.ruiko.lemoc.cpk [root@iz2ze6ezkrxf8bsldl6cn3z app]#
右鍵懸浮窗,啟動lemoc模塊
設(shè)置 菜單>設(shè)置>自動開啟serverg勾選,本機連接不勾選
刪除之前運行的docker容器,啟動時,新增一個映射端口(lemoc模塊的25303端口)
docker rm $(docker ps -aq) docker run --name=coolq -d -p 8001:9000 -p 25303:25303 -v /data/coolq-data:/home/user/coolq -e VNC_PASSWD=******* -e COOLQ_ACCOUNT=630389368 coolq/wine-coolq
windows下cmd:telnet ip 25303
導(dǎo)入下載的jar
KQClient.java
import org.apache.log4j.Logger; import java.net.URI; public class KQClient { private static Logger logger = Logger.getLogger(KQClient.class); private static RewriteKQWebClient kqWebClient; public static void runClient(String host){ try { if(kqWebClient == null){ //連接coolq服務(wù)器 kqWebClient = new RewriteKQWebClient(new URI(host)); } //消息監(jiān)聽適配器 MyQQAdapter myQQAdapter = new MyQQAdapter(kqWebClient); //監(jiān)聽消息 kqWebClient.addQQMSGListenner(myQQAdapter); }catch (Exception e){ System.err.println("init KQ client fail e:"+e.getMessage()); e.printStackTrace(); } } public static void main(String[] args) { KQClient.runClient("ws://39.106.87.218:25303"); } }
MyQQAdapter.java
import com.mumu.listenner.KQMSGAdapter; import com.mumu.msg.RE_MSG_Forum; import com.mumu.msg.RE_MSG_Group; import com.mumu.msg.RE_MSG_Private; public class MyQQAdapter extends KQMSGAdapter { private RewriteKQWebClient kqWebClient; MyQQAdapter(RewriteKQWebClient kqWebClient) { this.kqWebClient = kqWebClient; } /** * 接收私聊消息 */ public void Re_MSG_Private(RE_MSG_Private msg) { System.out.println("接收到私聊信息 from:"+msg.getFromqq()+">
RewriteKQWebClient.java
import com.alibaba.fastjson.JSONObject; import com.mumu.webclient.KQWebClient; import java.net.URI; public class RewriteKQWebClient extends KQWebClient { public RewriteKQWebClient(URI serverURI) { super(serverURI); } @Override public void sendPrivateMSG(String qq, String msg) { try { Thread.sleep(10L); } catch (InterruptedException var4) { var4.printStackTrace(); } JSONObject sendMsg = new JSONObject(); sendMsg.put("act",106); sendMsg.put("QQID",qq); sendMsg.put("msg",msg); super.send(sendMsg.toJSONString()); } @Override public void sendGroupMSG(String qq, String groupid, String msg, Boolean isAT) { try { Thread.sleep(10L); } catch (InterruptedException var4) { var4.printStackTrace(); } JSONObject sendMsg = new JSONObject(); sendMsg.put("act",101); sendMsg.put("groupid",groupid); sendMsg.put("msg",msg); super.send(sendMsg.toJSONString()); } }
public static void main(String[] args) { KQClient.runClient("ws://ip:25303"); }
https://cqp.cc/t/29722
“怎么用酷Q+java實現(xiàn)qq機器人”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。