判断openfire用户的状态

/**
* 判断openfire用户的状态
* 说明 :必须要 openfire加载 presence 插件,同时设置任何人都可以访问
* /status?jid=user1@my.openfire.com&type=xml 返回值 : 0 - 用户不存在; 1 - 用户在线; 2 -用户离线
* 示例:http://192.168.1.254:9090/plugins/presence/status?jid=13817764475@192.168.1.254&type=xml

* @后面的参数是服务器名称,我测试时服务器名称写为了192.168.1.254

*/
public static short IsUserOnLine(String strUrl) {
strUrl = "http://192.168.1.254:9090/plugins/presence/status?jid=13817764475@192.168.1.254&type=xml";
short shOnLineState = 0; // -不存在-
try {
URL oUrl = new URL(strUrl);
URLConnection oConn = oUrl.openConnection();
if (oConn != null) {
BufferedReader oIn = new BufferedReader(new InputStreamReader(oConn.getInputStream()));
if (null != oIn) {
String strFlag = oIn.readLine();
oIn.close();

if (strFlag.indexOf("type=\"unavailable\"") >= 0) {
shOnLineState = 2;
}
if (strFlag.indexOf("type=\"error\"") >= 0) {
shOnLineState = 0;
} else if (strFlag.indexOf("priority") >= 0 || strFlag.indexOf("id=\"") >= 0) {
shOnLineState = 1;
}
}
}
} catch (Exception e) {

}
return shOnLineState;
}

 

// 离线時,向offline表写数据
OfflineMessageStore offlineMessageStore = new OfflineMessageStore();
offlineMessageStore.addMessage(message);

 

posted @ 2016-09-30 10:39  这个名字想了很久~  阅读(434)  评论(0编辑  收藏  举报