查询任意QQ历史头像

本程序由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
06