White个人博客-忠于原创,乐于分享-www.10248.top
                                爱实验吧
【公告】:本站改版啦~
  • 灰色
  • 紫色
  • 红色
  • 天蓝色
  • 橙色
  • 淡绿色
  • 切换主题颜色

查询任意QQ历史头像

发布:White2018-8-5 10:20分类: JAVA 这篇文章木有标签 浏览:678字数:70577 去评论(0)

本程序由JAVA写的程序,源码已公布,供大家学习。有能力的也可以尝试把这个程序运行起来,有不懂的可以问我


【查询地址】在文章末尾
1.这个是启动类:

[Java] 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
package myapp.zjp.clent;
 
public class StartServer {
        public static void main(String[] args) {
                //初始化
                new Config();
                //启动socket服务
                if (Config.socketServerSwitch==1){
                        new Thread(new SocketServer()).start();
                }
                //启动http服务
                if (Config.httpServerSwitch==1){
                        new Thread(new HttpServer()).start();
                }
        }
}




2.这个是socket服务端程序

[Java] 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package myapp.zjp.clent;
 
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.regex.Pattern;
 
import net.sf.json.JSONObject;
 
import org.apache.log4j.Logger;
 
/**
 * 获取任意QQ历史头像服务器 
 */
public class SocketServer implements Runnable{
        private Logger log = Logger.getLogger(this.getClass());
         
    public SocketServer() {
    }
        public void run() {
                 try {
                    // 建立服务器连接,设定客户连接请求队列的长度
                    ServerSocket server = new ServerSocket(Config.socketServerPort, Config.socketServerMaxlen);
                    log.info("socket服务器已启动,服务端口:["+Config.socketServerPort +"],最大连接数:["+ Config.socketServerMaxlen +"]");
                    while (true) {
                        // 等待客户连接
                        Socket socket = server.accept();
                        new Thread(new SocketServerThread(socket)).start();
                    }
                } catch (IOException e) {
                    log.error("socket服务器启动失败", e);
                }
                 
        }
}
 
class SocketServerThread implements Runnable {
        private Logger log = Logger.getLogger(this.getClass());
         
    private Socket socket;
 
    public SocketServerThread(Socket socket) {
        this.socket = socket;
    }
 
    // 为一个用户提供服务
    public void run() {
 
            String hostAddress = socket.getInetAddress().getHostAddress();
            DataInputStream in = null;
            DataOutputStream out = null;
        try {
            try {
                // 读取客户端传过来信息的DataInputStream
                 in = new DataInputStream(socket.getInputStream());
                // 向客户端发送信息的DataOutputStream
                 out = new DataOutputStream(socket.getOutputStream());
                // 读取来自客户端的信息
                String qqNumber = in.readUTF();
                Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
                if( qqNumber!= null && qqNumber.trim().length()>0
                                //判断字符串是否为整数
                                && pattern.matcher(qqNumber.trim()).matches()){
                     JSONObject data = HttpUtils.getJSONResult(qqNumber, new getCookie().reader());
                     out.writeUTF(data.toString());
                     if (data.get("ret").toString().trim().equals("0")){
                             log.info("[" + hostAddress + "]查询QQ:[" + qqNumber +"]OK");
                     }else{
                             log.info("[" + hostAddress + "]查询QQ:[" + qqNumber +"]FAIL");
                     }
                         //停止线程
                         Thread.yield();
                }else{
                        log.info("[" + socket.getInetAddress().getHostAddress() + "]查询QQ:[" + qqNumber +"]FAIL");
                        //停止线程
                        Thread.yield();
                }
            } finally {// 建立连接失败的话不会执行socket.close();
                    in.close();
                    out.close();
                socket.close();
            }
        } catch (EOFException e){
                log.error( "[" + hostAddress + "]读取失败",e);
                //读取失败
        }catch (IOException e) {
                log.error("[" + hostAddress + "]系统异常",e);
        }
    }
     
    public void htmlService(){
             
    }
}


3.这个是http服务端程序源码:

[Java]

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package myapp.zjp.clent;
 
import java.io.BufferedReader;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
import java.util.regex.Pattern;
 
import net.sf.json.JSONObject;
 
import org.apache.log4j.Logger;
 
/**
 * 获取任意QQ历史头像服务器
 */
public class HttpServer implements Runnable{
        private Logger log = Logger.getLogger(this.getClass());
         
    public HttpServer() {
    }
    // 提供服务
    public void run() {
        try {
            // 建立服务器连接,设定客户连接请求队列的长度
            ServerSocket server = new ServerSocket(Config.httpServerPort, Config.httpServerMaxlen);
            log.info("http服务器已启动,服务端口:["+Config.httpServerPort +"],最大连接数:["+ Config.httpServerMaxlen +"]");
            while (true) {
                // 等待客户连接
                Socket socket = server.accept();
                new Thread(new HttpServerThread(socket)).start();
            }
        } catch (IOException e) {
            log.error("http服务器启动失败", e);
        }
    }
}
 
class HttpServerThread implements Runnable {
        private Logger log = Logger.getLogger(this.getClass());
         
    private Socket socket;
 
    public HttpServerThread(Socket socket) {
        this.socket = socket;
    }
 
    // 为一个用户提供服务
    public void run() {
 
            String hostAddress = socket.getInetAddress().getHostAddress();
            BufferedReader in = null;
            OutputStream out = null;
        try {
            try {
                                InputStream is = socket.getInputStream();
                                in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                                boolean flag = false;
                                // 读取返回的内容
                                String line = in.readLine();
                                String msg = "";
                                String qqNumber = "";
                                if(line.substring(0, 3).equalsIgnoreCase("GET")){
                                        flag = true;
                                        try{
                                                qqNumber = line.split("=")[1].split(" ")[0];
                                                 
                                                Pattern pattern = Pattern.compile("^[-\\+]?[\\d]{4,10}$");
                                                //判断字符串是否为整数
                                                flag = pattern.matcher(qqNumber).matches();
                                                if (!flag){
                                                        msg = "-1:请求参数有误";
                                                        log.error("["+hostAddress+"]请求参数不正确");
                                                }
                                                System.out.println(qqNumber);
                                        }catch (Exception e){
                                                flag = false;
                                                msg = "-2:请求参数有误";
                                                log.error("["+hostAddress+"]请求参数不正确",e);
                                        }
                                } else {
                                        flag = false;
                                        msg = "-3:暂不支持post请求方式";
                                        log.error("["+hostAddress+