Package mylib. webxml;
//~ --- JDK imports ------------------------------------------------------------
Import java. Io. ioexception;
Import java. Io. inputstream;
Import java.net. httpurlconnection;
Import java.net. url;
/**
*
* @ Author JMP ESP
* @ Version 1.0
*
*/
Public class checkqq {
// Status returned after Query
Private Final Static int error_qq = 2;
Private Final Static int offline_qq = 1;
Private Final Static int online_qq = 0;
// Signature
Private Final Static string online = "> Y <";
Private Final Static string offline = "> n <";
Private Final Static string webxml_qq =
"Http://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx/qqCheckOnline? Qqcode = ";
/**
* Determine whether QQ is online
* @ Param QQ
* @ Return online: 0 | offline: 1 | error: 2
*/
Public static int isonline (string qq ){
URL url = NULL;
Httpurlconnection HTTP = NULL;
Inputstream in = NULL;
Try {
Url = new URL (webxml_qq + qq );
HTTP = (httpurlconnection) URL. openconnection ();
HTTP. Connect ();
In = http. getinputstream ();
Int Len = 0;
Byte [] buffer = new byte [128];
String temp = "";
While (LEN = in. Read (buffer ))! =-1 ){
Temp = temp + new string (buffer, 0, Len, "UTF-8 ");
}
If (temp. lastindexof ("> n <")! =-1 ){
Return offline_qq;
} Else if (temp. lastindexof ("> Y <")! =-1 ){
Return online_qq;
} Else {
Return error_qq;
}
} Catch (exception e ){
System. Out. println (E. getmessage ());
Return error_qq;
} Finally {
If (in! = NULL ){
Try {
In. Close ();
HTTP. Disconnect ();
} Catch (ioexception ex ){
System. Out. println (Ex );
}
}
}
}
Public static void main (string [] ARGs ){
System. Out. println (checkqq. isonline ("695326874 "));
}
}
//~ Formatted by jindent --- http://www.jindent.com