Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize qq Robot with Cool Q+java

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to use cool Q+java to realize qq robot". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Background: due to the current business needs of the company, many of the business volume is through the offline qq notification channel, when the business volume is large, operators need to spend a lot of time to send QQ information notification channel. So I found the cool Q deployment shared by Daniel to implement the qq robot on the Internet, which successfully solved the problem.

Java implements QQ Robot to intercept QQ message + reply message using Java

Make sure the coolq environment is set up and deploy the coolq environment tutorial

Install the coolq plug-in

Click on me to download the required files.

Extract the folder and copy the org.ruiko.lemoc.cpk to the app directory under the coolq directory on the linux server. Here's my [root@iz2ze6ezkrxf8bsldl6cn3z app] # cd / data/coolq-data/app/ [root@iz2ze6ezkrxf8bsldl6cn3z app] # lltotal 1560 com.coxxs.status.cpk-rw-r--r-- 1 admin admin 401717 Aug 11-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] # Log in to the console of coolq

Right-click the floating window to start the lemoc module

Set menu > Settings > automatically enable serverg check box, local connection is not checked

Open 25303 access to the public network port

Delete the previously running docker container and add a new mapping port (port 25303 of the lemoc module) when starting

Docker rm $(docker ps-aq) docker run-- name=coolq-d-p 8001 docker run 9000-p 25303 docker rm 25303-v / data/coolq-data:/home/user/coolq-e VNC_PASSWD=*-e COOLQ_ACCOUNT=630389368 coolq/wine-coolq verify whether it is enabled successfully

Cmd:telnet ip 25303 under windows

Now that the module has been installed, start writing Java code to intercept QQ messages

Import downloaded 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) {/ / Connect coolq server kqWebClient = new RewriteKQWebClient (new URI (host)) } / / message listening adapter MyQQAdapter myQQAdapter = new MyQQAdapter (kqWebClient); / / listening for message 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 } / * receive private chat message * / public void Re_MSG_Private (RE_MSG_Private msg) {System.out.println ("received private chat message 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 ());}} Test whether public static void main (String [] args) {KQClient.runClient ("ws://ip:25303");} output the following log

Plug-in api address. For more interface description, please refer to

Https://cqp.cc/t/29722

"how to use cool Q+java to achieve qq robot" content is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report